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 FABASE/10-misc by default (without B)
32 src
=$FAI/distro-install-common
/shadow
34 if [[ ! -e $dst && -e $src ]]; then
35 # outside of fai context, we skip this
37 mount
-o bind $src $dst
40 $FAI/distro-install-common
/end
44 ### begin sources install + updates
45 # these get copied in an earlier stage by fai, but leaving it here since
46 # I run this as a single post-fai script to update things that have changed.
48 # this can fail if we need an apt update
49 chroot
$FAI_ROOT /usr
/bin
/apt-cache policy
>$tmpfile1 ||
:
52 chroot
$FAI_ROOT /usr
/bin
/apt-cache policy
>$tmpfile2
53 if ! diff -q $tmpfile1 $tmpfile2; then
54 chroot
$FAI_ROOT /usr
/bin
/apt update
56 # outside of fai, this seems to regularly lead to
57 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
58 # so add a sleep. 1 sec is probably way more than needed.
60 f
=$FAI_ROOT/var
/cache
/apt
/pkgcache.bin
61 if [[ ! -r $f ]] ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
63 while fuser
$FAI_ROOT/var
/lib
/dpkg
/lock
&>/dev
/null
; do
66 if (( i
> 300 )); then
67 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
70 $ROOTCMD apt-get update
73 ### end sources install + updates
76 #### misc configurations
77 chroot
$FAI_ROOT bash
<<'EOFOUTER'
78 if getent group systemd-journal >/dev/null; then
79 # makes the journal be saved to disk.
80 mkdir -p /var/log/journal
81 chmod 755 /var/log/journal
83 debconf-set-selections <<EOF
84 kexec-tools kexec-tools/load_kexec boolean false
86 apt-get install -y pxe-kexec
88 # this is usefull. Only thing reason I see this being disabled by default is
89 # that a normal user can disrupt the system, eg cause a reboot.
90 sed -i '$a kernel.sysrq=1
91 /^kernel.sysrq=/d' /etc/sysctl.conf
96 if [[ $FAI_ACTION != dirinstall
]] && ! ifclass NOCRYPT
; then
97 # luks options, see man systemd-cryptsetup-generator
98 # all i know is that with luks.crypttab=no, swap still timed out on boot.
99 # and with rd.luks.crypttab=no, it works.
100 if ifclass LINODE
; then
102 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8"
105 cmdline
="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
107 # https://wiki.archlinux.org/index.php/Solid_state_drive#Resolving_NCQ_errors
108 # evo-870 doesnt get along well with d16 with etiona.
109 # the number is based on dmesg errors
110 kd
) cmdline
+=" libata.force=4.00:noncq" ;;
111 # per rubens suggestion to make a d16 more stable
112 kd|kw
) cmdline
+=" pci=realloc=off" ;;
116 cat >$FAI_ROOT/etc
/grub.d
/40_custom
<<EOF
119 # This file provides an easy way to add custom menu entries. Simply type the
120 # menu entries you want to add after this comment. Be careful not to change
121 # the 'exec tail' line above.
123 # https://www.coreboot.org/Serial_console # tty
124 # but removed unneeded stuff
126 serial --speed=$speed
127 terminal_input --append serial
128 terminal_output --append serial
132 chroot
$FAI_ROOT bash
<<EOF
134 # https://askubuntu.com/questions/33416/how-do-i-disable-the-boot-splash-screen-and-only-show-kernel-and-boot-text-inst
135 # we remove quiet and splash, and all thats left is what we want
137 if grep -qF "$cmdline" /etc/default/grub; then
138 # already set things, exit
141 sed -ri 's/^ *GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="$cmdline"/' /etc/default/grub
142 # on xenial, no grub is displayed at all. fix that.
143 # found just by noticing this in the config file, and a
144 # warning about it in error.log
145 sed -i '/^ *GRUB_HIDDEN_TIMEOUT/d' /etc/default/grub
149 fi ##### end != dirinstall && != NOCRYPT
152 ###### begin network setup ####
154 # use old names. the idea of them changing between boots has never
155 # happened to me and I usually only have 1 wired or other type.
156 # If I ever do need to care about it, I will.
157 # Strangely this didn't work on kw, so I added kernel cmdline parameter.
158 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
159 ln -sf /dev
/null
$target/etc
/systemd
/network
/99-default.link
162 # bitfolk installer handles the rest
168 # use networkmanager if this host has wireless.
169 if type -p iw
&>/dev
/null
&& [[ $
(iw dev
) ]]; then
170 chroot
$FAI_ROOT bash
<<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'
187 if [[ $HOSTNAME == frodo
]]; then
188 cat > $target/etc
/network
/interfaces
<<-EOF
191 iface lo inet loopback
192 iface eth0 inet static
198 cat > $target/etc
/network
/interfaces
<<-EOF
201 iface lo inet loopback
203 iface eth0 inet6 auto
206 # previously had an else condition after
207 #elif ifclass VM || ifclass LINODE; then
208 # iface $NIC1 inet manual
209 # iface br0 inet dhcp
213 # however, on t9, on startup, br0, became
214 # rename1 and didn't come up. i dunno why,
215 # but the bridge is for vms that I rarely use,
216 # so not bothering to figure it out.
221 if ifclass LINODE
; then
222 mkdir
-p $target/etc
/initramfs-tools
/conf.d
223 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
224 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
225 # man 5 initramfs.conf
226 # /usr/share/doc/klibc-utils/README.ipconfig.gz
227 # /usr/share/initramfs-tools/scripts/functions
228 IP=$linode_ip::$linode_gw:255.255.255.0::eth0:off
232 if [[ $HOSTNAME == li
]]; then
234 cat > $target/etc
/network
/interfaces
<<-EOF
237 iface lo inet loopback
239 # for the standard network config, uncomment this and comment the lines after it.
240 #iface eth0 inet6 auto
242 iface eth0 inet6 static
243 # this is really a /128. it seems like we need to assign it for ipv6 to work.
244 address 2600:3c00::f03c:91ff:fe6d:baf8/64
247 iface eth0 inet6 static
248 # from a requested /64 pool
249 address 2600:3c00:e000:280::2/64
255 # I prefer to stick with ifup/down for now. a. networkd is not in its
256 # own package, so cant use in other init systems. b. it works fine.
257 chroot
$FAI_ROOT bash
<<EOF
258 systemctl disable systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
259 systemctl mask systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
262 ##### end network setup #####
265 if ifclass VOL_BUSTER_BOOTSTRAP
; then
266 fcopy
-riM /etc
/systemd
/system
267 chroot
$FAI_ROOT bash
<<'EOFOUTER'
268 systemctl enable fai_check.service
270 exit 0 # avoid unnecessary stuff in bootstrap vol
276 chroot
$FAI_ROOT bash
<<'EOFOUTER'
277 #### begin .ssh setup ###
280 mkdir -p /home/iank/.ssh
281 f=/root/.ssh/authorized_keys
283 cp $f /home/iank/.ssh
285 chown -R 1000:1000 /home/iank/.ssh
286 chmod -R u=Xrw,og= /home/iank/.ssh
288 # remove broken symlinks or the following cp will fail
289 find /home/iank/.ssh -xtype l -exec rm '{}' \;
290 cp -rL /home/iank/.ssh /root
291 chown -R root:root /root/.ssh
293 # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
294 # systemctl --user is not available at fai time, so create the link ourselves
295 d=/home/iank/.config/systemd/user/default.target.wants
296 sudo -u iank mkdir -p $d
297 sudo -u iank ln -sf /usr/lib/systemd/user/ssh-agent.service $d
298 #### end .ssh setup ###
300 ## duplicated in ssh-emacs-setup
301 # done here so its setup earlier for convenience
302 line='AcceptEnv INSIDE_EMACS BRC COLUMNS'
303 f=/etc/ssh/sshd_config
304 grep -xFq "$line" $f || tee -a $f <<<"$line"
307 # default debian groups (jessie through buster) + adm, sudo, root
308 for g in cdrom floppy audio dip video plugdev netdev adm sudo; do
309 if getent gropu $g >/dev/null; then
314 if getent group systemd-journal >/dev/null; then
315 usermod -aG systemd-journal iank
319 rm -f $target/etc
/resolv.conf
320 ln -s ..
/run
/systemd
/resolve
/stub-resolv.conf
$target/etc
/resolv.conf
321 # needed for bitfolk image
322 if [[ -e /a
/bin
/fai
/fai-wrapper
]]; then
323 systemctl
enable systemd-resolved
324 systemctl start systemd-resolved
329 # reading through the groups that iank is in but user2 isn't,
330 for g
in plugdev audio video cdrom
; do
331 $ROOTCMD usermod
-a -G $g user2