diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2014-01-30 16:00:43 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2014-01-30 16:00:43 -0500 |
commit | dcbc5247379fc89ee60749f578dee4b1a7dd9e4e (patch) | |
tree | cb51e02e68b8840a9d5d60356ab45f45a94060e5 | |
parent | a963e36939ca85afcdaebcc82b69e723f55a2a5f (diff) | |
download | multihome-dcbc5247379fc89ee60749f578dee4b1a7dd9e4e.tar.gz |
Standard cluster is completely optional now. If no cluster is found, defined, or forced with cluster_force=True, then drop to your normal home directory
-rwxr-xr-x | multihome | 73 |
1 files changed, 43 insertions, 30 deletions
@@ -30,9 +30,8 @@ transfer_env=( .*profile .*login .*cshrc* .bash* ) hostname_short=$(hostname -s) host_suffix=".stsci.edu" home_remote_path=$HOME - -# If hostname does not match anything in clusters array, set a default -cluster="standard" +cluster="" +cluster_force=false if [ -f "$RC" ]; then source $RC @@ -49,38 +48,52 @@ if [ ${#clusters[@]} -gt 0 ]; then done fi -# Assign directory structure -home_local_path="/home/$USER/home_local/$cluster/$hostname_short" - -# 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" - home_local_path=/home/$USER - fi +if [ "$cluster_force" != false ]; then + echo "Forcing clustered environment" + cluster="standard" fi -# Generate symlink to original home directory -( cd $home_local_path ; - if [ ! -L HEAD_"$USER" ]; then - ln -sf "$home_remote_path" HEAD_"$USER" - fi ) +if [ ! -z "$cluster" ]; then + # Assign directory structure + home_local_path="/home/$USER/home_local/$cluster/$hostname_short" -# 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 - continue - fi + # If we are already inside, die + if [[ "$PWD" == $home_local_path* ]]; then + exit 2 + fi - if [ ! -f "$DEST/$file" ]; then - cp -a $SRC $DEST 2>/dev/null + # 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" + home_local_path=/home/$USER fi - done ) + fi + + # Generate symlink to original home directory + ( cd $home_local_path ; + if [ ! -L HEAD_"$USER" ]; 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 + continue + fi + + if [ ! -f "$DEST/$file" ]; then + cp -a $SRC $DEST 2>/dev/null + fi + done ) +else + home_local_path=/home/$USER +fi SHELL_MODE= SHELL_MODE_DELIMITER= |