4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
6 if [[ $EUID != 0 ]]; then
7 echo "$0: error: expected to be root."
12 # note, $BASH_SOURCE is not defined here under fai.
14 src
=$
(dirname "$0")/p
/c
/machine_specific
/$HOSTNAME/filesystem
/etc
/ssh
16 if [[ -e $src && -e $dst ]]; then
17 # outside of fai context or setting up a brand new host, we skip this
21 root_pw_f
=/q
/root
/shadow
/standard
22 if [[ ! -e $root_pw_f ]]; then
23 root_pw_f
=/q
/root
/shadow
/$HOSTNAME
26 au
() { # add user. i don't use adduser for portability
28 if ! $ROOTCMD getent passwd
$user; then
29 $ROOTCMD useradd
-c $user -Um -s /bin
/bash $@
34 # only setup root pass for bootstrap vol
35 if ifclass VOL_BULLSEYE_BOOTSTRAP
; then
40 # return of 9 = user already exists. so we are idempotent.
42 # generating a hashed password:
43 # under debian, you can do
44 # mkpasswd -m sha-512 -s >/q/root/shadow/standard
45 # On arch, best seems to be copy your shadow file to a temp location,
46 # then passwd, get out the new pass, then copy the shadow file back.
47 if [[ -e $root_pw_f ]]; then
48 sed 's/^/root:/' $root_pw_f |
$ROOTCMD chpasswd
-e
49 sed 's/^/iank:/' $root_pw_f |
$ROOTCMD chpasswd
-e
53 if ifclass frodo
; then
54 sed 's/^/user2:/' /q
/root
/shadow
/user2 |
$ROOTCMD chpasswd
-e
56 # comparing iank's groups to user2, I see none she should join on arch
57 $ROOTCMD usermod
-a -G user2 iank
60 $ROOTCMD getent group docker
&>/dev
/null ||
$ROOTCMD groupadd
-r docker
61 $ROOTCMD usermod
-a -G docker iank
63 # based on unison error, with 8192 from
64 # sysctl -a | grep fs.inotify.max_user_watches
65 #http://stackoverflow.com/questions/535768/what-is-a-reasonable-amount-of-inotify-watches-with-linux
66 f
=$target/etc
/sysctl.d
/99-sysctl.conf
67 key
=fs.inotify.max_user_watches
68 if [[ -e $f ]]; then sed -ri --follow-symlinks "/^\s*$key\s*=/d" $f; fi
69 echo "fs.inotify.max_user_watches = 50000" >> $f
70 # applies it. it would be also be applied after a reboot
71 $ROOTCMD sysctl
--system
73 if getent group sudo
>/dev
/null
; then
74 $ROOTCMD usermod
-aG sudo iank
77 cat >$target/etc
/sudoers.d
/ianksudoers
<<'EOF'
78 Defaults timestamp_timeout=1440
80 Defaults env_keep += SUDOD
82 # makes ubuntu be like debian
83 # https://unix.stackexchange.com/a/91572
84 Defaults always_set_home
85 # umask: default setting is to have minimum umask of 0022
86 # This lets us have user-specific umasks which are more permissive.
87 # I did this for transmission and set it's umask gecos on install,
88 # see there for more info.
90 # i use sudo in cronjobs, it spams the logs rather uselessly
91 # https://stackoverflow.com/questions/14277116/suppress-log-entry-for-single-sudo-commands
92 Defaults:root,iank !log_allowed, !pam_session
93 # for just the root user, set some env vars
94 Defaults>root env_file=/etc/rootsudoenv
96 # a few commands we should be able to run with no password
97 iank ALL = (root) NOPASSWD: /usr/local/bin/spend,/usr/local/bin/us,/usr/local/bin/off,/usr/bin/nmtui-connect,/usr/local/bin/bitcoinoff,/usr/local/bin/bitcoinon
103 cat >>$target/etc
/sudoers.d
/ianksudoers
<<'EOF'
104 iank ALL=(ALL) NOPASSWD: ALL
109 # remove old config line. can be removed eventually.
110 f
=$target/etc
/sudoers
111 line
='iank ALL=(ALL) NOPASSWD: ALL'
112 if grep -qxF "$line" $f; then
113 sed -i "/^$line/d" $f
117 au
--system -s /bin
/false
--home-dir /var
/lib
/bitcoind bitcoin