various fixes
[automated-distro-installer] / fai / config / distro-install-common / end
1 #!/bin/bash -x
2
3 set -eE -o pipefail
4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
5
6 if [[ $EUID != 0 ]]; then
7 echo "$0: error: expected to be root."
8 exit 1
9 fi
10
11 TPW=/q/root/shadow/traci-simple
12 if ifclass tp; then
13 ROOTPW="$TPW"
14 else
15 ROOTPW=/q/root/shadow/standard
16 fi
17
18 chpw() {
19 # generating a hashed password:
20 # under debian, you can do
21 # mkpasswd -m sha-512 -s >/q/root/shadow/standard
22 # On arch, best seems to be copy your shadow file to a temp location,
23 # then passwd, get out the new pass, then copy the shadow file back.
24
25 user=$1
26 pwfile=$2
27 if [[ $pwfile && -e $pwfile ]]; then
28 printf "$user:" | cat - "$pwfile" | $ROOTCMD chpasswd -e
29 else
30 echo "$0: warning: no pw set for $user" >&2
31 fi
32 }
33 au() { # add user
34 if ! $ROOTCMD getent passwd ${@: -1}; then
35 $ROOTCMD useradd -m -s /bin/bash $@
36 fi
37 }
38
39 chpw root "$ROOTPW"
40 # 9 = user already exists. so we are idempotent.
41 au ian
42 chpw ian "$ROOTPW"
43
44 au traci
45 if ifclass frodo; then
46 chpw traci "$TPW"
47 fi
48 # comparing ian's groups to traci, I see none she should join on arch
49 $ROOTCMD usermod -a -G traci ian
50
51
52 # based on unison error, with 8192 from
53 # sysctl -a | grep fs.inotify.max_user_watches
54 #http://stackoverflow.com/questions/535768/what-is-a-reasonable-amount-of-inotify-watches-with-linux
55
56 f=$target/etc/sysctl.d/99-sysctl.conf
57 key=fs.inotify.max_user_watches
58 if [[ -e $f ]]; then sed -ri --follow-symlinks "/^\s*$key\s*=/d" $f; fi
59 echo "fs.inotify.max_user_watches = 1000000" >> $f
60 # applies it. it would be also be applied after a reboot
61 $ROOTCMD sysctl --system
62
63 f=$target/etc/sudoers
64 line='ian ALL=(ALL) NOPASSWD: ALL'
65 if [[ ! -e $f ]] || ! grep -xF "$line" $f; then
66 echo "$line" >> $f
67 fi
68
69 # ssh host keys
70 # note, $BASH_SOURCE is not defined here under fai.
71 src=$(dirname "$0")/p/c/machine_specific/$HOSTNAME/filesystem/etc/ssh
72 dst=$target/etc/ssh
73 if [[ -e $src && -e $dst ]]; then
74 # outside of fai context, we skip this
75 cp -rT $src $dst
76 fi
77
78
79 dir=/p/c/machine_specific/$HOSTNAME/.unison
80 $ROOTCMD mkdir -p $dir
81 if ! $ROOTCMD test -L /root/.unison; then
82 $ROOTCMD rm -rf /root/.unison
83 $ROOTCMD ln -s -T $dir /root/.unison
84 fi
85
86 $ROOTCMD chown -R 1000:1000 $dir
87 while true; do
88 $ROOTCMD chown 1000:1000 $dir
89 $ROOTCMD chmod 700 $dir
90 dir=$(dirname $dir)
91 if [[ $dir == /p ]]; then break; fi
92 done
93
94 au -s /bin/false --home-dir /var/lib/bitcoind bitcoin