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 if ! type -t fcopy
&>/dev
/null
; then
28 sudo apt-get
-y install fai-client
32 # -i = ignore non-matching class warnings, always exit 0
33 # -B = no backup files
35 # this is also done by FAIBASE/10-misc by default (without B)
36 fcopy
-riB /usr
/local
/bin
38 fcopy
-riB /etc
/apt
/logind.conf.d
40 # this gets done by fai, but just happens too often that
41 # I add sources due to new distros, whatever.
42 fcopy
-riB /etc
/apt
/preferences.d
43 fcopy
-riB /etc
/apt
/sources.list.d
46 src
=$FAI/distro-install-common
/shadow
48 if [[ ! -e $dst && -e $src ]]; then
49 # outside of fai context, we skip this
51 mount
-o bind $src $dst
56 $FAI/distro-install-common
/end
60 ### begin sources install + updates
61 # these get copied in an earlier stage by fai, but leaving it here since
62 # I run this as a single post-fai script to update things that have changed.
64 # this can fail if we need an apt update
65 $ROOTCMD /usr
/bin
/apt-cache policy
>$tmpfile1 ||
:
69 $ROOTCMD /usr
/bin
/apt-cache policy
>$tmpfile2
70 if ! diff -q $tmpfile1 $tmpfile2; then
71 $ROOTCMD /usr
/bin
/apt update
73 # outside of fai, this seems to regularly lead to
74 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
75 # so add a sleep. 1 sec is probably way more than needed.
77 f
=$FAI_ROOT/var
/cache
/apt
/pkgcache.bin
78 if [[ ! -r $f ]] ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
80 while fuser
$FAI_ROOT/var
/lib
/dpkg
/lock
&>/dev
/null
; do
83 if (( i
> 300 )); then
84 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
87 $ROOTCMD apt-get update
90 ### end sources install + updates
93 #### misc configurations
95 if [[ $FAI_ACTION != dirinstall
]] && ! ifclass NOCRYPT
; then
96 if ifclass LINODE
; then
98 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8"
101 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
104 fcopy
-v /usr
/bin
/myncq
106 cat >$target/etc
/systemd
/system
/myncq.service
<<'EOF'
108 Description=fix ncq errors
112 ExecStart=/usr/bin/myncq
116 # https://www.enricozini.org/blog/2017/debian/systemd-07-devices/
117 WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
120 $ROOTCMD bash
<<'EOFOUTER'
121 systemctl enable myncq.service
122 /usr/bin/myncq no-upgrub
126 # per rubens suggestion to make a d16 more stable
127 kd|kw
) cmdline
+=" pci=realloc=off" ;;
131 fi ##### end != dirinstall && != NOCRYPT
134 ###### begin network setup ####
136 # use old names. the idea of them changing between boots has never
137 # happened to me and I usually only have 1 wired or other type.
138 # If I ever do need to care about it, I will.
139 # Strangely this didn't work on kw, so I added kernel cmdline parameter.
140 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
141 ln -sf /dev
/null
$target/etc
/systemd
/network
/99-default.link
144 # bitfolk installer handles the rest
150 # bug fix, somewhere between t9's xorg 1.19.6
151 # and 1.20.1-3ubuntu2
152 # xserver-xorg-video-nouveau 1:1.0.15-3
153 # xorg stopped load nouveau
154 # https://www.linuxquestions.org/questions/slackware-14/kernel-modules-conflicting-with-nouveau-driver-4175623867/
155 # https://nouveau.freedesktop.org/InstallNouveau.html
156 # And now in t11, things got worse with a newer card also not loading
157 # nouveau when it did in t10.
158 if lspci|
grep -q 'VGA compatible controller: NVIDIA'; then
159 mkdir
-p $target/etc
/X11
/xorg.conf.d
/
160 cat >$target/etc
/X11
/xorg.conf.d
/10-nouveau.conf
<<'EOF'
168 # use networkmanager if this host has wireless.
169 if [[ $
(iw dev
) ]]; then
170 $ROOTCMD bash
-xe <<EOF
171 apt-get -y install network-manager
174 # allow networkmanager to manage interfaces
175 #https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
176 touch $target/etc
/NetworkManager
/conf.d
/10-globally-managed-devices.conf
177 # in a default desktop install, it looks like netplan creates this file under
178 # run/NetworkManager/conf.d in early boot.
180 # By default, dns=default is set in etiona, and dns is just broken.
181 # Maybe with resolvconf it would work, but theres no need for that.
182 # https://wiki.gnome.org/Projects/NetworkManager/DNS
183 cat >$target/etc
/NetworkManager
/conf.d
/99-iank.conf
<<'EOF'
188 $FAI/distro-install-common
/ethusb-static
189 if [[ $
(dig +short @
10.2.0.1 -x 10.2.0.2 2>&1 ||
:) == kd.b8.nz.
]] \
190 && ip n show
10.2.0.1 |
grep .
&>/dev
/null
; then
191 : # we are at home. note: logic duplicated in btrbk-run
193 $FAI/distro-install-common
/ethusb-nm
198 cat > $target/etc
/network
/interfaces
<<-EOF
201 iface lo inet loopback
203 iface eth0 inet6 auto
205 source-directory /etc/network/interfaces.d
208 # previously had an else condition after
209 #elif ifclass VM || ifclass LINODE; then
210 # iface $NIC1 inet manual
211 # iface br0 inet dhcp
215 # however, on t9, on startup, br0, became
216 # rename1 and didn't come up. i dunno why,
217 # but the bridge is for vms that I rarely use,
218 # so not bothering to figure it out.
223 if ifclass LINODE
; then
224 mkdir
-p $target/etc
/initramfs-tools
/conf.d
225 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
226 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
227 # man 5 initramfs.conf
228 # /usr/share/doc/klibc-utils/README.ipconfig.gz
229 # /usr/share/initramfs-tools/scripts/functions
230 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
234 if [[ $HOSTNAME == li
]]; then
235 cat > $target/etc
/network
/interfaces
<<-EOF
238 iface lo inet loopback
240 # for the standard network config, uncomment this and comment the lines after it.
241 #iface eth0 inet6 auto
243 iface eth0 inet6 static
244 # this is really a /128. it seems like we need to assign it for ipv6 to work.
245 address 2600:3c00::f03c:91ff:fe6d:baf8/64
248 iface eth0 inet6 static
249 # from a requested /64 pool
250 address 2600:3c00:e000:280::2/64
252 source-directory /etc/network/interfaces.d
258 ##### end network setup #####
261 if ifclass VOL_BULLSEYE_BOOTSTRAP || ifclass VOL_BOOKWORM_BOOTSTRAP
; then
262 fcopy
/etc
/systemd
/system
/faicheck.service
263 $ROOTCMD bash
<<'EOFOUTER'
264 systemctl enable faicheck.service
266 exit 0 # avoid unnecessary stuff in bootstrap vol
271 $ROOTCMD bash
<<'EOFOUTER'
272 #### begin .ssh setup ###
275 if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
276 mkdir -p /home/iank/.ssh
277 f=/root/.ssh/authorized_keys
279 cp $f /home/iank/.ssh
281 chown -R 1000:1000 /home/iank/.ssh
282 chmod -R u=Xrw,og= /home/iank/.ssh
284 # remove broken symlinks or the following cp will fail
285 find /home/iank/.ssh -xtype l -exec rm '{}' \;
286 cp -rL /home/iank/.ssh /root
287 chown -R root:root /root/.ssh
292 # # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
293 # but that made a service that started too soon and didn't pick up our
294 # x env vars. instead, copy from the root ssh-agent just the
295 # appropriate things into a new service.
297 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
298 /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
300 #### end .ssh setup ###
302 ## duplicated in ssh-emacs-setup
303 # done here so its setup earlier for convenience
304 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
305 f=/etc/ssh/sshd_config
306 grep -xFq "$line" $f || tee -a $f <<<"$line"
309 # default debian groups (jessie through buster) + adm, root, admin
310 for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
311 if getent group $g >/dev/null; then
316 if getent group systemd-journal >/dev/null; then
317 usermod -aG systemd-journal iank
321 rm -f $target/etc
/resolv.conf
322 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
323 # needed for bitfolk image
324 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
325 systemctl
enable systemd-resolved
326 systemctl start systemd-resolved
331 # reading through the groups that iank is in but user2 isn't,
332 for g
in plugdev audio video cdrom
; do
333 $ROOTCMD usermod
-a -G $g user2
337 ## begin get new kernel and btrfs-progs ##
340 $FAI/distro-install-common
/install-stable-kernel-debs
343 $ROOTCMD apt-get
-y install linux-libre
347 pre
=https
://mirrors.edge.kernel.org
/pub
/linux
/kernel
/people
/kdave
/btrfs-progs
348 tarball
=$
(curl
-s $pre/sha256sums.asc \
349 |
awk '$2 ~ /^btrfs-progs-v/ { print $2 }' |
grep -v -- -rc |
grep "^btrfs-progs-v.*gz\$" |
sort -V |
tail -n1)
351 dir
=${tarball%.tar.gz}
352 ver
=${dir#btrfs-progs-}
353 cur_ver
=$
($ROOTCMD btrfs
--version 2>/dev
/null |
awk '{print $2}') ||
:
355 if [[ $FAI_ROOT == / ]]; then
356 bp_dir
=/a
/opt
/btrfs-progs-release
358 bp_dir
=$FAI/distro-install-common
/btrfs-progs-release
360 if [[ $ver != "$cur_ver" ]]; then
361 if [[ $ver != "$($bp_dir/btrfs --version 2>/dev/null | awk '{print $2}')" ]]; then
365 $ROOTCMD apt-get
-y build-dep btrfs-progs
366 # no docs cuz I didn't want to bother fixing error of missing docs dependencies
367 $ROOTCMD bash
-xe <<EOF
368 cd /tmp/${tarball%.tar.gz}
369 ./configure --disable-documentation
373 # If our desktop is HOST2, will we btrbk this latest bprogs to other
375 if [[ -s /a
/bin
/bash_unpublished
/source-state
]]; then
376 source /a
/bin
/bash_unpublished
/source-state
378 if [[ $HOST2 == "$HOSTNAME" && $FAI_ROOT != / ]]; then
380 chown
-R iank
:iank
$target/tmp
/${tarball%.tar.gz}
381 mv $target/tmp
/${tarball%.tar.gz} $bp_dir
384 if ! $ROOTCMD dpkg
-s -- build-essential
2>&1 |
grep -Fx "Status: install ok installed" &>/dev
/null
; then
385 $ROOTCMD apt-get
-y install build-essential
388 if [[ $FAI_ROOT == / ]]; then
389 cd /a
/opt
/btrfs-progs-release
392 mkdir
-p $target/tmp
/bprogs
393 mount
-o bind $bp_dir $target/tmp
/bprogs
394 $ROOTCMD bash
-xe <<EOF
401 ## end get new kernel and btrfs-progs ##