]> arthur.barton.de Git - ConfigScripts.git/blob - install.sh
Make sure that "type manpath" emits no error 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         printf -- "$*"
11 }
12
13 Abort() {
14         Msg "- ERROR!\n"
15         exit 1
16 }
17
18 Copy_File() {
19         src="$1"; dst="$2"; own="$3"; perm="$4"
20         Msg "     $src -> $dst"
21         if [ -e "$dst" ]; then
22                 grep "alex@barton.de" "$dst" >/dev/null 2>&1
23                 if [ $? -ne 0 ]; then
24                         Msg " (B)"
25                         cp "$dst" "$dst.bak"
26                 fi
27         fi
28         Msg " "
29         cp "$src" "$dst" || Abort
30         if [ -n "$own" -a "$own" != "$USER" ]; then
31                 chown "$own" "$dst" || Abort
32         fi
33         if [ -n "$perm" ]; then
34                 chmod "$perm" "$dst" || Abort
35         fi
36         Msg "- OK.\n"
37 }
38
39 Config_System() {
40         if [ "$UID" = "0" -a -z "$I_local" ]; then
41                 Msg "Starting system configuration:\n"
42                 Msg " - bash shell:\n"
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.\n"
51                 grep "alex@barton.de" /etc/profile >/dev/null 2>&1
52                 if [ $? -ne 0 -o -n "$I_local" ]; then
53                         Msg "Installing system files to $HOME/.etc/ ...\n"
54                         mkdir -p "$HOME/.etc"
55                         Copy_File sys/bashrc $HOME/.etc/bashrc "$user" 600
56                         Copy_File sys/profile $HOME/.etc/profile "$user" 600
57                 else
58                         Msg "System configuration seems to be modified: not installing locally.\n"
59                 fi
60         fi
61 }
62
63 Config_User() {
64         # $1: user name
65         # $2: home directory
66
67         user="$1"
68         home="$2"
69
70         Msg "Starting user configuration ($user in $home):\n"
71         touch "$home/.test.$$" >/dev/null 2>&1
72         if [ $? -eq 0 ]; then
73                 rm -f "$home/.test.$$"
74                 Msg " - bash shell:\n"
75                 if [ -e "$home/.profile" ]; then
76                         Copy_File user/bash_profile "$home/.profile" "$user" 600
77                 else
78                         Copy_File user/bash_profile "$home/.bash_profile" "$user" 600
79                 fi
80                 Copy_File user/bashrc "$home/.bashrc" "$user" 600
81                 Copy_File user/bash_logout "$home/.bash_logout" "$user" 600
82         else
83                 Msg "Can't write to user home directory - user configuration SKIPPED.\n"
84         fi
85 }
86
87 Config_RootUser() {
88         if [ "$UID" = "0" ]; then
89                 user=`grep "^.*:.*:0:" /etc/passwd | head -n 1 | cut -d':' -f1`
90                 home=`grep "^.*:.*:0:" /etc/passwd | cut -d':' -f6`
91                 Config_User "$user" "$home"
92         else
93                 Msg "Not running with root privileges - root user configuration SKIPPED.\n"
94         fi
95 }
96
97 while [ $# -gt 0 ]; do
98         case "$1" in
99         "--local"|"-l")
100                 export I_local=1; ;;
101         *)
102                 echo "Usage: $0 [--local|-l]"
103                 exit 1
104         esac
105         shift
106 done
107
108 [ -n "$UID" ] || UID=`id -u`
109 export UID
110
111 Msg "Running $NAME (uid=$UID) ...\n"
112
113 user=`basename "$HOME"`
114
115 Config_System
116 Config_User "$user" "$HOME"
117 Config_RootUser
118
119 Msg "$NAME: Done.\n"
120
121 # -eof-