2 # This file is part of Ian Kelling's automated-distro-installer
3 # Copyright (C) 2024 Ian Kelling
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
22 if [[ $EUID != 0 ]]; then
23 echo "$0: error: expected to be root."
27 # ignore this line. hack to make shellcheck ignore $target
28 if [[ ! $target ]]; then target
=; fi
30 if ! type -t fcopy
&>/dev
/null
; then
31 sudo apt-get
-y install fai-client
35 # -i = ignore non-matching class warnings, always exit 0
36 # -B = no backup files
38 # this is also done by FAIBASE/10-misc by default (without B)
39 fcopy
-riB /usr
/local
/bin
41 fcopy
-riB /etc
/apt
/logind.conf.d
43 # this gets done by fai, but just happens too often that
44 # I add sources due to new distros, whatever.
45 fcopy
-riB /etc
/apt
/preferences.d
46 fcopy
-riB /etc
/apt
/sources.list.d
49 src
=$FAI/distro-install-common
/shadow
51 if [[ ! -e $dst && -e $src ]]; then
52 # outside of fai context, we skip this
54 mount
-o bind $src $dst
59 $FAI/distro-install-common
/end
63 ### begin sources install + updates
64 # these get copied in an earlier stage by fai, but leaving it here since
65 # I run this as a single post-fai script to update things that have changed.
67 # this can fail if we need an apt update
68 $ROOTCMD /usr
/bin
/apt-cache policy
>$tmpfile1 ||
:
72 $ROOTCMD /usr
/bin
/apt-cache policy
>$tmpfile2
73 if ! diff -q $tmpfile1 $tmpfile2; then
74 $ROOTCMD /usr
/bin
/apt update
76 # outside of fai, this seems to regularly lead to
77 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
78 # so add a sleep. 1 sec is probably way more than needed.
80 f
=$FAI_ROOT/var
/cache
/apt
/pkgcache.bin
81 if [[ ! -r $f ]] ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
83 while fuser
$FAI_ROOT/var
/lib
/dpkg
/lock
&>/dev
/null
; do
86 if (( i
> 300 )); then
87 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
90 $ROOTCMD apt-get update
93 ### end sources install + updates
96 #### misc configurations
98 if [[ $FAI_ACTION != dirinstall
]] && ! ifclass NOCRYPT
; then
99 if ifclass LINODE
; then
101 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8"
104 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
107 fcopy
-v /usr
/bin
/myncq
109 cat >$target/etc
/systemd
/system
/myncq.service
<<'EOF'
111 Description=fix ncq errors
115 ExecStart=/usr/bin/myncq
119 # https://www.enricozini.org/blog/2017/debian/systemd-07-devices/
120 WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
123 $ROOTCMD bash
<<'EOFOUTER'
124 systemctl enable myncq.service
125 /usr/bin/myncq no-upgrub
129 # per rubens suggestion to make a d16 more stable
130 kd|kw
) cmdline
+=" pci=realloc=off" ;;
134 fi ##### end != dirinstall && != NOCRYPT
137 ###### begin network setup ####
139 # use old names. the idea of them changing between boots has never
140 # happened to me and I usually only have 1 wired or other type.
141 # If I ever do need to care about it, I will.
142 # Strangely this didn't work on kw, so I added kernel cmdline parameter.
143 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
144 ln -sf /dev
/null
$target/etc
/systemd
/network
/99-default.link
147 # bitfolk installer handles the rest
153 # bug fix, somewhere between t9's xorg 1.19.6
154 # and 1.20.1-3ubuntu2
155 # xserver-xorg-video-nouveau 1:1.0.15-3
156 # xorg stopped load nouveau
157 # https://www.linuxquestions.org/questions/slackware-14/kernel-modules-conflicting-with-nouveau-driver-4175623867/
158 # https://nouveau.freedesktop.org/InstallNouveau.html
159 # And now in t11, things got worse with a newer card also not loading
160 # nouveau when it did in t10.
161 if lspci|
grep -q 'VGA compatible controller: NVIDIA'; then
162 mkdir
-p $target/etc
/X11
/xorg.conf.d
/
163 cat >$target/etc
/X11
/xorg.conf.d
/10-nouveau.conf
<<'EOF'
171 # use networkmanager if this host has wireless.
172 if [[ $
(iw dev
) ||
$HOSTNAME == so
]]; then
173 $ROOTCMD bash
-xe <<EOF
174 apt-get -y install network-manager
177 # allow networkmanager to manage interfaces
178 #https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
179 # touch $target/etc/NetworkManager/conf.d/10-globally-managed-devices.conf
181 # in 24.04, netplan takes over and nm won't automatically connect any
182 # ethernet devices. Ya, man NetworkManager helpfully suggests the
183 # config setting device*.managed=1, but of course that isn't REAL
184 # setting, you go to man NetworkManager.conf and find that every
185 # setting has a section. So what section is that setting in? It
186 # doesn't tell you. You have to figure out that it is implied that a
187 # setting x.y means section x, setting y. Ok, but what section is
188 # device*? that isn't documented in the man page either (at least not
189 # properly). But if you read closely, you can intuit that device* is
190 # likely a valid section and then try it. Might as use this same magic
191 # config file name since it is supposed to exist, but I have no idea
192 # if it is still magic. note: In figuring this out, I also removed
193 # /etc/netplan/*, which seemed to have no effect. dunno if it matters.
194 cat >$target/etc
/NetworkManager
/conf.d
/10-globally-managed-devices.conf
<<'EOF'
198 # in a default desktop install, it looks like netplan creates this file under
199 # run/NetworkManager/conf.d in early boot.
201 # By default, dns=default is set in etiona, and dns is just broken.
202 # Maybe with resolvconf it would work, but theres no need for that.
203 # https://wiki.gnome.org/Projects/NetworkManager/DNS
204 cat >$target/etc
/NetworkManager
/conf.d
/99-iank.conf
<<'EOF'
210 if [[ ! $FAI_WRAPPER ||
$SSH_CLIENT ]]; then
211 # for running from fai or remote connections, don't kill the internet
214 if [[ $
(timeout
1 dig +short @
10.2.0.1 -x 10.2.0.2 2>&1 ||
:) == kd.b8.nz.
]] \
215 && ip n show
10.2.0.1 |
grep .
&>/dev
/null
; then
217 $FAI/distro-install-common
/ethusb-static
$ethusb_arg
219 $FAI/distro-install-common
/ethusb-static off
$ethusb_arg
224 cat > $target/etc
/network
/interfaces
<<-EOF
227 iface lo inet loopback
229 iface eth0 inet6 auto
231 source-directory /etc/network/interfaces.d
234 # previously had an else condition after
235 #elif ifclass VM || ifclass LINODE; then
236 # iface $NIC1 inet manual
237 # iface br0 inet dhcp
241 # however, on t9, on startup, br0, became
242 # rename1 and didn't come up. i dunno why,
243 # but the bridge is for vms that I rarely use,
244 # so not bothering to figure it out.
249 if ifclass LINODE
; then
250 mkdir
-p $target/etc
/initramfs-tools
/conf.d
251 # shellcheck disable=SC2154 # comes with LINODE environment
252 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
253 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
254 # man 5 initramfs.conf
255 # /usr/share/doc/klibc-utils/README.ipconfig.gz
256 # /usr/share/initramfs-tools/scripts/functions
257 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
261 if [[ $HOSTNAME == li
]]; then
262 cat > $target/etc
/network
/interfaces
<<-EOF
265 iface lo inet loopback
267 # for the standard network config, uncomment this and comment the lines after it.
268 #iface eth0 inet6 auto
270 iface eth0 inet6 static
271 # this is really a /128. it seems like we need to assign it for ipv6 to work.
272 address 2600:3c00::f03c:91ff:fe6d:baf8/64
275 iface eth0 inet6 static
276 # from a requested /64 pool
277 address 2600:3c00:e000:280::2/64
279 source-directory /etc/network/interfaces.d
285 ##### end network setup #####
288 if ifclass VOL_BULLSEYE_BOOTSTRAP || ifclass VOL_BOOKWORM_BOOTSTRAP
; then
289 fcopy
/etc
/systemd
/system
/faicheck.service
290 $ROOTCMD bash
<<'EOFOUTER'
291 systemctl enable faicheck.service
293 exit 0 # avoid unnecessary stuff in bootstrap vol
298 $ROOTCMD bash
<<'EOFOUTER'
299 #### begin .ssh setup ###
302 if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
303 mkdir -p /home/iank/.ssh
304 f=/root/.ssh/authorized_keys
306 cp $f /home/iank/.ssh
308 chown -R 1000:1000 /home/iank/.ssh
309 chmod -R u=Xrw,og= /home/iank/.ssh
311 # remove broken symlinks or the following cp will fail
312 find /home/iank/.ssh -xtype l -exec rm '{}' \;
313 cp -rL /home/iank/.ssh /root
314 chown -R root:root /root/.ssh
319 # # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
320 # but that made a service that started too soon and didn't pick up our
321 # x env vars. instead, copy from the root ssh-agent just the
322 # appropriate things into a new service.
324 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
325 /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
327 #### end .ssh setup ###
329 ## duplicated in ssh-emacs-setup
330 # done here so its setup earlier for convenience
331 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
332 f=/etc/ssh/sshd_config
333 grep -xFq "$line" $f || tee -a $f <<<"$line"
336 # default debian groups (jessie through buster) + adm, root, admin
337 for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
338 if getent group $g >/dev/null; then
343 if getent group systemd-journal >/dev/null; then
344 usermod -aG systemd-journal iank
348 rm -f $target/etc
/resolv.conf
349 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
350 # needed for bitfolk image
351 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
352 systemctl
enable systemd-resolved
353 systemctl start systemd-resolved
358 # reading through the groups that iank is in but user2 isn't,
359 for g
in plugdev audio video cdrom
; do
360 $ROOTCMD usermod
-a -G $g user2
363 ## begin get new kernel and btrfs-progs ##
366 # on sy t11, severe wifi degredation on 6.8
367 # on so t11, no x11 display on 6.8
368 $FAI/distro-install-common
/install-mainline-kernel-debs stable
371 if ! $ROOTCMD dpkg
-s -- freesh-archive-keyring
2>&1 |
grep -Fx "Status: install ok installed" &>/dev
/null
; then
372 apt-get
-y install wget
373 wget
-O /target
/tmp
/x.deb https
://linux-libre.fsfla.org
/pub
/linux-libre
/freesh
/pool
/main
/f
/freesh-archive-keyring
/freesh-archive-keyring_1.1_all.deb
374 $ROOTCMD dpkg
-i /tmp
/x.deb
375 $ROOTCMD apt-get update
376 $ROOTCMD apt-get
-y install linux-libre
381 pre
=https
://mirrors.edge.kernel.org
/pub
/linux
/kernel
/people
/kdave
/btrfs-progs
382 tarball
=$
(curl
-s $pre/sha256sums.asc \
383 |
awk '$2 ~ /^btrfs-progs-v/ { print $2 }' |
grep -v -- -rc |
grep "^btrfs-progs-v.*gz\$" |
sort -V |
tail -n1)
385 dir
=${tarball%.tar.gz}
386 ver
=${dir#btrfs-progs-}
387 cur_ver
=$
($ROOTCMD btrfs
--version 2>/dev
/null |
awk '{print $2}') ||
:
389 if [[ $FAI_ROOT == / ]]; then
390 bp_dir
=/a
/opt
/btrfs-progs-release
392 bp_dir
=$FAI/distro-install-common
/btrfs-progs-release
394 if [[ $ver != "$cur_ver" ]]; then
395 if [[ $ver != "$($bp_dir/btrfs --version 2>/dev/null | awk '{print $2}')" ]]; then
399 $ROOTCMD apt-get
-y build-dep btrfs-progs
400 # no docs cuz I didn't want to bother fixing error of missing docs dependencies
401 $ROOTCMD bash
-xe <<EOF
402 cd /tmp/${tarball%.tar.gz}
403 ./configure --disable-documentation
407 # If our desktop is HOST2, will we btrbk this latest bprogs to other
409 if [[ -s /a
/bin
/bash_unpublished
/source-state
]]; then
410 source /a
/bin
/bash_unpublished
/source-state
412 if [[ $HOST2 == "$HOSTNAME" && $FAI_ROOT != / ]]; then
414 chown
-R iank
:iank
$target/tmp
/${tarball%.tar.gz}
415 mv $target/tmp
/${tarball%.tar.gz} $bp_dir
418 if ! $ROOTCMD dpkg
-s -- build-essential
2>&1 |
grep -Fx "Status: install ok installed" &>/dev
/null
; then
419 $ROOTCMD apt-get
-y install build-essential
422 if [[ $FAI_ROOT == / ]]; then
423 cd /a
/opt
/btrfs-progs-release
426 mkdir
-p $target/tmp
/bprogs
427 mount
-o bind $bp_dir $target/tmp
/bprogs
428 $ROOTCMD bash
-xe <<EOF
435 ## end get new kernel and btrfs-progs ##