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 (without B)
30 fcopy
-riB /usr
/local
/bin
33 src
=$FAI/distro-install-common
/shadow
35 if [[ ! -e $dst && -e $src ]]; then
36 # outside of fai context, we skip this
38 mount
-o bind $src $dst
41 $FAI/distro-install-common
/end
45 ### begin sources install + updates
46 # these get copied in an earlier stage by fai, but leaving it here since
47 # I run this as a single post-fai script to update things that have changed.
49 # this can fail if we need an apt update
50 chroot
$FAI_ROOT /usr
/bin
/apt-cache policy
>$tmpfile1 ||
:
53 chroot
$FAI_ROOT /usr
/bin
/apt-cache policy
>$tmpfile2
54 if ! diff -q $tmpfile1 $tmpfile2; then
55 chroot
$FAI_ROOT /usr
/bin
/apt update
57 # outside of fai, this seems to regularly lead to
58 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
59 # so add a sleep. 1 sec is probably way more than needed.
61 f
=$FAI_ROOT/var
/cache
/apt
/pkgcache.bin
62 if [[ ! -r $f ]] ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
64 while fuser
$FAI_ROOT/var
/lib
/dpkg
/lock
&>/dev
/null
; do
67 if (( i
> 300 )); then
68 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
71 $ROOTCMD apt-get update
74 ### end sources install + updates
77 #### misc configurations
78 chroot
$FAI_ROOT bash
<<'EOFOUTER'
79 if getent group systemd-journal >/dev/null; then
80 # makes the journal be saved to disk.
81 mkdir -p /var/log/journal
82 chmod 755 /var/log/journal
84 debconf-set-selections <<EOF
85 kexec-tools kexec-tools/load_kexec boolean false
87 apt-get install -y pxe-kexec
89 # this is usefull. Only thing reason I see this being disabled by default is
90 # that a normal user can disrupt the system, eg cause a reboot.
91 sed -i '$a kernel.sysrq=1
92 /^kernel.sysrq=/d' /etc/sysctl.conf
97 if [[ $FAI_ACTION != dirinstall
]] && ! ifclass NOCRYPT
; then
98 # luks options, see man systemd-cryptsetup-generator
99 # all i know is that with luks.crypttab=no, swap still timed out on boot.
100 # and with rd.luks.crypttab=no, it works.
101 if ifclass LINODE
; then
103 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8"
106 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
109 fcopy
-v /usr
/bin
/myncq
111 cat >$target/etc
/systemd
/system
/myncq.service
<<'EOF'
113 Description=fix ncq errors
117 ExecStart=/usr/bin/myncq
121 # https://www.enricozini.org/blog/2017/debian/systemd-07-devices/
122 WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
125 chroot
$FAI_ROOT bash
<<'EOFOUTER'
126 systemctl enable myncq.service
127 /usr/bin/myncq no-upgrub
131 # per rubens suggestion to make a d16 more stable
132 kd|kw
) cmdline
+=" pci=realloc=off" ;;
136 cat >$FAI_ROOT/etc
/grub.d
/40_custom
<<EOF
139 # This file provides an easy way to add custom menu entries. Simply type the
140 # menu entries you want to add after this comment. Be careful not to change
141 # the 'exec tail' line above.
143 # https://www.coreboot.org/Serial_console # tty
144 # but removed unneeded stuff
146 serial --speed=$speed
147 terminal_input --append serial
148 terminal_output --append serial
152 chroot
$FAI_ROOT bash
<<EOF
154 # https://askubuntu.com/questions/33416/how-do-i-disable-the-boot-splash-screen-and-only-show-kernel-and-boot-text-inst
156 sed -ri 's/(^GRUB_CMDLINE_LINUX_DEFAULT=")quiet/\1/;s/^(GRUB_CMDLINE_LINUX_DEFAULT=".*) quiet([ "])/\1\2/' /etc/default/grub
157 sed -ri 's/(^GRUB_CMDLINE_LINUX_DEFAULT=")splash/\1/;s/^(GRUB_CMDLINE_LINUX_DEFAULT=".*) splash([ "])/\1\2/' /etc/default/grub
159 for arg in $cmdline; do
160 if ! grep "^GRUB_CMDLINE_LINUX_DEFAULT=.*[\" ]${arg//./\\.}[\" ]" /etc/default/grub; then
161 sed -ri "s/^GRUB_CMDLINE_LINUX_DEFAULT=\"(.*)/GRUB_CMDLINE_LINUX_DEFAULT=\"$arg \1/" /etc/default/grub
165 if grep -qF "$cmdline" /etc/default/grub; then
166 # already set things, exit
169 sed -ri 's/^ *GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="$cmdline"/' /etc/default/grub
170 # on xenial, no grub is displayed at all. fix that.
171 # found just by noticing this in the config file, and a
172 # warning about it in error.log
173 sed -i '/^ *GRUB_HIDDEN_TIMEOUT/d' /etc/default/grub
175 if type -P update-grub2 &>/dev/null; then
182 fi ##### end != dirinstall && != NOCRYPT
185 ###### begin network setup ####
187 # use old names. the idea of them changing between boots has never
188 # happened to me and I usually only have 1 wired or other type.
189 # If I ever do need to care about it, I will.
190 # Strangely this didn't work on kw, so I added kernel cmdline parameter.
191 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
192 ln -sf /dev
/null
$target/etc
/systemd
/network
/99-default.link
195 # bitfolk installer handles the rest
201 # bug fix, somewhere between t9's xorg 1.19.6
202 # and 1.20.1-3ubuntu2
203 # xserver-xorg-video-nouveau 1:1.0.15-3
204 # xorg stopped load nouveau
205 # https://www.linuxquestions.org/questions/slackware-14/kernel-modules-conflicting-with-nouveau-driver-4175623867/
206 # https://nouveau.freedesktop.org/InstallNouveau.html
207 if lspci|
grep -q 'GeForce GTX 6[0-9][0-9]\]'; then
208 mkdir
-p $target/etc
/X11
/xorg.conf.d
/
209 cat >$target/etc
/X11
/xorg.conf.d
/10-nouveau.conf
<<'EOF'
217 # use networkmanager if this host has wireless.
218 if [[ $HOSTNAME == bo
]] ||
type -p iw
&>/dev
/null
&& [[ $
(iw dev
) ]]; then
219 chroot
$FAI_ROOT bash
<<EOF
220 apt-get -y install network-manager
223 # allow networkmanager to manage interfaces
224 #https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
225 touch $target/etc
/NetworkManager
/conf.d
/10-globally-managed-devices.conf
226 # in a default desktop install, it looks like netplan creates this file under
227 # run/NetworkManager/conf.d in early boot.
229 # By default, dns=default is set in etiona, and dns is just broken.
230 # Maybe with resolvconf it would work, but theres no need for that.
231 # https://wiki.gnome.org/Projects/NetworkManager/DNS
232 cat >$target/etc
/NetworkManager
/conf.d
/99-iank.conf
<<'EOF'
236 if [[ $HOSTNAME == frodo
]]; then
237 cat > $target/etc
/network
/interfaces
<<-EOF
240 iface lo inet loopback
241 iface eth0 inet static
244 source-directory /etc/network/interfaces.d
249 cat > $target/etc
/network
/interfaces
<<-EOF
252 iface lo inet loopback
254 iface eth0 inet6 auto
256 source-directory /etc/network/interfaces.d
259 # previously had an else condition after
260 #elif ifclass VM || ifclass LINODE; then
261 # iface $NIC1 inet manual
262 # iface br0 inet dhcp
266 # however, on t9, on startup, br0, became
267 # rename1 and didn't come up. i dunno why,
268 # but the bridge is for vms that I rarely use,
269 # so not bothering to figure it out.
274 if ifclass LINODE
; then
275 mkdir
-p $target/etc
/initramfs-tools
/conf.d
276 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
277 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
278 # man 5 initramfs.conf
279 # /usr/share/doc/klibc-utils/README.ipconfig.gz
280 # /usr/share/initramfs-tools/scripts/functions
281 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
285 if [[ $HOSTNAME == li
]]; then
287 cat > $target/etc
/network
/interfaces
<<-EOF
290 iface lo inet loopback
292 # for the standard network config, uncomment this and comment the lines after it.
293 #iface eth0 inet6 auto
295 iface eth0 inet6 static
296 # this is really a /128. it seems like we need to assign it for ipv6 to work.
297 address 2600:3c00::f03c:91ff:fe6d:baf8/64
300 iface eth0 inet6 static
301 # from a requested /64 pool
302 address 2600:3c00:e000:280::2/64
304 source-directory /etc/network/interfaces.d
309 # I prefer to stick with ifup/down for now. a. networkd is not in its
310 # own package, so cant use in other init systems. b. it works fine.
311 chroot
$FAI_ROOT bash
<<EOF
312 systemctl disable systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
313 systemctl mask systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
316 ##### end network setup #####
319 if ifclass VOL_BULLSEYE_BOOTSTRAP
; then
320 fcopy
/etc
/systemd
/system
/faicheck.service
321 chroot
$FAI_ROOT bash
<<'EOFOUTER'
322 systemctl enable faicheck.service
324 exit 0 # avoid unnecessary stuff in bootstrap vol
329 chroot
$FAI_ROOT bash
<<'EOFOUTER'
330 #### begin .ssh setup ###
333 if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
334 mkdir -p /home/iank/.ssh
335 f=/root/.ssh/authorized_keys
337 cp $f /home/iank/.ssh
339 chown -R 1000:1000 /home/iank/.ssh
340 chmod -R u=Xrw,og= /home/iank/.ssh
342 # remove broken symlinks or the following cp will fail
343 find /home/iank/.ssh -xtype l -exec rm '{}' \;
344 cp -rL /home/iank/.ssh /root
345 chown -R root:root /root/.ssh
350 # # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
351 # but that made a service that started too soon and didn't pick up our
352 # x env vars. instead, copy from the root ssh-agent just the
353 # appropriate things into a new service.
354 rm -f /home/iank/.config/systemd/user/default.target.wants/ssh-agent.service
356 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
357 /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
359 #### end .ssh setup ###
361 ## duplicated in ssh-emacs-setup
362 # done here so its setup earlier for convenience
363 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
364 f=/etc/ssh/sshd_config
365 grep -xFq "$line" $f || tee -a $f <<<"$line"
368 # default debian groups (jessie through buster) + adm, root, admin
369 for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
370 if getent group $g >/dev/null; then
375 if getent group systemd-journal >/dev/null; then
376 usermod -aG systemd-journal iank
380 rm -f $target/etc
/resolv.conf
381 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
382 # needed for bitfolk image
383 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
384 systemctl
enable systemd-resolved
385 systemctl start systemd-resolved
390 # reading through the groups that iank is in but user2 isn't,
391 for g
in plugdev audio video cdrom
; do
392 $ROOTCMD usermod
-a -G $g user2