various fixes, data subvols changed, mostly handled elsewhere now
[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() {
34 if ! $ROOTCMD getent passwd $1; then
35 $ROOTCMD useradd -m -s /bin/bash $1 || [[ $? == 9 ]]
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
70 dir=/p/c/machine_specific/$HOSTNAME/.unison
71 $ROOTCMD mkdir -p $dir
72 if ! $ROOTCMD test -L /root/.unison; then
73 $ROOTCMD rm -rf /root/.unison
74 $ROOTCMD ln -s -T $dir /root/.unison
75 fi
76
77 $ROOTCMD chown -R 1000:1000 $dir
78 while true; do
79 $ROOTCMD chown 1000:1000 $dir
80 $ROOTCMD chmod 700 $dir
81 dir=$(dirname $dir)
82 if [[ $dir == /p ]]; then break; fi
83 done