set sudo group earlier to be safe
[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
14 src=$(dirname "$0")/p/c/machine_specific/$HOSTNAME/filesystem/etc/ssh
15 dst=$target/etc/ssh
16 if [[ -e $src && -e $dst ]]; then
17 # outside of fai context or setting up a brand new host, we skip this
18 cp -rT $src $dst
19 fi
20
21 USER2PW=/q/root/shadow/user2
22 # if doesn't exist, we dont set one
23 ROOTPW=/q/root/shadow/standard
24 if [[ ! -e $ROOTPW ]]; then
25 ROOTPW=/q/root/shadow/$HOSTNAME
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 local user=${@: -1}
45 if ! $ROOTCMD getent passwd $user; then
46 $ROOTCMD useradd -c $user -Um -s /bin/bash $@
47 fi
48 }
49
50 chpw root "$ROOTPW"
51
52 # only setup root pass for bootstrap vol
53 if ifclass VOL_BULLSEYE_BOOTSTRAP; then
54 exit 0
55 fi
56
57
58 # return of 9 = user already exists. so we are idempotent.
59 au iank
60 chpw iank "$ROOTPW"
61
62 au user2
63 if ifclass frodo; then
64 chpw user2 "$USER2PW"
65 fi
66 # comparing iank's groups to user2, I see none she should join on arch
67 $ROOTCMD usermod -a -G user2 iank
68
69
70 $ROOTCMD getent group docker &>/dev/null || $ROOTCMD groupadd -r docker
71 $ROOTCMD usermod -a -G docker iank
72
73 # based on unison error, with 8192 from
74 # sysctl -a | grep fs.inotify.max_user_watches
75 #http://stackoverflow.com/questions/535768/what-is-a-reasonable-amount-of-inotify-watches-with-linux
76 f=$target/etc/sysctl.d/99-sysctl.conf
77 key=fs.inotify.max_user_watches
78 if [[ -e $f ]]; then sed -ri --follow-symlinks "/^\s*$key\s*=/d" $f; fi
79 echo "fs.inotify.max_user_watches = 50000" >> $f
80 # applies it. it would be also be applied after a reboot
81 $ROOTCMD sysctl --system
82
83 if getent group sudo >/dev/null; then
84 usermod -aG sudo iank
85 fi
86
87 cat >$target/etc/sudoers.d/ianksudoers <<'EOF'
88 Defaults timestamp_timeout=1440
89 # used in bashrc
90 Defaults env_keep += SUDOD
91 # always_set_home
92 # makes ubuntu be like debian
93 # https://unix.stackexchange.com/a/91572
94 Defaults always_set_home
95 # umask: default setting is to have minimum umask of 0022
96 # This lets us have user-specific umasks which are more permissive.
97 # I did this for transmission and set it's umask gecos on install,
98 # see there for more info.
99 Defaults !umask
100 # i use sudo in cronjobs, it spams the logs rather uselessly
101 # https://stackoverflow.com/questions/14277116/suppress-log-entry-for-single-sudo-commands
102 Defaults:root,iank !log_allowed, !pam_session
103 # for just the root user, set some env vars
104 Defaults>root env_file=/etc/rootsudoenv
105 EOF
106
107 case $HOSTNAME in
108 li|bk|je)
109 cat >>$target/etc/sudoers.d/ianksudoers <<'EOF'
110 iank ALL=(ALL) NOPASSWD: ALL
111 EOF
112 ;;
113 esac
114
115 # remove old config line. can be removed eventually.
116 f=$target/etc/sudoers
117 line='iank ALL=(ALL) NOPASSWD: ALL'
118 if grep -qxF "$line" $f; then
119 sed -i "/^$line/d" $f
120 fi
121
122
123 au --system -s /bin/false --home-dir /var/lib/bitcoind bitcoin