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
) ]]; 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
180 # in a default desktop install, it looks like netplan creates this file under
181 # run/NetworkManager/conf.d in early boot.
183 # By default, dns=default is set in etiona, and dns is just broken.
184 # Maybe with resolvconf it would work, but theres no need for that.
185 # https://wiki.gnome.org/Projects/NetworkManager/DNS
186 cat >$target/etc
/NetworkManager
/conf.d
/99-iank.conf
<<'EOF'
192 if [[ ! $FAI_WRAPPER ||
$SSH_CLIENT ]]; then
193 # for running from fai or remote connections, don't kill the internet
196 if [[ $
(dig +short @
10.2.0.1 -x 10.2.0.2 2>&1 ||
:) == kd.b8.nz.
]] \
197 && ip n show
10.2.0.1 |
grep .
&>/dev
/null
; then
199 $FAI/distro-install-common
/ethusb-static
$ethusb_arg
201 $FAI/distro-install-common
/ethusb-static off
$ethusb_arg
206 cat > $target/etc
/network
/interfaces
<<-EOF
209 iface lo inet loopback
211 iface eth0 inet6 auto
213 source-directory /etc/network/interfaces.d
216 # previously had an else condition after
217 #elif ifclass VM || ifclass LINODE; then
218 # iface $NIC1 inet manual
219 # iface br0 inet dhcp
223 # however, on t9, on startup, br0, became
224 # rename1 and didn't come up. i dunno why,
225 # but the bridge is for vms that I rarely use,
226 # so not bothering to figure it out.
231 if ifclass LINODE
; then
232 mkdir
-p $target/etc
/initramfs-tools
/conf.d
233 # shellcheck disable=SC2154 # comes with LINODE environment
234 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
235 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
236 # man 5 initramfs.conf
237 # /usr/share/doc/klibc-utils/README.ipconfig.gz
238 # /usr/share/initramfs-tools/scripts/functions
239 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
243 if [[ $HOSTNAME == li
]]; then
244 cat > $target/etc
/network
/interfaces
<<-EOF
247 iface lo inet loopback
249 # for the standard network config, uncomment this and comment the lines after it.
250 #iface eth0 inet6 auto
252 iface eth0 inet6 static
253 # this is really a /128. it seems like we need to assign it for ipv6 to work.
254 address 2600:3c00::f03c:91ff:fe6d:baf8/64
257 iface eth0 inet6 static
258 # from a requested /64 pool
259 address 2600:3c00:e000:280::2/64
261 source-directory /etc/network/interfaces.d
267 ##### end network setup #####
270 if ifclass VOL_BULLSEYE_BOOTSTRAP || ifclass VOL_BOOKWORM_BOOTSTRAP
; then
271 fcopy
/etc
/systemd
/system
/faicheck.service
272 $ROOTCMD bash
<<'EOFOUTER'
273 systemctl enable faicheck.service
275 exit 0 # avoid unnecessary stuff in bootstrap vol
280 $ROOTCMD bash
<<'EOFOUTER'
281 #### begin .ssh setup ###
284 if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
285 mkdir -p /home/iank/.ssh
286 f=/root/.ssh/authorized_keys
288 cp $f /home/iank/.ssh
290 chown -R 1000:1000 /home/iank/.ssh
291 chmod -R u=Xrw,og= /home/iank/.ssh
293 # remove broken symlinks or the following cp will fail
294 find /home/iank/.ssh -xtype l -exec rm '{}' \;
295 cp -rL /home/iank/.ssh /root
296 chown -R root:root /root/.ssh
301 # # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
302 # but that made a service that started too soon and didn't pick up our
303 # x env vars. instead, copy from the root ssh-agent just the
304 # appropriate things into a new service.
306 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
307 /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
309 #### end .ssh setup ###
311 ## duplicated in ssh-emacs-setup
312 # done here so its setup earlier for convenience
313 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
314 f=/etc/ssh/sshd_config
315 grep -xFq "$line" $f || tee -a $f <<<"$line"
318 # default debian groups (jessie through buster) + adm, root, admin
319 for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
320 if getent group $g >/dev/null; then
325 if getent group systemd-journal >/dev/null; then
326 usermod -aG systemd-journal iank
330 rm -f $target/etc
/resolv.conf
331 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
332 # needed for bitfolk image
333 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
334 systemctl
enable systemd-resolved
335 systemctl start systemd-resolved
340 # reading through the groups that iank is in but user2 isn't,
341 for g
in plugdev audio video cdrom
; do
342 $ROOTCMD usermod
-a -G $g user2
345 ## begin get new kernel and btrfs-progs ##
348 # on sy t11, severe wifi degredation on 6.8
349 # on so t11, no x11 display on 6.8
350 $FAI/distro-install-common
/install-mainline-kernel-debs stable
353 if ! $ROOTCMD dpkg
-s -- freesh-archive-keyring
2>&1 |
grep -Fx "Status: install ok installed" &>/dev
/null
; then
354 apt-get
-y install wget
355 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
356 $ROOTCMD dpkg
-i /tmp
/x.deb
357 $ROOTCMD apt-get update
358 $ROOTCMD apt-get
-y install linux-libre
363 pre
=https
://mirrors.edge.kernel.org
/pub
/linux
/kernel
/people
/kdave
/btrfs-progs
364 tarball
=$
(curl
-s $pre/sha256sums.asc \
365 |
awk '$2 ~ /^btrfs-progs-v/ { print $2 }' |
grep -v -- -rc |
grep "^btrfs-progs-v.*gz\$" |
sort -V |
tail -n1)
367 dir
=${tarball%.tar.gz}
368 ver
=${dir#btrfs-progs-}
369 cur_ver
=$
($ROOTCMD btrfs
--version 2>/dev
/null |
awk '{print $2}') ||
:
371 if [[ $FAI_ROOT == / ]]; then
372 bp_dir
=/a
/opt
/btrfs-progs-release
374 bp_dir
=$FAI/distro-install-common
/btrfs-progs-release
376 if [[ $ver != "$cur_ver" ]]; then
377 if [[ $ver != "$($bp_dir/btrfs --version 2>/dev/null | awk '{print $2}')" ]]; then
381 $ROOTCMD apt-get
-y build-dep btrfs-progs
382 # no docs cuz I didn't want to bother fixing error of missing docs dependencies
383 $ROOTCMD bash
-xe <<EOF
384 cd /tmp/${tarball%.tar.gz}
385 ./configure --disable-documentation
389 # If our desktop is HOST2, will we btrbk this latest bprogs to other
391 if [[ -s /a
/bin
/bash_unpublished
/source-state
]]; then
392 source /a
/bin
/bash_unpublished
/source-state
394 if [[ $HOST2 == "$HOSTNAME" && $FAI_ROOT != / ]]; then
396 chown
-R iank
:iank
$target/tmp
/${tarball%.tar.gz}
397 mv $target/tmp
/${tarball%.tar.gz} $bp_dir
400 if ! $ROOTCMD dpkg
-s -- build-essential
2>&1 |
grep -Fx "Status: install ok installed" &>/dev
/null
; then
401 $ROOTCMD apt-get
-y install build-essential
404 if [[ $FAI_ROOT == / ]]; then
405 cd /a
/opt
/btrfs-progs-release
408 mkdir
-p $target/tmp
/bprogs
409 mount
-o bind $bp_dir $target/tmp
/bprogs
410 $ROOTCMD bash
-xe <<EOF
417 ## end get new kernel and btrfs-progs ##