aboutsummaryrefslogtreecommitdiff
path: root/multihome
diff options
context:
space:
mode:
Diffstat (limited to 'multihome')
-rwxr-xr-xmultihome109
1 files changed, 109 insertions, 0 deletions
diff --git a/multihome b/multihome
new file mode 100755
index 0000000..1c65b49
--- /dev/null
+++ b/multihome
@@ -0,0 +1,109 @@
+#!/bin/bash
+#
+# multihome is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# multihome is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with multihome. If not, see <http://www.gnu.org/licenses/>.
+
+# 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|-||'`
+
+### MULTI-HOME BEGIN ###
+# Define rc file for custom configuration
+RC=$HOME/.homerc
+
+# Add default cluster patterns
+# Elements are delimited by SPACES
+clusters=( )
+
+transfer_env=( .*profile .*login .*cshrc* .bash* )
+
+# Don't edit these
+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"
+
+if [ -f "$RC" ]; then
+ source $RC
+fi
+
+# Are we on a cluster machine?
+if [ ${#clusters[@]} -gt 0 ]; then
+ for host in "${clusters[@]}"
+ do
+ if [[ "$HOSTNAME" == *${host}*${host_suffix} ]]; then
+ cluster=${host}
+ break
+ fi
+ 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
+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 )
+
+SHELL_MODE=
+SHELL_MODE_DELIMITER=
+#Environment switch-over (external eval required)
+case "$parent_shell" in
+ bash|ksh|sh)
+ SHELL_MODE="export"
+ SHELL_MODE_DELIMITER="="
+ ;;
+ tcsh|csh)
+ SHELL_MODE="setenv"
+ SHELL_MODE_DELIMITER=" "
+ ;;
+ *)
+ ;;
+esac
+
+if [ -z "$SHELL_MODE" ]; then
+ echo Unsupported shell: $parent_shell, aborting
+ exit 1
+fi
+
+# Give us a new HOME
+echo $SHELL_MODE HOME${SHELL_MODE_DELIMITER}"${home_local_path}"
+
+### MULTI-HOME END ###