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