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