]> arthur.barton.de Git - ConfigScripts.git/blobdiff - install.sh
install.sh: Don't handle root user specially
[ConfigScripts.git] / install.sh
index 372606925ba93e25e4582420807f656f5e638678..b2ea6c41fb54f29230ba0fb0f6f445b257758a89 100755 (executable)
@@ -26,56 +26,104 @@ Copy_File() {
                fi
        fi
        Msg " "
-       cp "$src" "$dst" || Abort
-       [ -n "$own" ] && chown "$own" "$dst" || Abort
-       [ -n "$perm" ] && chmod "$perm" "$dst" || Abort
+       cp --preserve=timestamps "$src" "$dst" || Abort
+       if [ -n "$own" ]; then
+               chown "$own" "$dst" || Abort
+       fi
+       if [ -n "$perm" ]; then
+               chmod "$perm" "$dst" || Abort
+       fi
        Msg "- OK.\n"
 }
 
-[ -n "$UID" ] || UID=`id -u`
-export UID
+Config_System() {
+       if [ "$UID" = "0" -a -z "$I_local" ]; then
+               Msg "Starting system configuration:\n"
+               Msg " - bash shell:\n"
+               if [ -e /etc/bash.bashrc ]; then
+                       Copy_File sys/bashrc /etc/bash.bashrc root 644
+               else
+                       Copy_File sys/bashrc /etc/bashrc root 644
+               fi
+               Copy_File sys/profile /etc/profile root 644
+       else
+               Msg "Not running with root privileges - system configuration SKIPPED.\n"
+               grep "alex@barton.de" /etc/profile >/dev/null 2>&1
+               if [ $? -ne 0 -o -n "$I_local" -o -d $HOME/.etc ]; then
+                       Msg "Installing system files to $HOME/.etc/ ...\n"
+                       mkdir -p "$HOME/.etc"
+                       Msg " - bash shell:\n"
+                       Copy_File sys/bashrc $HOME/.etc/bashrc "$user" 600
+                       Copy_File sys/profile $HOME/.etc/profile "$user" 600
+               else
+                       Msg "System configuration seems to be modified: not installing locally.\n"
+               fi
+       fi
+}
 
-Msg "Running $NAME (uid=$UID) ...\n"
+Config_User() {
+       # $1: user name
+       # $2: home directory
 
-user=`basename "$HOME"`
+       user="$1"
+       home="$2"
 
-if [ "$UID" = "0" ]; then
-       Msg "Starting system configuration:\n"
-       Msg " - bash shell:\n"
-       if [ -e /etc/bash.bashrc ]; then
-               Copy_File sys/bashrc /etc/bash.bashrc root 644
-       else
-               Copy_File sys/bashrc /etc/bashrc root 644
-       fi
-       Copy_File sys/profile /etc/profile root 644
-else
-       Msg "Not running with root privileges - system configuration SKIPPED.\n"
-       grep "alex@barton.de" /etc/profile >/dev/null 2>&1
-       if [ $? -ne 0 ]; then
-               Msg "Installing system files to $HOME/.etc/ ...\n"
-               mkdir -p "$HOME/.etc"
-               Copy_File sys/bashrc $HOME/.etc/bashrc "$user" 600
-               Copy_File sys/profile $HOME/.etc/profile "$user" 600
+       Msg "Starting user configuration ($user in $home):\n"
+       touch "$home/.test.$$" >/dev/null 2>&1
+       if [ $? -eq 0 ]; then
+               rm -f "$home/.test.$$"
+               Msg " - bash shell:\n"
+               if [ -e "$home/.profile" ]; then
+                       Copy_File user/bash_profile "$home/.profile" "$user" 600
+               else
+                       Copy_File user/bash_profile "$home/.bash_profile" "$user" 600
+               fi
+               Copy_File user/bashrc "$home/.bashrc" "$user" 600
+               Copy_File user/bash_logout "$home/.bash_logout" "$user" 600
        else
-               Msg "System configuration seems to be modified: not installing locally.\n"
+               Msg "Can't write to user home directory - user configuration SKIPPED.\n"
        fi
-fi
-
-touch "$HOME/.test.$$" >/dev/null 2>&1
-if [ $? -eq 0 ]; then
-       rm -f "$HOME/.test.$$"
-       Msg "Starting user configuration ($user in $HOME):\n"
-       Msg " - bash shell:\n"
-       if [ -e "$HOME/.profile" ]; then
-               Copy_File user/bash_profile "$HOME/.profile" "$user" 600
+}
+
+Config_Skel() {
+       if [ -w /etc/skel -a -z "$I_local" ]; then
+               Msg "Starting \"/etc/skel\" configuration:\n"
+               Msg " - bash shell:\n"
+               Copy_File user/bash_logout /etc/skel/.bash_logout root 644
+               if [ -e /etc/skel/.profile ]; then
+                       Copy_File user/bash_profile /etc/skel/.profile root 644
+               else
+                       Copy_File user/bash_profile /etc/skel/.bash_profile root 644
+               fi
+               Copy_File user/bashrc /etc/skel/.bashrc root 644
        else
-               Copy_File user/bash_profile "$HOME/.bash_profile" "$user" 600
+               [ -z "$I_local" ] \
+                       && Msg "Can't write to \"/etc/skel\" - configuration SKIPPED.\n" \
+                       || Msg "Local install selected, \"/etc/skel\" configuration SKIPPED.\n"
        fi
-       Copy_File user/bashrc "$HOME/.bashrc" "$user" 600
-       Copy_File user/bash_logout "$HOME/.bash_logout" "$user" 600
-else
-       Msg "Can't write to user home directory - user configuration SKIPPED.\n"
-fi
+}
+
+while [ $# -gt 0 ]; do
+       case "$1" in
+       "--local"|"-l")
+               export I_local=1; ;;
+       *)
+               echo "Usage: $0 [--local|-l]"
+               exit 1
+       esac
+       shift
+done
+
+[ -n "$UID" ] || UID=`id -u`
+export UID
+
+Msg "Running $NAME (uid=$UID) ...\n"
+
+user=`basename "$HOME"`
+
+Config_Skel
+Config_System
+Config_User "$user" "$HOME"
 
 Msg "$NAME: Done.\n"