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
23 source /a
/bin
/bash_unpublished
/source-state
24 bprogs_dir
=/a
/opt
/btrfs-progs-release
26 bprogs_dir
=/srv
/btrfs-progs-release
27 chroot
="chroot $FAI_ROOT"
31 # -i = ignore non-matching class warnings, always exit 0
32 # -B = no backup files
34 # this is also done by FAIBASE/10-misc by default (without B)
35 fcopy
-riB /usr
/local
/bin
37 fcopy
-riB /etc
/apt
/logind.conf.d
39 # this gets done by fai, but just happens too often that
40 # I add sources due to new distros, whatever.
41 fcopy
-riB /etc
/apt
/preferences.d
42 fcopy
-riB /etc
/apt
/sources.list.d
45 src
=$FAI/distro-install-common
/shadow
47 if [[ ! -e $dst && -e $src ]]; then
48 # outside of fai context, we skip this
50 mount
-o bind $src $dst
53 $FAI/distro-install-common
/end
57 ### begin sources install + updates
58 # these get copied in an earlier stage by fai, but leaving it here since
59 # I run this as a single post-fai script to update things that have changed.
61 # this can fail if we need an apt update
62 $chroot /usr
/bin
/apt-cache policy
>$tmpfile1 ||
:
66 $chroot /usr
/bin
/apt-cache policy
>$tmpfile2
67 if ! diff -q $tmpfile1 $tmpfile2; then
68 $chroot /usr
/bin
/apt update
70 # outside of fai, this seems to regularly lead to
71 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
72 # so add a sleep. 1 sec is probably way more than needed.
74 f
=$FAI_ROOT/var
/cache
/apt
/pkgcache.bin
75 if [[ ! -r $f ]] ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
77 while fuser
$FAI_ROOT/var
/lib
/dpkg
/lock
&>/dev
/null
; do
80 if (( i
> 300 )); then
81 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
84 $ROOTCMD apt-get update
87 ### end sources install + updates
90 #### misc configurations
93 if [[ $FAI_ACTION != dirinstall
]] && ! ifclass NOCRYPT
; then
94 if ifclass LINODE
; then
96 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8"
99 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
102 fcopy
-v /usr
/bin
/myncq
104 cat >$target/etc
/systemd
/system
/myncq.service
<<'EOF'
106 Description=fix ncq errors
110 ExecStart=/usr/bin/myncq
114 # https://www.enricozini.org/blog/2017/debian/systemd-07-devices/
115 WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
118 $chroot bash
<<'EOFOUTER'
119 systemctl enable myncq.service
120 /usr/bin/myncq no-upgrub
124 # per rubens suggestion to make a d16 more stable
125 kd|kw
) cmdline
+=" pci=realloc=off" ;;
129 fi ##### end != dirinstall && != NOCRYPT
132 ###### begin network setup ####
134 # use old names. the idea of them changing between boots has never
135 # happened to me and I usually only have 1 wired or other type.
136 # If I ever do need to care about it, I will.
137 # Strangely this didn't work on kw, so I added kernel cmdline parameter.
138 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
139 ln -sf /dev
/null
$target/etc
/systemd
/network
/99-default.link
142 # bitfolk installer handles the rest
148 # bug fix, somewhere between t9's xorg 1.19.6
149 # and 1.20.1-3ubuntu2
150 # xserver-xorg-video-nouveau 1:1.0.15-3
151 # xorg stopped load nouveau
152 # https://www.linuxquestions.org/questions/slackware-14/kernel-modules-conflicting-with-nouveau-driver-4175623867/
153 # https://nouveau.freedesktop.org/InstallNouveau.html
154 # And now in t11, things got worse with a newer card also not loading
155 # nouveau when it did in t10.
156 if lspci|
grep -q 'VGA compatible controller: NVIDIA'; then
157 mkdir
-p $target/etc
/X11
/xorg.conf.d
/
158 cat >$target/etc
/X11
/xorg.conf.d
/10-nouveau.conf
<<'EOF'
166 # use networkmanager if this host has wireless.
167 if [[ $HOSTNAME == bo
]] ||
type -p iw
&>/dev
/null
&& [[ $
(iw dev
) ]]; then
169 apt-get -y install network-manager
172 # allow networkmanager to manage interfaces
173 #https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
174 touch $target/etc
/NetworkManager
/conf.d
/10-globally-managed-devices.conf
175 # in a default desktop install, it looks like netplan creates this file under
176 # run/NetworkManager/conf.d in early boot.
178 # By default, dns=default is set in etiona, and dns is just broken.
179 # Maybe with resolvconf it would work, but theres no need for that.
180 # https://wiki.gnome.org/Projects/NetworkManager/DNS
181 cat >$target/etc
/NetworkManager
/conf.d
/99-iank.conf
<<'EOF'
186 cat > $target/etc
/network
/interfaces
<<-EOF
189 iface lo inet loopback
191 iface eth0 inet6 auto
193 source-directory /etc/network/interfaces.d
196 # previously had an else condition after
197 #elif ifclass VM || ifclass LINODE; then
198 # iface $NIC1 inet manual
199 # iface br0 inet dhcp
203 # however, on t9, on startup, br0, became
204 # rename1 and didn't come up. i dunno why,
205 # but the bridge is for vms that I rarely use,
206 # so not bothering to figure it out.
211 # for new btrfs features, get latest stable kernel and btrfs progs,
212 # update ver= as needed.
215 mkdir
-p $FAI_ROOT/tmp
/kernel-debs
216 files
=($FAI_ROOT/tmp
/kernel-debs
/*)
217 if (( ${#files[@]} >= 1 )); then
220 cd $FAI_ROOT/tmp
/kernel-debs
222 va
=$
(curl
-s https
://kernel.ubuntu.com
/mainline
/ | \
223 sed -rn 's,.*alt="\[DIR\]".*href="([^/]+).*,\1,p' | \
224 grep -v -- -rc |
sed 's/^v//' |
grep "^$ver" |
sort -V |
tail -n1)
226 # note the wiki page about these says to install linux-headers.*generic.*amd64, but
227 # as of 2024, they have a requirement of a very new glibc, and people report
228 # that installing it is not needed.
229 pkgs
=$
(curl
-s https
://kernel.ubuntu.com
/mainline
/v
$va/amd64
/CHECKSUMS |
awk '$2 ~ /^linux-/ { print $2 }' |
sort -u |
grep -iv 'linux-headers.*generic.*amd64' )
233 if ! dpkg
-s -- "${p%%_*}" 2>&1 |
grep -Fx "Status: install ok installed" &>/dev
/null
; then
234 urls
+=(https
://kernel.ubuntu.com
/mainline
/v
$va/amd64
/$p)
237 if (( ${#urls[@]} >= 1 )); then
246 $chroot apt-get
-y install linux-libre
250 pre
=https
://mirrors.edge.kernel.org
/pub
/linux
/kernel
/people
/kdave
/btrfs-progs
251 tarball
=$
(curl
-s $pre/sha256sums.asc \
252 |
awk '$2 ~ /^btrfs-progs-v/ { print $2 }' |
grep -v -- -rc |
grep "^btrfs-progs-v${ver}.*gz\$" |
sort -V |
tail -n1)
254 dir
=${tarball%.tar.gz}
255 ver
=${dir#btrfs-progs}
256 cur_ver
=$
(btrfs
--version 2>/dev
/null |
awk '{print $2}') ||
:
257 if [[ $ver != "$cur_ver" ]]; then
258 if [[ $HOST2 == $HOSTNAME && $ver != "$($bprogs_dir/btrfs --version 2>/dev/null | awk '{print $2}')" ]]; then
262 sudo
-u iank
tar xzf
$tarball
263 mv ${tarball%.tar.gz} $bprogs_dir
265 apt-get
-y build-dep btrfs-progs
266 sudo
-u iank .
/configure
--disable-documentation
270 $chroot bash
-xe <<EOF
277 if ifclass LINODE
; then
278 mkdir
-p $target/etc
/initramfs-tools
/conf.d
279 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
280 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
281 # man 5 initramfs.conf
282 # /usr/share/doc/klibc-utils/README.ipconfig.gz
283 # /usr/share/initramfs-tools/scripts/functions
284 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
288 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
306 source-directory /etc/network/interfaces.d
312 ##### end network setup #####
315 if ifclass VOL_BULLSEYE_BOOTSTRAP
; then
316 fcopy
/etc
/systemd
/system
/faicheck.service
317 $chroot bash
<<'EOFOUTER'
318 systemctl enable faicheck.service
320 exit 0 # avoid unnecessary stuff in bootstrap vol
325 $chroot bash
<<'EOFOUTER'
326 #### begin .ssh setup ###
329 if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
330 mkdir -p /home/iank/.ssh
331 f=/root/.ssh/authorized_keys
333 cp $f /home/iank/.ssh
335 chown -R 1000:1000 /home/iank/.ssh
336 chmod -R u=Xrw,og= /home/iank/.ssh
338 # remove broken symlinks or the following cp will fail
339 find /home/iank/.ssh -xtype l -exec rm '{}' \;
340 cp -rL /home/iank/.ssh /root
341 chown -R root:root /root/.ssh
346 # # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
347 # but that made a service that started too soon and didn't pick up our
348 # x env vars. instead, copy from the root ssh-agent just the
349 # appropriate things into a new service.
351 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
352 /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
354 #### end .ssh setup ###
356 ## duplicated in ssh-emacs-setup
357 # done here so its setup earlier for convenience
358 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
359 f=/etc/ssh/sshd_config
360 grep -xFq "$line" $f || tee -a $f <<<"$line"
363 # default debian groups (jessie through buster) + adm, root, admin
364 for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
365 if getent group $g >/dev/null; then
370 if getent group systemd-journal >/dev/null; then
371 usermod -aG systemd-journal iank
375 rm -f $target/etc
/resolv.conf
376 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
377 # needed for bitfolk image
378 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
379 systemctl
enable systemd-resolved
380 systemctl start systemd-resolved
385 # reading through the groups that iank is in but user2 isn't,
386 for g
in plugdev audio video cdrom
; do
387 $ROOTCMD usermod
-a -G $g user2