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 FAIBASE/10-misc by default (without B)
30 fcopy
-riBM /usr
/local
/bin
32 # this gets done by fai, but just happens too often that
33 # I add sources due to new distros, whatever.
34 fcopy
-riBM /etc
/apt
/preferences.d
35 fcopy
-riBM /etc
/apt
/sources.list.d
38 src
=$FAI/distro-install-common
/shadow
40 if [[ ! -e $dst && -e $src ]]; then
41 # outside of fai context, we skip this
43 mount
-o bind $src $dst
46 $FAI/distro-install-common
/end
50 ### begin sources install + updates
51 # these get copied in an earlier stage by fai, but leaving it here since
52 # I run this as a single post-fai script to update things that have changed.
54 # this can fail if we need an apt update
55 chroot
$FAI_ROOT /usr
/bin
/apt-cache policy
>$tmpfile1 ||
:
58 # get ubuntu key, for running from fai wrapper.
59 apt-key add
$FAI/package_config
/UBUNTU.asc
62 chroot
$FAI_ROOT /usr
/bin
/apt-cache policy
>$tmpfile2
63 if ! diff -q $tmpfile1 $tmpfile2; then
64 chroot
$FAI_ROOT /usr
/bin
/apt update
66 # outside of fai, this seems to regularly lead to
67 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
68 # so add a sleep. 1 sec is probably way more than needed.
70 f
=$FAI_ROOT/var
/cache
/apt
/pkgcache.bin
71 if [[ ! -r $f ]] ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
73 while fuser
$FAI_ROOT/var
/lib
/dpkg
/lock
&>/dev
/null
; do
76 if (( i
> 300 )); then
77 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
80 $ROOTCMD apt-get update
83 ### end sources install + updates
86 #### misc configurations
87 chroot
$FAI_ROOT bash
<<'EOFOUTER'
88 if getent group systemd-journal >/dev/null; then
89 # makes the journal be saved to disk.
90 mkdir -p /var/log/journal
91 chmod 755 /var/log/journal
93 debconf-set-selections <<EOF
94 kexec-tools kexec-tools/load_kexec boolean false
96 apt-get install -y pxe-kexec
98 # this is usefull. Only thing reason I see this being disabled by default is
99 # that a normal user can disrupt the system, eg cause a reboot.
100 sed -i '$a kernel.sysrq=1
101 /^kernel.sysrq=/d' /etc/sysctl.conf
106 if [[ $FAI_ACTION != dirinstall
]] && ! ifclass NOCRYPT
; then
107 # luks options, see man systemd-cryptsetup-generator
108 # all i know is that with luks.crypttab=no, swap still timed out on boot.
109 # and with rd.luks.crypttab=no, it works.
110 if ifclass LINODE
; then
112 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8"
115 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
118 fcopy
-v /usr
/bin
/myncq
120 cat >$target/etc
/systemd
/system
/myncq.service
<<'EOF'
122 Description=fix ncq errors
126 ExecStart=/usr/bin/myncq
130 # https://www.enricozini.org/blog/2017/debian/systemd-07-devices/
131 WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
134 chroot
$FAI_ROOT bash
<<'EOFOUTER'
135 systemctl enable myncq.service
136 /usr/bin/myncq no-upgrub
140 # per rubens suggestion to make a d16 more stable
141 kd|kw
) cmdline
+=" pci=realloc=off" ;;
145 cat >$FAI_ROOT/etc
/grub.d
/40_custom
<<EOF
148 # This file provides an easy way to add custom menu entries. Simply type the
149 # menu entries you want to add after this comment. Be careful not to change
150 # the 'exec tail' line above.
152 # https://www.coreboot.org/Serial_console # tty
153 # but removed unneeded stuff
155 serial --speed=$speed
156 terminal_input --append serial
157 terminal_output --append serial
161 chroot
$FAI_ROOT bash
<<EOF
163 # https://askubuntu.com/questions/33416/how-do-i-disable-the-boot-splash-screen-and-only-show-kernel-and-boot-text-inst
165 sed -ri 's/(^GRUB_CMDLINE_LINUX_DEFAULT=")quiet/\1/;s/^(GRUB_CMDLINE_LINUX_DEFAULT=".*) quiet([ "])/\1\2/' /etc/default/grub
166 sed -ri 's/(^GRUB_CMDLINE_LINUX_DEFAULT=")splash/\1/;s/^(GRUB_CMDLINE_LINUX_DEFAULT=".*) splash([ "])/\1\2/' /etc/default/grub
168 for arg in $cmdline; do
169 if ! grep "^GRUB_CMDLINE_LINUX_DEFAULT=.*[\" ]${arg//./\\.}[\" ]" /etc/default/grub; then
170 sed -ri "s/^GRUB_CMDLINE_LINUX_DEFAULT=\"(.*)/GRUB_CMDLINE_LINUX_DEFAULT=\"$arg \1/" /etc/default/grub
174 if grep -qF "$cmdline" /etc/default/grub; then
175 # already set things, exit
178 sed -ri 's/^ *GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="$cmdline"/' /etc/default/grub
179 # on xenial, no grub is displayed at all. fix that.
180 # found just by noticing this in the config file, and a
181 # warning about it in error.log
182 sed -i '/^ *GRUB_HIDDEN_TIMEOUT/d' /etc/default/grub
184 if type -P update-grub2 &>/dev/null; then
191 fi ##### end != dirinstall && != NOCRYPT
194 ###### begin network setup ####
196 # use old names. the idea of them changing between boots has never
197 # happened to me and I usually only have 1 wired or other type.
198 # If I ever do need to care about it, I will.
199 # Strangely this didn't work on kw, so I added kernel cmdline parameter.
200 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
201 ln -sf /dev
/null
$target/etc
/systemd
/network
/99-default.link
204 # bitfolk installer handles the rest
210 # bug fix, somewhere between t9's xorg 1.19.6
211 # and 1.20.1-3ubuntu2
212 # xserver-xorg-video-nouveau 1:1.0.15-3
213 # xorg stopped load nouveau
214 # https://www.linuxquestions.org/questions/slackware-14/kernel-modules-conflicting-with-nouveau-driver-4175623867/
215 # https://nouveau.freedesktop.org/InstallNouveau.html
216 if lspci|
grep -q 'GeForce GTX 6[0-9][0-9]\]'; then
217 mkdir
-p $target/etc
/X11
/xorg.conf.d
/
218 cat >$target/etc
/X11
/xorg.conf.d
/10-nouveau.conf
<<'EOF'
226 # use networkmanager if this host has wireless.
227 if [[ $HOSTNAME == bo
]] ||
type -p iw
&>/dev
/null
&& [[ $
(iw dev
) ]]; then
228 chroot
$FAI_ROOT bash
<<EOF
229 apt-get -y install network-manager
232 # allow networkmanager to manage interfaces
233 #https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
234 touch $target/etc
/NetworkManager
/conf.d
/10-globally-managed-devices.conf
235 # in a default desktop install, it looks like netplan creates this file under
236 # run/NetworkManager/conf.d in early boot.
238 # By default, dns=default is set in etiona, and dns is just broken.
239 # Maybe with resolvconf it would work, but theres no need for that.
240 # https://wiki.gnome.org/Projects/NetworkManager/DNS
241 cat >$target/etc
/NetworkManager
/conf.d
/99-iank.conf
<<'EOF'
245 if [[ $HOSTNAME == frodo
]]; then
246 cat > $target/etc
/network
/interfaces
<<-EOF
249 iface lo inet loopback
250 iface eth0 inet static
253 source-directory /etc/network/interfaces.d
258 cat > $target/etc
/network
/interfaces
<<-EOF
261 iface lo inet loopback
263 iface eth0 inet6 auto
265 source-directory /etc/network/interfaces.d
268 # previously had an else condition after
269 #elif ifclass VM || ifclass LINODE; then
270 # iface $NIC1 inet manual
271 # iface br0 inet dhcp
275 # however, on t9, on startup, br0, became
276 # rename1 and didn't come up. i dunno why,
277 # but the bridge is for vms that I rarely use,
278 # so not bothering to figure it out.
283 if ifclass LINODE
; then
284 mkdir
-p $target/etc
/initramfs-tools
/conf.d
285 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
286 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
287 # man 5 initramfs.conf
288 # /usr/share/doc/klibc-utils/README.ipconfig.gz
289 # /usr/share/initramfs-tools/scripts/functions
290 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
294 if [[ $HOSTNAME == li
]]; then
296 cat > $target/etc
/network
/interfaces
<<-EOF
299 iface lo inet loopback
301 # for the standard network config, uncomment this and comment the lines after it.
302 #iface eth0 inet6 auto
304 iface eth0 inet6 static
305 # this is really a /128. it seems like we need to assign it for ipv6 to work.
306 address 2600:3c00::f03c:91ff:fe6d:baf8/64
309 iface eth0 inet6 static
310 # from a requested /64 pool
311 address 2600:3c00:e000:280::2/64
313 source-directory /etc/network/interfaces.d
318 # I prefer to stick with ifup/down for now. a. networkd is not in its
319 # own package, so cant use in other init systems. b. it works fine.
320 chroot
$FAI_ROOT bash
<<EOF
321 systemctl disable systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
322 systemctl mask systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
325 ##### end network setup #####
328 if ifclass VOL_BULLSEYE_BOOTSTRAP
; then
329 fcopy
/etc
/systemd
/system
/faicheck.service
330 chroot
$FAI_ROOT bash
<<'EOFOUTER'
331 systemctl enable faicheck.service
333 exit 0 # avoid unnecessary stuff in bootstrap vol
338 chroot
$FAI_ROOT bash
<<'EOFOUTER'
339 #### begin .ssh setup ###
342 if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
343 mkdir -p /home/iank/.ssh
344 f=/root/.ssh/authorized_keys
346 cp $f /home/iank/.ssh
348 chown -R 1000:1000 /home/iank/.ssh
349 chmod -R u=Xrw,og= /home/iank/.ssh
351 # remove broken symlinks or the following cp will fail
352 find /home/iank/.ssh -xtype l -exec rm '{}' \;
353 cp -rL /home/iank/.ssh /root
354 chown -R root:root /root/.ssh
359 # # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
360 # but that made a service that started too soon and didn't pick up our
361 # x env vars. instead, copy from the root ssh-agent just the
362 # appropriate things into a new service.
363 rm -f /home/iank/.config/systemd/user/default.target.wants/ssh-agent.service
365 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
366 /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
368 #### end .ssh setup ###
370 ## duplicated in ssh-emacs-setup
371 # done here so its setup earlier for convenience
372 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
373 f=/etc/ssh/sshd_config
374 grep -xFq "$line" $f || tee -a $f <<<"$line"
377 # default debian groups (jessie through buster) + adm, root, admin
378 for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
379 if getent group $g >/dev/null; then
384 if getent group systemd-journal >/dev/null; then
385 usermod -aG systemd-journal iank
389 rm -f $target/etc
/resolv.conf
390 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
391 # needed for bitfolk image
392 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
393 systemctl
enable systemd-resolved
394 systemctl start systemd-resolved
399 # reading through the groups that iank is in but user2 isn't,
400 for g
in plugdev audio video cdrom
; do
401 $ROOTCMD usermod
-a -G $g user2