]> arthur.barton.de Git - ConfigScripts.git/blob - install.sh
Make sure that $UID is set.
[ConfigScripts.git] / install.sh
1 #!/bin/sh
2 #
3 # ConfigScripts - install.sh
4 # Written by Alexander Barton <alex@barton.de>. Public Domain.
5 #
6
7 NAME=`basename "$0"`
8
9 Abort() {
10         echo "- ERROR!"
11         exit 1
12 }
13
14 Copy_File() {
15         src="$1"; dst="$2"; own="$3"; perm="$4"
16         echo "     $src -> $dst\c"
17         if [ -e "$dst" ]; then
18                 grep "alex@barton.de" "$dst" >/dev/null 2>&1
19                 if [ $? -ne 0 ]; then
20                         echo " (B)\c"
21                         cp "$dst" "$dst.bak"
22                 fi
23         fi
24         echo " \c"
25         cp "$src" "$dst" || Abort
26         [ -n "$own" ] && chown "$own" "$dst" || Abort
27         [ -n "$perm" ] && chmod "$perm" "$dst" || Abort
28         echo "- OK."
29 }
30
31 [ -n "$UID" ] || UID=`id -u`
32 export UID
33
34 echo "Running $NAME (uid=$UID) ..."
35
36 if [ "$UID" = "0" ]; then
37         echo "Starting system configuration:"
38         echo " - bash shell:"
39         if [ -e /etc/bash.bashrc ]; then
40                 Copy_File sys/bashrc /etc/bash.bashrc root 644
41         else
42                 Copy_File sys/bashrc /etc/bashrc root 644
43         fi
44         Copy_File sys/profile /etc/profile root 644
45 else
46         echo "Not running with root privileges - system configuration SKIPPED."
47 fi
48
49 user=`basename "$HOME"`
50 echo "Starting user configuration ($user in $HOME):"
51 echo " - bash shell:"
52 Copy_File user/bash_profile "$HOME/.bash_profile" "$user" 600
53 Copy_File user/bashrc "$HOME/.bashrc" "$user" 600
54 Copy_File user/bash_logout "$HOME/.bash_logout" "$user" 600
55
56 echo "$NAME: Done."
57
58 # -eof-