]> arthur.barton.de Git - ConfigScripts.git/blobdiff - install.sh
Use Msg() function to output console messages.
[ConfigScripts.git] / install.sh
index c7e7d257964c96e5bbcc03852b0041d5ce18dc97..ad13c6b3afa8fa7aa11a2d19d200660f1ffd2db3 100755 (executable)
@@ -6,36 +6,40 @@
 
 NAME=`basename "$0"`
 
+Msg() {
+       /bin/echo -e "$*"
+}
+
 Abort() {
-       echo "- ERROR!"
+       Msg "- ERROR!"
        exit 1
 }
 
 Copy_File() {
        src="$1"; dst="$2"; own="$3"; perm="$4"
-       echo "     $src -> $dst\c"
+       Msg "     $src -> $dst\c"
        if [ -e "$dst" ]; then
                grep "alex@barton.de" "$dst" >/dev/null 2>&1
                if [ $? -ne 0 ]; then
-                       echo " (B)\c"
+                       Msg " (B)\c"
                        cp "$dst" "$dst.bak"
                fi
        fi
-       echo " \c"
+       Msg " \c"
        cp "$src" "$dst" || Abort
        [ -n "$own" ] && chown "$own" "$dst" || Abort
        [ -n "$perm" ] && chmod "$perm" "$dst" || Abort
-       echo "- OK."
+       Msg "- OK."
 }
 
 [ -n "$UID" ] || UID=`id -u`
 export UID
 
-echo "Running $NAME (uid=$UID) ..."
+Msg "Running $NAME (uid=$UID) ..."
 
 if [ "$UID" = "0" ]; then
-       echo "Starting system configuration:"
-       echo " - bash shell:"
+       Msg "Starting system configuration:"
+       Msg " - bash shell:"
        if [ -e /etc/bash.bashrc ]; then
                Copy_File sys/bashrc /etc/bash.bashrc root 644
        else
@@ -43,16 +47,26 @@ if [ "$UID" = "0" ]; then
        fi
        Copy_File sys/profile /etc/profile root 644
 else
-       echo "Not running with root privileges - system configuration SKIPPED."
+       Msg "Not running with root privileges - system configuration SKIPPED."
 fi
 
 user=`basename "$HOME"`
-echo "Starting user configuration ($user in $HOME):"
-echo " - bash shell:"
-Copy_File user/bash_profile "$HOME/.bash_profile" "$user" 600
-Copy_File user/bashrc "$HOME/.bashrc" "$user" 600
-Copy_File user/bash_logout "$HOME/.bash_logout" "$user" 600
+touch "$HOME/.test.$$" >/dev/null 2>&1
+if [ $? -eq 0 ]; then
+       rm -f "$HOME/.test.$$"
+       Msg "Starting user configuration ($user in $HOME):"
+       Msg " - bash shell:"
+       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 "Can't write to user home directory - user configuration SKIPPED."
+fi
 
-echo "$NAME: Done."
+Msg "$NAME: Done."
 
 # -eof-