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
22 if [[ $FAI_ROOT != / ]]; then
24 chroot
="chroot $FAI_ROOT"
28 # -i = ignore non-matching class warnings, always exit 0
29 # -B = no backup files
31 # this is also done by FAIBASE/10-misc by default (without B)
32 fcopy
-riB /usr
/local
/bin
34 fcopy
-riB /etc
/apt
/logind.conf.d
36 # this gets done by fai, but just happens too often that
37 # I add sources due to new distros, whatever.
38 fcopy
-riB /etc
/apt
/preferences.d
39 fcopy
-riB /etc
/apt
/sources.list.d
42 src
=$FAI/distro-install-common
/shadow
44 if [[ ! -e $dst && -e $src ]]; then
45 # outside of fai context, we skip this
47 mount
-o bind $src $dst
50 $FAI/distro-install-common
/end
54 ### begin sources install + updates
55 # these get copied in an earlier stage by fai, but leaving it here since
56 # I run this as a single post-fai script to update things that have changed.
58 # this can fail if we need an apt update
59 $chroot /usr
/bin
/apt-cache policy
>$tmpfile1 ||
:
63 $chroot /usr
/bin
/apt-cache policy
>$tmpfile2
64 if ! diff -q $tmpfile1 $tmpfile2; then
65 $chroot /usr
/bin
/apt update
67 # outside of fai, this seems to regularly lead to
68 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
69 # so add a sleep. 1 sec is probably way more than needed.
71 f
=$FAI_ROOT/var
/cache
/apt
/pkgcache.bin
72 if [[ ! -r $f ]] ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
74 while fuser
$FAI_ROOT/var
/lib
/dpkg
/lock
&>/dev
/null
; do
77 if (( i
> 300 )); then
78 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
81 $ROOTCMD apt-get update
84 ### end sources install + updates
87 #### misc configurations
90 if [[ $FAI_ACTION != dirinstall
]] && ! ifclass NOCRYPT
; then
91 if ifclass LINODE
; then
93 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8"
96 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
99 fcopy
-v /usr
/bin
/myncq
101 cat >$target/etc
/systemd
/system
/myncq.service
<<'EOF'
103 Description=fix ncq errors
107 ExecStart=/usr/bin/myncq
111 # https://www.enricozini.org/blog/2017/debian/systemd-07-devices/
112 WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
115 $chroot bash
<<'EOFOUTER'
116 systemctl enable myncq.service
117 /usr/bin/myncq no-upgrub
121 # per rubens suggestion to make a d16 more stable
122 kd|kw
) cmdline
+=" pci=realloc=off" ;;
126 fi ##### end != dirinstall && != NOCRYPT
129 ###### begin network setup ####
131 # use old names. the idea of them changing between boots has never
132 # happened to me and I usually only have 1 wired or other type.
133 # If I ever do need to care about it, I will.
134 # Strangely this didn't work on kw, so I added kernel cmdline parameter.
135 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
136 ln -sf /dev
/null
$target/etc
/systemd
/network
/99-default.link
139 # bitfolk installer handles the rest
145 # bug fix, somewhere between t9's xorg 1.19.6
146 # and 1.20.1-3ubuntu2
147 # xserver-xorg-video-nouveau 1:1.0.15-3
148 # xorg stopped load nouveau
149 # https://www.linuxquestions.org/questions/slackware-14/kernel-modules-conflicting-with-nouveau-driver-4175623867/
150 # https://nouveau.freedesktop.org/InstallNouveau.html
151 # And now in t11, things got worse with a newer card also not loading
152 # nouveau when it did in t10.
153 if lspci|
grep -q 'VGA compatible controller: NVIDIA'; then
154 mkdir
-p $target/etc
/X11
/xorg.conf.d
/
155 cat >$target/etc
/X11
/xorg.conf.d
/10-nouveau.conf
<<'EOF'
163 # use networkmanager if this host has wireless.
164 if [[ $HOSTNAME == bo
]] ||
type -p iw
&>/dev
/null
&& [[ $
(iw dev
) ]]; then
166 apt-get -y install network-manager
169 # allow networkmanager to manage interfaces
170 #https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
171 touch $target/etc
/NetworkManager
/conf.d
/10-globally-managed-devices.conf
172 # in a default desktop install, it looks like netplan creates this file under
173 # run/NetworkManager/conf.d in early boot.
175 # By default, dns=default is set in etiona, and dns is just broken.
176 # Maybe with resolvconf it would work, but theres no need for that.
177 # https://wiki.gnome.org/Projects/NetworkManager/DNS
178 cat >$target/etc
/NetworkManager
/conf.d
/99-iank.conf
<<'EOF'
183 cat > $target/etc
/network
/interfaces
<<-EOF
186 iface lo inet loopback
188 iface eth0 inet6 auto
190 source-directory /etc/network/interfaces.d
193 # previously had an else condition after
194 #elif ifclass VM || ifclass LINODE; then
195 # iface $NIC1 inet manual
196 # iface br0 inet dhcp
200 # however, on t9, on startup, br0, became
201 # rename1 and didn't come up. i dunno why,
202 # but the bridge is for vms that I rarely use,
203 # so not bothering to figure it out.
208 # for btrfs bug reporting, install latest kernel and btrfs progs, as of
212 mkdir
-p $FAI_ROOT/tmp
/kernel-debs
213 cd $FAI_ROOT/tmp
/kernel-debs
216 vc
=${vb}.202307110536
217 pre
="https://kernel.ubuntu.com/~kernel-ppa/mainline/v$va/amd64/linux-"
218 if ! dpkg
-s -- linux-headers-
${vb} 2>&1 |
grep -Fx "Status: install ok installed" &>/dev
/null
; then
220 ${pre}headers-${vb}_${vc}_all.deb
221 ${pre}{headers,image-unsigned,modules}-${vb}-generic_${vc}_amd64.deb
231 $chroot apt-get
-y install linux-libre
235 cp -ra $bprogs_pre/a
/opt
/btrfs-progs-release
/btrfs-progs-v6.3
.2 $FAI_ROOT/tmp
/btrfs-progs
242 if ifclass LINODE
; then
243 mkdir
-p $target/etc
/initramfs-tools
/conf.d
244 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
245 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
246 # man 5 initramfs.conf
247 # /usr/share/doc/klibc-utils/README.ipconfig.gz
248 # /usr/share/initramfs-tools/scripts/functions
249 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
253 if [[ $HOSTNAME == li
]]; then
254 cat > $target/etc
/network
/interfaces
<<-EOF
257 iface lo inet loopback
259 # for the standard network config, uncomment this and comment the lines after it.
260 #iface eth0 inet6 auto
262 iface eth0 inet6 static
263 # this is really a /128. it seems like we need to assign it for ipv6 to work.
264 address 2600:3c00::f03c:91ff:fe6d:baf8/64
267 iface eth0 inet6 static
268 # from a requested /64 pool
269 address 2600:3c00:e000:280::2/64
271 source-directory /etc/network/interfaces.d
277 ##### end network setup #####
280 if ifclass VOL_BULLSEYE_BOOTSTRAP
; then
281 fcopy
/etc
/systemd
/system
/faicheck.service
282 $chroot bash
<<'EOFOUTER'
283 systemctl enable faicheck.service
285 exit 0 # avoid unnecessary stuff in bootstrap vol
290 $chroot bash
<<'EOFOUTER'
291 #### begin .ssh setup ###
294 if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
295 mkdir -p /home/iank/.ssh
296 f=/root/.ssh/authorized_keys
298 cp $f /home/iank/.ssh
300 chown -R 1000:1000 /home/iank/.ssh
301 chmod -R u=Xrw,og= /home/iank/.ssh
303 # remove broken symlinks or the following cp will fail
304 find /home/iank/.ssh -xtype l -exec rm '{}' \;
305 cp -rL /home/iank/.ssh /root
306 chown -R root:root /root/.ssh
311 # # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
312 # but that made a service that started too soon and didn't pick up our
313 # x env vars. instead, copy from the root ssh-agent just the
314 # appropriate things into a new service.
315 rm -f /home/iank/.config/systemd/user/default.target.wants/ssh-agent.service
317 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
318 /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
320 #### end .ssh setup ###
322 ## duplicated in ssh-emacs-setup
323 # done here so its setup earlier for convenience
324 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
325 f=/etc/ssh/sshd_config
326 grep -xFq "$line" $f || tee -a $f <<<"$line"
329 # default debian groups (jessie through buster) + adm, root, admin
330 for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
331 if getent group $g >/dev/null; then
336 if getent group systemd-journal >/dev/null; then
337 usermod -aG systemd-journal iank
341 rm -f $target/etc
/resolv.conf
342 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
343 # needed for bitfolk image
344 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
345 systemctl
enable systemd-resolved
346 systemctl start systemd-resolved
351 # reading through the groups that iank is in but user2 isn't,
352 for g
in plugdev audio video cdrom
; do
353 $ROOTCMD usermod
-a -G $g user2