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)
29 fcopy
-riB /usr
/local
/bin
31 fcopy
-riB /etc
/apt
/logind.conf.d
33 # this gets done by fai, but just happens too often that
34 # I add sources due to new distros, whatever.
35 fcopy
-riB /etc
/apt
/preferences.d
36 fcopy
-riB /etc
/apt
/sources.list.d
39 src
=$FAI/distro-install-common
/shadow
41 if [[ ! -e $dst && -e $src ]]; then
42 # outside of fai context, we skip this
44 mount
-o bind $src $dst
47 $FAI/distro-install-common
/end
51 ### begin sources install + updates
52 # these get copied in an earlier stage by fai, but leaving it here since
53 # I run this as a single post-fai script to update things that have changed.
55 # this can fail if we need an apt update
56 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
64 # outside of fai, this seems to regularly lead to
65 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
66 # so add a sleep. 1 sec is probably way more than needed.
68 f
=$FAI_ROOT/var
/cache
/apt
/pkgcache.bin
69 if [[ ! -r $f ]] ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
71 while fuser
$FAI_ROOT/var
/lib
/dpkg
/lock
&>/dev
/null
; do
74 if (( i
> 300 )); then
75 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
78 $ROOTCMD apt-get update
81 ### end sources install + updates
84 #### misc configurations
87 if [[ $FAI_ACTION != dirinstall
]] && ! ifclass NOCRYPT
; then
88 if ifclass LINODE
; then
90 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8"
93 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
96 fcopy
-v /usr
/bin
/myncq
98 cat >$target/etc
/systemd
/system
/myncq.service
<<'EOF'
100 Description=fix ncq errors
104 ExecStart=/usr/bin/myncq
108 # https://www.enricozini.org/blog/2017/debian/systemd-07-devices/
109 WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
112 chroot
$FAI_ROOT bash
<<'EOFOUTER'
113 systemctl enable myncq.service
114 /usr/bin/myncq no-upgrub
118 # per rubens suggestion to make a d16 more stable
119 kd|kw
) cmdline
+=" pci=realloc=off" ;;
123 fi ##### end != dirinstall && != NOCRYPT
126 ###### begin network setup ####
128 # use old names. the idea of them changing between boots has never
129 # happened to me and I usually only have 1 wired or other type.
130 # If I ever do need to care about it, I will.
131 # Strangely this didn't work on kw, so I added kernel cmdline parameter.
132 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
133 ln -sf /dev
/null
$target/etc
/systemd
/network
/99-default.link
136 # bitfolk installer handles the rest
142 # bug fix, somewhere between t9's xorg 1.19.6
143 # and 1.20.1-3ubuntu2
144 # xserver-xorg-video-nouveau 1:1.0.15-3
145 # xorg stopped load nouveau
146 # https://www.linuxquestions.org/questions/slackware-14/kernel-modules-conflicting-with-nouveau-driver-4175623867/
147 # https://nouveau.freedesktop.org/InstallNouveau.html
148 # And now in t11, things got worse with a newer card also not loading
149 # nouveau when it did in t10.
150 if lspci|
grep -q 'VGA compatible controller: NVIDIA'; then
151 mkdir
-p $target/etc
/X11
/xorg.conf.d
/
152 cat >$target/etc
/X11
/xorg.conf.d
/10-nouveau.conf
<<'EOF'
160 # use networkmanager if this host has wireless.
161 if [[ $HOSTNAME == bo
]] ||
type -p iw
&>/dev
/null
&& [[ $
(iw dev
) ]]; then
162 chroot
$FAI_ROOT bash
<<EOF
163 apt-get -y install network-manager
166 # allow networkmanager to manage interfaces
167 #https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
168 touch $target/etc
/NetworkManager
/conf.d
/10-globally-managed-devices.conf
169 # in a default desktop install, it looks like netplan creates this file under
170 # run/NetworkManager/conf.d in early boot.
172 # By default, dns=default is set in etiona, and dns is just broken.
173 # Maybe with resolvconf it would work, but theres no need for that.
174 # https://wiki.gnome.org/Projects/NetworkManager/DNS
175 cat >$target/etc
/NetworkManager
/conf.d
/99-iank.conf
<<'EOF'
180 cat > $target/etc
/network
/interfaces
<<-EOF
183 iface lo inet loopback
185 iface eth0 inet6 auto
187 source-directory /etc/network/interfaces.d
190 # previously had an else condition after
191 #elif ifclass VM || ifclass LINODE; then
192 # iface $NIC1 inet manual
193 # iface br0 inet dhcp
197 # however, on t9, on startup, br0, became
198 # rename1 and didn't come up. i dunno why,
199 # but the bridge is for vms that I rarely use,
200 # so not bothering to figure it out.
205 # for btrfs bug reporting, install latest kernel and btrfs progs, as of
209 mkdir
-p $FAI_ROOT/tmp
/kernel-debs
210 cd $FAI_ROOT/tmp
/kernel-debs
213 vc
=${vb}.202307110536
214 pre
="https://kernel.ubuntu.com/~kernel-ppa/mainline/v$va/amd64/linux-"
216 ${pre}headers-${vb}_${vc}_all.deb
217 ${pre}{headers,image-unsigned,modules}-${vb}-generic_${vc}_amd64.deb
220 chroot
$FAI_ROOT make install
222 chroot
$FAI_ROOT bash
<<EOF
229 chroot
$FAI_ROOT apt-get
install linux-libre
233 cp -ra /srv
/a
/opt
/btrfs-progs-release
/btrfs-progs-v6.3
.2 $FAI_ROOT/tmp
/btrfs-progs
234 chroot
$FAI_ROOT bash
<<EOF
240 if ifclass LINODE
; then
241 mkdir
-p $target/etc
/initramfs-tools
/conf.d
242 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
243 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
244 # man 5 initramfs.conf
245 # /usr/share/doc/klibc-utils/README.ipconfig.gz
246 # /usr/share/initramfs-tools/scripts/functions
247 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
251 if [[ $HOSTNAME == li
]]; then
252 cat > $target/etc
/network
/interfaces
<<-EOF
255 iface lo inet loopback
257 # for the standard network config, uncomment this and comment the lines after it.
258 #iface eth0 inet6 auto
260 iface eth0 inet6 static
261 # this is really a /128. it seems like we need to assign it for ipv6 to work.
262 address 2600:3c00::f03c:91ff:fe6d:baf8/64
265 iface eth0 inet6 static
266 # from a requested /64 pool
267 address 2600:3c00:e000:280::2/64
269 source-directory /etc/network/interfaces.d
275 ##### end network setup #####
278 if ifclass VOL_BULLSEYE_BOOTSTRAP
; then
279 fcopy
/etc
/systemd
/system
/faicheck.service
280 chroot
$FAI_ROOT bash
<<'EOFOUTER'
281 systemctl enable faicheck.service
283 exit 0 # avoid unnecessary stuff in bootstrap vol
288 chroot
$FAI_ROOT bash
<<'EOFOUTER'
289 #### begin .ssh setup ###
292 if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
293 mkdir -p /home/iank/.ssh
294 f=/root/.ssh/authorized_keys
296 cp $f /home/iank/.ssh
298 chown -R 1000:1000 /home/iank/.ssh
299 chmod -R u=Xrw,og= /home/iank/.ssh
301 # remove broken symlinks or the following cp will fail
302 find /home/iank/.ssh -xtype l -exec rm '{}' \;
303 cp -rL /home/iank/.ssh /root
304 chown -R root:root /root/.ssh
309 # # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
310 # but that made a service that started too soon and didn't pick up our
311 # x env vars. instead, copy from the root ssh-agent just the
312 # appropriate things into a new service.
313 rm -f /home/iank/.config/systemd/user/default.target.wants/ssh-agent.service
315 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
316 /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
318 #### end .ssh setup ###
320 ## duplicated in ssh-emacs-setup
321 # done here so its setup earlier for convenience
322 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
323 f=/etc/ssh/sshd_config
324 grep -xFq "$line" $f || tee -a $f <<<"$line"
327 # default debian groups (jessie through buster) + adm, root, admin
328 for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
329 if getent group $g >/dev/null; then
334 if getent group systemd-journal >/dev/null; then
335 usermod -aG systemd-journal iank
339 rm -f $target/etc
/resolv.conf
340 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
341 # needed for bitfolk image
342 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
343 systemctl
enable systemd-resolved
344 systemctl start systemd-resolved
349 # reading through the groups that iank is in but user2 isn't,
350 for g
in plugdev audio video cdrom
; do
351 $ROOTCMD usermod
-a -G $g user2