]> arthur.barton.de Git - ConfigScripts.git/blobdiff - install.sh
Suppress "warning: setlocale: LC_CTYPE: cannot change locale (...)"
[ConfigScripts.git] / install.sh
index 4645cbd19f022fdfcecbb79955b264c507b15537..877058beb19d507b8763729c5063d86afbcb9a23 100755 (executable)
@@ -27,13 +27,17 @@ Copy_File() {
        fi
        Msg " "
        cp "$src" "$dst" || Abort
-       [ -n "$own" ] && chown "$own" "$dst" || Abort
-       [ -n "$perm" ] && chmod "$perm" "$dst" || Abort
+       if [ -n "$own" -a "$own" != "$USER" ]; then
+               chown "$own" "$dst" || Abort
+       fi
+       if [ -n "$perm" ]; then
+               chmod "$perm" "$dst" || Abort
+       fi
        Msg "- OK.\n"
 }
 
 Config_System() {
-       if [ "$UID" = "0" ]; then
+       if [ "$UID" = "0" -a -z "$I_local" ]; then
                Msg "Starting system configuration:\n"
                Msg " - bash shell:\n"
                if [ -e /etc/bash.bashrc ]; then
@@ -45,7 +49,7 @@ Config_System() {
        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
+               if [ $? -ne 0 -o -n "$I_local" ]; then
                        Msg "Installing system files to $HOME/.etc/ ...\n"
                        mkdir -p "$HOME/.etc"
                        Copy_File sys/bashrc $HOME/.etc/bashrc "$user" 600
@@ -80,9 +84,24 @@ Config_User() {
        fi
 }
 
+Config_Skel() {
+       if [ -w /etc/skel ]; then
+               Msg "Starting \"/etc/skel\" configuration:\n"
+               Copy_File user/bash_logout /etc/skel/.bash_logout
+               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
+               Msg "Can't write to \"/etc/skel\" - configuration SKIPPED.\n"
+       fi
+}
+
 Config_RootUser() {
        if [ "$UID" = "0" ]; then
-               user=`grep "^.*:.*:0:" /etc/passwd | cut -d':' -f1`
+               user=`grep "^.*:.*:0:" /etc/passwd | head -n 1 | cut -d':' -f1`
                home=`grep "^.*:.*:0:" /etc/passwd | cut -d':' -f6`
                Config_User "$user" "$home"
        else
@@ -90,6 +109,17 @@ Config_RootUser() {
        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
 
@@ -98,6 +128,7 @@ Msg "Running $NAME (uid=$UID) ...\n"
 user=`basename "$HOME"`
 
 Config_System
+Config_Skel
 Config_User "$user" "$HOME"
 Config_RootUser