]> arthur.barton.de Git - ConfigScripts.git/blob - install.sh
Use Msg() function to output console messages.
[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 Msg() {
10         /bin/echo -e "$*"
11 }
12
13 Abort() {
14         Msg "- ERROR!"
15         exit 1
16 }
17
18 Copy_File() {
19         src="$1"; dst="$2"; own="$3"; perm="$4"
20         Msg "     $src -> $dst\c"
21         if [ -e "$dst" ]; then
22                 grep "alex@barton.de" "$dst" >/dev/null 2>&1
23                 if [ $? -ne 0 ]; then
24                         Msg " (B)\c"
25                         cp "$dst" "$dst.bak"
26                 fi
27         fi
28         Msg " \c"
29         cp "$src" "$dst" || Abort
30         [ -n "$own" ] && chown "$own" "$dst" || Abort
31         [ -n "$perm" ] && chmod "$perm" "$dst" || Abort
32         Msg "- OK."
33 }
34
35 [ -n "$UID" ] || UID=`id -u`
36 export UID
37
38 Msg "Running $NAME (uid=$UID) ..."
39
40 if [ "$UID" = "0" ]; then
41         Msg "Starting system configuration:"
42         Msg " - bash shell:"
43         if [ -e /etc/bash.bashrc ]; then
44                 Copy_File sys/bashrc /etc/bash.bashrc root 644
45         else
46                 Copy_File sys/bashrc /etc/bashrc root 644
47         fi
48         Copy_File sys/profile /etc/profile root 644
49 else
50         Msg "Not running with root privileges - system configuration SKIPPED."
51 fi
52
53 user=`basename "$HOME"`
54 touch "$HOME/.test.$$" >/dev/null 2>&1
55 if [ $? -eq 0 ]; then
56         rm -f "$HOME/.test.$$"
57         Msg "Starting user configuration ($user in $HOME):"
58         Msg " - bash shell:"
59         if [ -e "$HOME/.profile" ]; then
60                 Copy_File user/bash_profile "$HOME/.profile" "$user" 600
61         else
62                 Copy_File user/bash_profile "$HOME/.bash_profile" "$user" 600
63         fi
64         Copy_File user/bashrc "$HOME/.bashrc" "$user" 600
65         Copy_File user/bash_logout "$HOME/.bash_logout" "$user" 600
66 else
67         Msg "Can't write to user home directory - user configuration SKIPPED."
68 fi
69
70 Msg "$NAME: Done."
71
72 # -eof-