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 # this gets done by fai, but just happens too often that
32 # I add sources due to new distros, whatever.
33 fcopy
-riB /etc
/apt
/preferences.d
34 fcopy
-riB /etc
/apt
/sources.list.d
37 src
=$FAI/distro-install-common
/shadow
39 if [[ ! -e $dst && -e $src ]]; then
40 # outside of fai context, we skip this
42 mount
-o bind $src $dst
45 $FAI/distro-install-common
/end
49 ### begin sources install + updates
50 # these get copied in an earlier stage by fai, but leaving it here since
51 # I run this as a single post-fai script to update things that have changed.
53 # this can fail if we need an apt update
54 chroot
$FAI_ROOT /usr
/bin
/apt-cache policy
>$tmpfile1 ||
:
58 chroot
$FAI_ROOT /usr
/bin
/apt-cache policy
>$tmpfile2
59 if ! diff -q $tmpfile1 $tmpfile2; then
60 chroot
$FAI_ROOT /usr
/bin
/apt update
62 # outside of fai, this seems to regularly lead to
63 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
64 # so add a sleep. 1 sec is probably way more than needed.
66 f
=$FAI_ROOT/var
/cache
/apt
/pkgcache.bin
67 if [[ ! -r $f ]] ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
69 while fuser
$FAI_ROOT/var
/lib
/dpkg
/lock
&>/dev
/null
; do
72 if (( i
> 300 )); then
73 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
76 $ROOTCMD apt-get update
79 ### end sources install + updates
82 #### misc configurations
85 if [[ $FAI_ACTION != dirinstall
]] && ! ifclass NOCRYPT
; then
86 if ifclass LINODE
; then
88 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8"
91 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
94 fcopy
-v /usr
/bin
/myncq
96 cat >$target/etc
/systemd
/system
/myncq.service
<<'EOF'
98 Description=fix ncq errors
102 ExecStart=/usr/bin/myncq
106 # https://www.enricozini.org/blog/2017/debian/systemd-07-devices/
107 WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
110 chroot
$FAI_ROOT bash
<<'EOFOUTER'
111 systemctl enable myncq.service
112 /usr/bin/myncq no-upgrub
116 # per rubens suggestion to make a d16 more stable
117 kd|kw
) cmdline
+=" pci=realloc=off" ;;
121 fi ##### end != dirinstall && != NOCRYPT
124 ###### begin network setup ####
126 # use old names. the idea of them changing between boots has never
127 # happened to me and I usually only have 1 wired or other type.
128 # If I ever do need to care about it, I will.
129 # Strangely this didn't work on kw, so I added kernel cmdline parameter.
130 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
131 ln -sf /dev
/null
$target/etc
/systemd
/network
/99-default.link
134 # bitfolk installer handles the rest
140 # bug fix, somewhere between t9's xorg 1.19.6
141 # and 1.20.1-3ubuntu2
142 # xserver-xorg-video-nouveau 1:1.0.15-3
143 # xorg stopped load nouveau
144 # https://www.linuxquestions.org/questions/slackware-14/kernel-modules-conflicting-with-nouveau-driver-4175623867/
145 # https://nouveau.freedesktop.org/InstallNouveau.html
146 if lspci|
grep -q 'GeForce GTX 6[0-9][0-9]\]'; then
147 mkdir
-p $target/etc
/X11
/xorg.conf.d
/
148 cat >$target/etc
/X11
/xorg.conf.d
/10-nouveau.conf
<<'EOF'
156 # use networkmanager if this host has wireless.
157 if [[ $HOSTNAME == bo
]] ||
type -p iw
&>/dev
/null
&& [[ $
(iw dev
) ]]; then
158 chroot
$FAI_ROOT bash
<<EOF
159 apt-get -y install network-manager
162 # allow networkmanager to manage interfaces
163 #https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
164 touch $target/etc
/NetworkManager
/conf.d
/10-globally-managed-devices.conf
165 # in a default desktop install, it looks like netplan creates this file under
166 # run/NetworkManager/conf.d in early boot.
168 # By default, dns=default is set in etiona, and dns is just broken.
169 # Maybe with resolvconf it would work, but theres no need for that.
170 # https://wiki.gnome.org/Projects/NetworkManager/DNS
171 cat >$target/etc
/NetworkManager
/conf.d
/99-iank.conf
<<'EOF'
175 if [[ $HOSTNAME == frodo
]]; then
176 cat > $target/etc
/network
/interfaces
<<-EOF
179 iface lo inet loopback
180 iface eth0 inet static
183 source-directory /etc/network/interfaces.d
188 cat > $target/etc
/network
/interfaces
<<-EOF
191 iface lo inet loopback
193 iface eth0 inet6 auto
195 source-directory /etc/network/interfaces.d
198 # previously had an else condition after
199 #elif ifclass VM || ifclass LINODE; then
200 # iface $NIC1 inet manual
201 # iface br0 inet dhcp
205 # however, on t9, on startup, br0, became
206 # rename1 and didn't come up. i dunno why,
207 # but the bridge is for vms that I rarely use,
208 # so not bothering to figure it out.
213 if ifclass LINODE
; then
214 mkdir
-p $target/etc
/initramfs-tools
/conf.d
215 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
216 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
217 # man 5 initramfs.conf
218 # /usr/share/doc/klibc-utils/README.ipconfig.gz
219 # /usr/share/initramfs-tools/scripts/functions
220 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
224 if [[ $HOSTNAME == li
]]; then
225 cat > $target/etc
/network
/interfaces
<<-EOF
228 iface lo inet loopback
230 # for the standard network config, uncomment this and comment the lines after it.
231 #iface eth0 inet6 auto
233 iface eth0 inet6 static
234 # this is really a /128. it seems like we need to assign it for ipv6 to work.
235 address 2600:3c00::f03c:91ff:fe6d:baf8/64
238 iface eth0 inet6 static
239 # from a requested /64 pool
240 address 2600:3c00:e000:280::2/64
242 source-directory /etc/network/interfaces.d
248 ##### end network setup #####
251 if ifclass VOL_BULLSEYE_BOOTSTRAP
; then
252 fcopy
/etc
/systemd
/system
/faicheck.service
253 chroot
$FAI_ROOT bash
<<'EOFOUTER'
254 systemctl enable faicheck.service
256 exit 0 # avoid unnecessary stuff in bootstrap vol
261 chroot
$FAI_ROOT bash
<<'EOFOUTER'
262 #### begin .ssh setup ###
265 if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
266 mkdir -p /home/iank/.ssh
267 f=/root/.ssh/authorized_keys
269 cp $f /home/iank/.ssh
271 chown -R 1000:1000 /home/iank/.ssh
272 chmod -R u=Xrw,og= /home/iank/.ssh
274 # remove broken symlinks or the following cp will fail
275 find /home/iank/.ssh -xtype l -exec rm '{}' \;
276 cp -rL /home/iank/.ssh /root
277 chown -R root:root /root/.ssh
282 # # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
283 # but that made a service that started too soon and didn't pick up our
284 # x env vars. instead, copy from the root ssh-agent just the
285 # appropriate things into a new service.
286 rm -f /home/iank/.config/systemd/user/default.target.wants/ssh-agent.service
288 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
289 /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
291 #### end .ssh setup ###
293 ## duplicated in ssh-emacs-setup
294 # done here so its setup earlier for convenience
295 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
296 f=/etc/ssh/sshd_config
297 grep -xFq "$line" $f || tee -a $f <<<"$line"
300 # default debian groups (jessie through buster) + adm, root, admin
301 for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
302 if getent group $g >/dev/null; then
307 if getent group systemd-journal >/dev/null; then
308 usermod -aG systemd-journal iank
312 rm -f $target/etc
/resolv.conf
313 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
314 # needed for bitfolk image
315 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
316 systemctl
enable systemd-resolved
317 systemctl start systemd-resolved
322 # reading through the groups that iank is in but user2 isn't,
323 for g
in plugdev audio video cdrom
; do
324 $ROOTCMD usermod
-a -G $g user2