1

So I am trying to write a script which compiles VMAF from the GIT and I need to change the PYTHONPATH location to the installation directory. The script is working good, and it is installing VMAF, but the problem is that when I source the changes in .bashrc it is valid until the bash script completes, and I want to make them globally. I understand that the bash process is isolating the changes but is there a way to execute the source that it persists the execution of the script? This is my code:

#!/bin/bash

mkdir $HOME/install
sudo apt-get install python-dev python-pip python-tk -y
sudo pip install --upgrade scikit-learn h5py numpy scipy matplotlib pandas

cd $HOME/install
git clone https://github.com/Netflix/vmaf.git
cd $HOME/install/vmaf
make
echo "export PYTHONPATH=$HOME/install/vmaf/python:\$PYTHONPATH" | sudo tee -a $HOME/.bashrc
echo "alias ll='ls -al --color'" | sudo tee -a $HOME/.bashrc

source $HOME/.bashrc
./unittest
1
  • 1
    To add global exports, add a new file to /etc/profile.d/ add global aliases to /etc/bash.bashrc or /etc/bashrc depending on your distro (see /etc/profile around line 18 # Source global bash config (works only for interactive shells)
    – Michael D.
    Commented Feb 24, 2017 at 18:02

1 Answer 1

1

Probably not the most elegant solution, but you could define the global variables in /etc/bash.bashrc and run unittest with bash -c unittest. I *think* that will work, but YMMV.

I can't help but point out that there is free open-source software like Chef and Puppet designed to automate stuff like this. While there's a learning curve to overcome, both are well-documented with tutorials. I'm partial to Chef and would use it if I had to do what you're attempting to do here.

Take a look at https://learn.chef.io/tutorials/learn-the-basics/ubuntu/free/configure-a-resource/ to get a feel for how to use Chef in local mode, which is what I'd do in this situation. Here's a Chef script I wrote to get you started, but use it at your own risk. I haven't tested it. Save it to something like install_vmaf.rb.

include_recipe 'python'
include_recipe 'python::pip'

['python-dev','python-pip','python-tk'].each do |p|
  package p do
    action :install
  end
end

['scikit-learn','h5py','numpy','scipy','matplotlib','pandas'].each do |p|
  python_pip p do
    action :install
  end
end

git "/path/to/check/out/to" do
  repository "https://github.com/Netflix/vmaf.git"
  reference "master"
  action :sync
end

This is incomplete, so you'll need to add a resource block to handle the build process. It's several years old, but take a look at https://serverfault.com/questions/298013/installing-something-from-source-using-chef-should-i-be-doing-some-checks for some direction on how to do this.

Lastly, keep in mind chef-client is meant to be run as root, so you'll want to use the "user" property within the "git" resource block to set ownership of the cloned vmaf repo correctly. See https://docs.chef.io/resource_git.html for more info.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .