4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
6 if [[ $EUID != 0 ]]; then
7 echo "$0: error: expected to be root."
11 if ! type -t fcopy
&>/dev
/null
; then
12 sudo apt-get
-y install fai-client
15 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
25 # -i = ignore non-matching class warnings, always exit 0
26 # -B = no backup files
28 # this is also done by FABASE/10-misc by default.
32 src
=$FAI/distro-install-common
/shadow
34 if [[ ! -e $dst && -e $src ]]; then
35 # outside of fai context, we skip this
37 mount
-o bind $src $dst
40 $FAI/distro-install-common
/end
44 if ifclass VOL_STRETCH_BOOTSTRAP
; then
45 fcopy
-riM /etc
/systemd
/system
46 chroot
$FAI_ROOT bash
<<'EOFOUTER'
47 systemctl enable fai_check.service
49 exit 0 # avoid unnecessary stuff in bootstrap vol
53 # these get copied in an earlier stage by fai, but leaving it here since
54 # I run this as a single post-fai script to update things that have changed.
56 # this can fail if we need an apt update
57 chroot
$FAI_ROOT /usr
/bin
/apt-cache policy
>$tmpfile1 ||
:
60 chroot
$FAI_ROOT /usr
/bin
/apt-cache policy
>$tmpfile2
61 if ! diff -q $tmpfile1 $tmpfile2; then
62 chroot
$FAI_ROOT /usr
/bin
/apt update
65 # outside of fai, this seems to regularly lead to
66 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
67 # so add a sleep. 1 sec is probably way more than needed.
69 f
=$FAI_ROOT/var
/cache
/apt
/pkgcache.bin
70 if [[ ! -r $f ]] ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
72 while fuser
$FAI_ROOT/var
/lib
/dpkg
/lock
&>/dev
/null
; do
75 if (( i
> 300 )); then
76 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
79 $ROOTCMD apt-get update
85 #### misc configurations
86 chroot
$FAI_ROOT bash
<<'EOFOUTER'
87 if getent group systemd-journal >/dev/null; then
88 # makes the journal be saved to disk.
89 mkdir -p /var/log/journal
90 chmod 755 /var/log/journal
92 debconf-set-selections <<EOF
93 kexec-tools kexec-tools/load_kexec boolean false
95 apt-get install -y pxe-kexec
98 #### begin .ssh setup ###
101 mkdir -p /home/iank/.ssh
102 f=/root/.ssh/authorized_keys
104 cp $f /home/iank/.ssh
106 chown -R 1000:1000 /home/iank/.ssh
107 chmod -R u=Xrw,og= /home/iank/.ssh
109 # remove broken symlinks or the following cp will fail
110 find /home/iank/.ssh -xtype l -exec rm '{}' \;
111 cp -rL /home/iank/.ssh /root
112 chown -R root:root /root/.ssh
114 # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
115 # systemctl --user is not available at fai time, so create the link ourselves
116 d=/home/iank/.config/systemd/user/default.target.wants
117 sudo -u iank mkdir -p $d
118 sudo -u iank ln -sf /usr/lib/systemd/user/ssh-agent.service $d
119 #### end .ssh setup ###
122 ## duplicated in ssh-emacs-setup
123 # done here so its setup earlier for convenience
124 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
125 f=/etc/ssh/sshd_config
126 grep -xFq "$line" $f || tee -a $f <<<"$line"
129 # default debian groups (jessie through buster) + adm, sudo, root
130 for g in cdrom floppy audio dip video plugdev netdev adm sudo; do
131 if getent gropu $g >/dev/null; then
136 if getent group systemd-journal >/dev/null; then
137 usermod -aG systemd-journal iank
141 # this is usefull. Only thing reason I see this being disabled by default is
142 # that a normal user can disrupt the system, eg cause a reboot.
143 sed -i '$a kernel.sysrq=1
144 /^kernel.sysrq=/d' /etc/sysctl.conf
148 rm -f $target/etc
/resolv.conf
149 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
150 # needed for bitfolk image
151 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
152 systemctl
enable systemd-resolved
153 systemctl start systemd-resolved
157 # bitfolk installer handles the rest
163 if [[ $FAI_ACTION != dirinstall
]] && ! ifclass NOCRYPT
; then
164 # luks options, see man systemd-cryptsetup-generator
165 # all i know is that with luks.crypttab=no, swap still timed out on boot.
166 # and with rd.luks.crypttab=no, it works.
167 if ifclass LINODE
; then
169 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8"
172 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
174 # per rubens suggestion to make a d16 more stable
175 kd|kw
) cmdline
+=" pci=realloc=off" ;;
179 cat >$FAI_ROOT/etc
/grub.d
/40_custom
<<EOF
182 # This file provides an easy way to add custom menu entries. Simply type the
183 # menu entries you want to add after this comment. Be careful not to change
184 # the 'exec tail' line above.
186 # https://www.coreboot.org/Serial_console # tty
187 # but removed unneeded stuff
189 serial --speed=$speed
190 terminal_input --append serial
191 terminal_output --append serial
195 chroot
$FAI_ROOT bash
<<EOF
197 # https://askubuntu.com/questions/33416/how-do-i-disable-the-boot-splash-screen-and-only-show-kernel-and-boot-text-inst
198 # we remove quiet and splash, and all thats left is what we want
200 if grep -qF "$cmdline" /etc/default/grub; then
201 # already set things, exit
204 sed -ri 's/^ *GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="$cmdline"/' /etc/default/grub
205 # on xenial, no grub is displayed at all. fix that.
206 # found just by noticing this in the config file, and a
207 # warning about it in error.log
208 sed -i '/^ *GRUB_HIDDEN_TIMEOUT/d' /etc/default/grub
212 fi ##### end != dirinstall && != NOCRYPT
215 # reading through the groups that iank is in but user2 isn't,
216 for g
in plugdev audio video cdrom
; do
217 $ROOTCMD usermod
-a -G $g user2
222 ###### begin network setup ####
224 # use old names. the idea of them changing between boots has never
225 # happened to me and I usually only have 1 wired or other type.
226 # If I ever do need to care about it, I will.
227 # Strangely this didn't work on kw, so I added kernel cmdline parameter.
228 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
229 ln -sf /dev
/null
$target/etc
/systemd
/network
/99-default.link
231 # use networkmanager if this host has wireless.
233 if type -p iw
&>/dev
/null
&& [[ $
(iw dev
) ]]; then
234 chroot
$FAI_ROOT bash
<<EOF
235 apt-get -y install network-manager
238 # allow networkmanager to manage interfaces
239 #https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
240 touch $target/etc
/NetworkManager
/conf.d
/10-globally-managed-devices.conf
241 # in a default desktop install, it looks like netplan creates this file under
242 # run/NetworkManager/conf.d in early boot.
244 # By default, dns=default is set in etiona, and dns is just broken.
245 # Maybe with resolvconf it would work, but theres no need for that.
246 # https://wiki.gnome.org/Projects/NetworkManager/DNS
247 cat >$target/etc
/NetworkManager
/conf.d
/99-iank.conf
<<'EOF'
253 cat > $target/etc
/network
/interfaces
<<-EOF
256 iface lo inet loopback
258 iface eth0 inet6 auto
261 # previously had an else condition after
262 #elif ifclass VM || ifclass LINODE; then
263 # iface $NIC1 inet manual
264 # iface br0 inet dhcp
268 # however, on t9, on startup, br0, became
269 # rename1 and didn't come up. i dunno why,
270 # but the bridge is for vms that I rarely use,
271 # so not bothering to figure it out.
276 if ifclass LINODE
; then
277 mkdir
-p $target/etc
/initramfs-tools
/conf.d
278 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
279 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
280 # man 5 initramfs.conf
281 # /usr/share/doc/klibc-utils/README.ipconfig.gz
282 # /usr/share/initramfs-tools/scripts/functions
283 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
287 if [[ $HOSTNAME == li
]]; then
289 cat > $target/etc
/network
/interfaces
<<-EOF
292 iface lo inet loopback
294 # for the standard network config, uncomment this and comment the lines after it.
295 #iface eth0 inet6 auto
297 iface eth0 inet6 static
298 # this is really a /128. it seems like we need to assign it for ipv6 to work.
299 address 2600:3c00::f03c:91ff:fe6d:baf8/64
302 iface eth0 inet6 static
303 # from a requested /64 pool
304 address 2600:3c00:e000:280::2/64
310 # I prefer to stick with ifup/down for now. a. networkd is not in its
311 # own package, so cant use in other init systems. b. it works fine.
312 chroot
$FAI_ROOT bash
<<EOF
313 systemctl disable systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
314 systemctl mask systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
317 ##### end network setup #####