[provisioning] Make path additions idempotent

This commit is contained in:
Correl Roush 2018-02-23 20:13:11 -05:00
parent 4c219d9db2
commit 0bd050086c

View file

@ -1,16 +1,26 @@
#!/bin/bash
set +e
function __addline {
local filename=$1
shift
local line="$@"
grep "^$line\$" $filename || echo $line >> $filename
}
function _path_low {
PATH="$1:$PATH"
test -r ~/.bash_profile && echo "export PATH='$1'":'"$PATH"' >>~/.bash_profile
echo "export PATH='$1'":'"$PATH"' >>~/.profile
test -r ~/.bash_profile && __addline ~/.bash_profile "export PATH='$1'":'"$PATH"'
__addline ~/.profile "export PATH='$1'":'"$PATH"'
__addline ~/.zshenv "export PATH='$1'":'"$PATH"'
}
function _path_high {
PATH="$PATH:$1"
test -r ~/.bash_profile && echo 'export PATH="$PATH"':"'$PATH'" >>~/.bash_profile
echo "export PATH='$1'":'"$PATH"' >>~/.profile
test -r ~/.bash_profile && __addline ~/.bash_profile 'export PATH="$PATH"':"'$PATH'"
__addline ~/.profile "export PATH='$1'":'"$PATH"'
__addline ~/.zshenv "export PATH='$1'":'"$PATH"'
}
function _path {