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'
179 if [[ $HOSTNAME == frodo
]]; then
180 cat > $target/etc
/network
/interfaces
<<-EOF
183 iface lo inet loopback
184 iface eth0 inet static
187 source-directory /etc/network/interfaces.d
192 cat > $target/etc
/network
/interfaces
<<-EOF
195 iface lo inet loopback
197 iface eth0 inet6 auto
199 source-directory /etc/network/interfaces.d
202 # previously had an else condition after
203 #elif ifclass VM || ifclass LINODE; then
204 # iface $NIC1 inet manual
205 # iface br0 inet dhcp
209 # however, on t9, on startup, br0, became
210 # rename1 and didn't come up. i dunno why,
211 # but the bridge is for vms that I rarely use,
212 # so not bothering to figure it out.
217 if ifclass LINODE
; then
218 mkdir
-p $target/etc
/initramfs-tools
/conf.d
219 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
220 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
221 # man 5 initramfs.conf
222 # /usr/share/doc/klibc-utils/README.ipconfig.gz
223 # /usr/share/initramfs-tools/scripts/functions
224 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
228 if [[ $HOSTNAME == li
]]; then
229 cat > $target/etc
/network
/interfaces
<<-EOF
232 iface lo inet loopback
234 # for the standard network config, uncomment this and comment the lines after it.
235 #iface eth0 inet6 auto
237 iface eth0 inet6 static
238 # this is really a /128. it seems like we need to assign it for ipv6 to work.
239 address 2600:3c00::f03c:91ff:fe6d:baf8/64
242 iface eth0 inet6 static
243 # from a requested /64 pool
244 address 2600:3c00:e000:280::2/64
246 source-directory /etc/network/interfaces.d
252 ##### end network setup #####
255 if ifclass VOL_BULLSEYE_BOOTSTRAP
; then
256 fcopy
/etc
/systemd
/system
/faicheck.service
257 chroot
$FAI_ROOT bash
<<'EOFOUTER'
258 systemctl enable faicheck.service
260 exit 0 # avoid unnecessary stuff in bootstrap vol
265 chroot
$FAI_ROOT bash
<<'EOFOUTER'
266 #### begin .ssh setup ###
269 if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
270 mkdir -p /home/iank/.ssh
271 f=/root/.ssh/authorized_keys
273 cp $f /home/iank/.ssh
275 chown -R 1000:1000 /home/iank/.ssh
276 chmod -R u=Xrw,og= /home/iank/.ssh
278 # remove broken symlinks or the following cp will fail
279 find /home/iank/.ssh -xtype l -exec rm '{}' \;
280 cp -rL /home/iank/.ssh /root
281 chown -R root:root /root/.ssh
286 # # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
287 # but that made a service that started too soon and didn't pick up our
288 # x env vars. instead, copy from the root ssh-agent just the
289 # appropriate things into a new service.
290 rm -f /home/iank/.config/systemd/user/default.target.wants/ssh-agent.service
292 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
293 /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
295 #### end .ssh setup ###
297 ## duplicated in ssh-emacs-setup
298 # done here so its setup earlier for convenience
299 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
300 f=/etc/ssh/sshd_config
301 grep -xFq "$line" $f || tee -a $f <<<"$line"
304 # default debian groups (jessie through buster) + adm, root, admin
305 for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
306 if getent group $g >/dev/null; then
311 if getent group systemd-journal >/dev/null; then
312 usermod -aG systemd-journal iank
316 rm -f $target/etc
/resolv.conf
317 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
318 # needed for bitfolk image
319 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
320 systemctl
enable systemd-resolved
321 systemctl start systemd-resolved
326 # reading through the groups that iank is in but user2 isn't,
327 for g
in plugdev audio video cdrom
; do
328 $ROOTCMD usermod
-a -G $g user2