From b366d871b4f4b629c8963b358c309fd4b3c0f257 Mon Sep 17 00:00:00 2001 From: Joe Hunkeler Date: Mon, 10 Feb 2014 16:55:47 -0500 Subject: Regression: BASH v4 only, thanks to associative arrays. --- multihome | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'multihome') diff --git a/multihome b/multihome index 9f0ad81..56666cc 100755 --- a/multihome +++ b/multihome @@ -13,6 +13,13 @@ # You should have received a copy of the GNU General Public License # along with multihome. If not, see . + +# 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 -- cgit