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