]> arthur.barton.de Git - ConfigScripts.git/blob - install.sh
Read global files from $HOME/.etc if we can't install to /etc.
[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 user=`basename "$HOME"`
41
42 if [ "$UID" = "0" ]; then
43         Msg "Starting system configuration:"
44         Msg " - bash shell:"
45         if [ -e /etc/bash.bashrc ]; then
46                 Copy_File sys/bashrc /etc/bash.bashrc root 644
47         else
48                 Copy_File sys/bashrc /etc/bashrc root 644
49         fi
50         Copy_File sys/profile /etc/profile root 644
51 else
52         Msg "Not running with root privileges - system configuration SKIPPED."
53         grep "alex@barton.de" /etc/profile >/dev/null 2>&1
54         if [ $? -ne 0 ]; then
55                 Msg "Installing system files to $HOME/.etc/ ..."
56                 mkdir -p "$HOME/.etc"
57                 Copy_File sys/bashrc $HOME/.etc/bashrc "$user" 600
58                 Copy_File sys/profile $HOME/.etc/profile "$user" 600
59         else
60                 Msg "System configuration seems to be modified: not installing locally."
61         fi
62 fi
63
64 touch "$HOME/.test.$$" >/dev/null 2>&1
65 if [ $? -eq 0 ]; then
66         rm -f "$HOME/.test.$$"
67         Msg "Starting user configuration ($user in $HOME):"
68         Msg " - bash shell:"
69         if [ -e "$HOME/.profile" ]; then
70                 Copy_File user/bash_profile "$HOME/.profile" "$user" 600
71         else
72                 Copy_File user/bash_profile "$HOME/.bash_profile" "$user" 600
73         fi
74         Copy_File user/bashrc "$HOME/.bashrc" "$user" 600
75         Copy_File user/bash_logout "$HOME/.bash_logout" "$user" 600
76 else
77         Msg "Can't write to user home directory - user configuration SKIPPED."
78 fi
79
80 Msg "$NAME: Done."
81
82 # -eof-