diff options
author | Joe Hunkeler <jhunk@stsci.edu> | 2014-02-10 16:55:47 -0500 |
---|---|---|
committer | Joe Hunkeler <jhunk@stsci.edu> | 2014-02-10 16:56:45 -0500 |
commit | b366d871b4f4b629c8963b358c309fd4b3c0f257 (patch) | |
tree | c9a533927ebc317ae36b2de26b1db389be69cf4e | |
parent | 25e98704ec3810727af1aef42ace874189d06f56 (diff) | |
download | multihome-b366d871b4f4b629c8963b358c309fd4b3c0f257.tar.gz |
Regression: BASH v4 only, thanks to associative arrays.
-rwxr-xr-x | multihome | 31 |
1 files changed, 24 insertions, 7 deletions
@@ -13,6 +13,13 @@ # You should have received a copy of the GNU General Public License # along with multihome. If not, see <http://www.gnu.org/licenses/>. + +# Associative arrays are not supported before BASH 4.x +if [ "$BASH_VERSINFO" -lt 4 ]; then + echo echo \"multihome: unsupported BASH version, requires \>\= 4.x.x\" + exit 3 +fi + # Determine parent shell to know what kind of variable export mode we need later parent_shell=`ps -ocommand= -p $PPID | awk -F/ '{print $NF}' | awk '{print $1}'| sed 's|-||'` @@ -25,6 +32,7 @@ RC=$HOME/.homerc clusters=( ) transfer_env=( .*profile .*login .*cshrc* .bash* .Xauthority .ssh ) +declare -A transfer_env_custom # Don't edit these hostname_short=$(hostname -s) @@ -49,7 +57,6 @@ if [ ${#clusters[@]} -gt 0 ]; then fi if [ "$cluster_force" != false ]; then - echo "Forcing clustered environment" cluster="standard" fi @@ -59,14 +66,14 @@ if [ ! -z "$cluster" ]; then # If we are already inside, die if [[ "$PWD" == $home_local_path* ]]; then - exit 2 + exit 2 fi # If multi-home directory does not exist, create it if [ ! -d $home_local_path ]; then mkdir -p $home_local_path if [ $? -ne 0 ]; then - echo "No write access: $home_local_path, aborting" + echo echo \"No write access: \$home_local_path, aborting\" home_local_path=/home/$USER fi fi @@ -77,20 +84,30 @@ if [ ! -z "$cluster" ]; then ln -sf "$home_remote_path" HEAD_"$USER" fi ) - # Copy baseline enviroment ( cd $home_local_path ; for file in "${transfer_env[@]}" do SRC="$home_remote_path/$file" DEST="$home_local_path" - if [ "$file" == stsci_multihome ]; then + if [ "$file" == "multihome" ]; then continue fi - if [ ! -f "$DEST/$file" ]; then + if [ ! -f "$DEST/$file" ] || [ "$transfer_env_always" == true ]; then cp -a $SRC $DEST 2>/dev/null fi done ) + (cd $home_local_path ; + if [ ! -z "${transfer_env_custom[${hostname_short}]}" ]; then + for file in ${transfer_env_custom["${hostname_short}"]} + do + SRC="$file" + DEST="$home_local_path" + if [ ! -f "$DEST/$file" ] || [ "$tranfer_env_${hostname_short}_always" == true ]; then + cp -a $SRC $DEST 2>/dev/null + fi + done ; + fi ) else home_local_path=/home/$USER fi @@ -112,7 +129,7 @@ case "$parent_shell" in esac if [ -z "$SHELL_MODE" ]; then - echo Unsupported shell: $parent_shell, aborting + echo echo \"multihome: unsupported shell: \$parent_shell, aborting\" exit 1 fi |