6afcd1eaf5f75cf22e52b8893679b74cd92b352a
[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 -s /bin/bash $1 || [[ $? == 9 ]]
43 fi
44 }
45
46 chpw root "$ROOTPW"
47 # 9 = user already exists. so we are idempotent.
48 au ian
49 chpw ian "$ROOTPW"
50
51 au traci
52 if ifclass frodo; then
53 chpw traci "$TPW"
54 fi
55 # comparing ian's groups to traci, I see none she should join on arch
56 $ROOTCMD usermod -a -G traci ian
57
58
59 # based on unison error, with 8192 from
60 # sysctl -a | grep fs.inotify.max_user_watches
61 #http://stackoverflow.com/questions/535768/what-is-a-reasonable-amount-of-inotify-watches-with-linux
62
63 f=$target/etc/sysctl.d/99-sysctl.conf
64 key=fs.inotify.max_user_watches
65 if [[ -e $f ]]; then sed -ri --follow-symlinks "/^\s*$key\s*=/d" $f; fi
66 echo "fs.inotify.max_user_watches = 1000000" >> $f
67 # applies it. it would be also be applied after a reboot
68 $ROOTCMD sysctl --system
69
70 f=$target/etc/sudoers
71 line='ian ALL=(ALL) NOPASSWD: ALL'
72 if [[ ! -e $f ]] || ! grep -xF "$line" $f; then
73 echo "$line" >> $f
74 fi
75
76
77 dir=/q/p/c/machine_specific/$HOSTNAME/.unison
78 $ROOTCMD mkdir -p $dir
79 if ! $ROOTCMD test -L /root/.unison; then
80 $ROOTCMD rm -rf /root/.unison
81 $ROOTCMD ln -s -T $dir /root/.unison
82 fi
83
84 $ROOTCMD ln -sf /q/p /
85 $ROOTCMD chown -R 1000:1000 $dir
86 while true; do
87 $ROOTCMD chown 1000:1000 $dir
88 $ROOTCMD chmod 700 $dir
89 dir=$(dirname $dir)
90 [[ $dir != /q ]] || break
91 done