finally fully use gnu license recommendations
[distro-setup] / distro-begin
1 #!/bin/bash
2 # Setup Ian's computers
3 # Copyright (C) 2024 Ian Kelling
4
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9
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.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 # SPDX-License-Identifier: GPL-3.0-or-later
19
20 #### for setting up a new machine
21 # usage: $0 [-r] [HOSTNAME]
22 # HOSTNAME changes the machine's hostname
23
24 # Update target_down alerts in
25 # /a/bin/ds/filesystem/etc/prometheus/rules/iank.yml
26 #
27 # Update hostnames in /b/ds/check-remote-mailqs
28
29 ### end new machine setup
30
31 # tips:
32 # run any sudo command first so your pass is cached
33 # set the scrollback to unlimited in case something goes wrong
34
35
36 # send to registrar, glue records:
37 # for iankelling.org:
38
39 # ns1.iankelling.org 72.14.176.105
40 # ns1.iankelling.org 2600:3c00::f03c:91ff:fe6d:baf8
41 # ns2.iankelling.org 172.105.84.95
42 # ns2.iankelling.org 2a01:7e01::f03c:91ff:feb5:baec
43
44 # for zroe.org:
45
46 # ns1.zroe.org 72.14.176.105
47 # ns1.zroe.org 2600:3c00::f03c:91ff:fe6d:baf8
48 # ns2.zroe.org 172.105.84.95
49 # ns2.zroe.org 2a01:7e01::f03c:91ff:feb5:baec
50 #
51
52
53
54 ####### begin setup environment #######
55
56
57 ### make ssh interactive shell run better. for when running line interactively line by line
58 sudo bash -c '/a/exe/ssh-emacs-setup'
59
60 ##### setup error handling
61 interactive=true # set this to false to force set -x
62 [[ $- == *i* ]] || interactive=false
63 if ! $interactive; then
64 set -x
65 fi
66 source /a/bin/bash-bear-trap/bash-bear
67
68 mkdir -p ~/.local
69 err-cleanup() {
70 echo 1 >~/.local/distro-begin
71 }
72
73 source /a/bin/distro-functions/src/package-manager-abstractions
74
75 ### setup logging
76 echo "$0: $(date): starting now)"
77
78
79 ### sanity checking
80 if [[ $EUID == 0 ]]; then
81 if getent passwd iank || getent passwd ian ; then
82 echo "$0: error: running as root. unprivileged user exists. use it."
83 exit 1
84 else
85 echo "$0: warning: running as root. I will setup users then exit"
86 fi
87 fi
88
89
90 ### arg parsing
91 recompile=false
92 emacs=false
93 if [[ -e /a/opt/emacs ]]; then
94 emacs=true
95 fi
96 while [[ $1 == -* ]]; do
97 case $1 in
98 -r) recompile=true; shift ;;
99 -e) emacs=false; shift ;;
100 esac
101 done
102 if [[ $1 ]]; then
103 export HOSTNAME=$1
104 fi
105
106
107 ##### variables/env setup
108 script_dir="$(readlink -f "${BASH_SOURCE[@]}")"; script_dir=${script_dir%/*}
109 # shellcheck source=./pkgs
110 source $script_dir/pkgs
111 set +x
112 source /a/bin/distro-functions/src/identify-distros
113 $interactive || set -x
114 for f in kd x2 x3 x8 frodo tp li bk je demohost kw sy bo; do
115 eval "$f() { [[ $HOSTNAME == $f ]]; }"
116 done
117 codename=$(debian-codename)
118 bitfolk() { je || bk; }
119 has_wayland() { has_monitor && [[ $codename == buster ]]; }
120 has_x() { has_monitor && [[ $codename != buster ]]; }
121 has_monitor() { ! vps ; }
122 vps() { bitfolk || li; }
123 # linode actually has btrfs now, but we dont do anything with it.
124 has_btrfs() { ! vps; }
125 home_network() { ! vps && ! tp; }
126 has_p() { ! vps && ! tp; }
127 encrypted() { ! bitfolk; }
128 shopt -s extglob
129 export GLOBIGNORE="*/.:*/.."
130 umask 022
131 PATH="/a/exe:$PATH"
132 sed="sed --follow-symlinks"
133
134 ####### end setup environment #######
135
136
137 ##### begin setup encryption scripts ######
138 if encrypted; then
139 # I tried making a service which was dependent on reboot.target,
140 # but it happened too late in the shutdown process.
141 sudo dd of=/etc/systemd/system/keyscripton.service <<'EOF'
142 [Unit]
143 Description=keyscripton
144 # This is triggered by reboot and when keyscriptoff stops.
145
146 # tried using graphical.target, but it made my display manager restart before rebooting.
147 # generally, I don't think targets order shutdown like they do startup.
148 # So, I did systemd-analyze plot > something.svg, and picked a reliably started
149 # service that happens late in the game.
150 After=ntp.service
151 DefaultDependencies=no
152 # not sure if needed, makes sure we shut down before reboot.target
153 Conflicts=reboot.target
154
155 [Service]
156 Type=oneshot
157 RemainAfterExit=yes
158 ExecStart=/bin/true
159 ExecStop=/a/exe/keyscript-on
160
161 [Install]
162 WantedBy=keyscriptoff.service
163 EOF
164 sudo systemctl daemon-reload # needed if the file was already there
165 sudo systemctl enable keyscripton.service
166
167 sudo dd of=/etc/systemd/system/keyscriptoff.service <<'EOF'
168 [Unit]
169 Description=keyscriptoff
170
171 [Service]
172 Type=oneshot
173 ExecStart=/a/exe/keyscript-off
174
175 [Install]
176 WantedBy=multi-user.target
177 EOF
178 sudo systemctl daemon-reload # needed if the file was already there
179 sudo systemctl enable keyscriptoff.service
180 sudo systemctl start keyscriptoff.service
181
182 pi rsync zstd
183
184 ## /usr/share/doc/dropbear-initramfs/README.initramfs.gz
185 ## claims we need to do this. but it works fine without it.
186 # tmp=$(mktemp)
187 # while read -r m _; do /sbin/modinfo -F filename "$m"; done </proc/modules | \
188 # sed -nr "s@^/lib/modules/$(uname -r)/kernel/drivers/net(/.*)?/([^/]+)\.ko\$@\2@p" \
189 # | sudo dd of=$tmp
190 # if ! diff -q /etc/initramfs-tools/modules $tmp &>/dev/null; then
191 # sudo dd if=$tmp of=/etc/initramfs-tools/modules
192 # sudo /usr/sbin/update-initramfs -u -k all
193 # fi
194 #
195 ## if we were creating an intall for a different machine needing different modules, we could include them all like this:
196 ## find /lib/modules/*/kernel/drivers/net /lib/modules/*/kernel/net -type f -name '*.ko' -printf "%f\n" | sed 's/.ko$//' | sort -u >/etc/initramfs-tools/modules
197
198 # this is here to cleanup the leftover from the comments above. remove it eventually.
199 if [[ -s /etc/initramfs-tools/modules ]]; then
200 sudo truncate -s0 /etc/initramfs-tools/modules
201 sudo /usr/sbin/update-initramfs -u -k all
202 fi
203
204 # initram auth keys get setup with rootsshsync later on.
205 $script_dir/rootsshsync
206
207 ### To do a remote unlock: ssh and do this once per crypt disk:
208 # echo -n PASS >/lib/cryptsetup/passfifo
209 # or for buster+
210 # cryptroot-unlock
211
212 fi
213 ##### end setup encryption scripts ######
214
215
216 # disabled until its fixed up
217 # install-myqueue
218
219 # todo, it would be nice to cut down on some of the output
220
221
222 #### rerun my fai-time scripts
223 # already ran for pxe installs, but used for vps & updates
224 distro=$(distro-name)
225 case $distro in
226 ubuntu|debian|trisquel)
227 sudo bash -c ". /a/bin/fai/fai-wrapper && /a/bin/fai/fai/config/scripts/IANK/11-iank"
228 ;;
229 *)
230 sudo bash -c ". /a/bin/fai/fai-wrapper &&
231 /a/bin/fai/fai/config/distro-install-common/end"
232 ;;
233 esac
234
235 ###### setup hostname
236 if [[ $HOSTNAME != $(cat /etc/hostname) ]]; then
237 echo $HOSTNAME > /etc/hostname
238 hostname -F /etc/hostname
239 fi
240 # office vpn dhcp adds to /etc/resolv.conf search office.fsf.org which
241 # makes that be #1 priority, which makes dnsmasq resolve that for
242 # unqualified hosts first, which means we skip the hosts file. Ya, its
243 # kinda dumb, but it is what it is. There is a dnsmasq config option to
244 # override it too, but this seems simpler.
245 sudo sed -i --follow-symlinks -f - /etc/hosts <<EOF
246 \$a 127.0.1.1 $HOSTNAME.b8.nz $HOSTNAME.office.fsf.org $HOSTNAME
247 /^127\.0\.1\.1/d
248 EOF
249
250 ##### exit first stage if running as root
251 if [[ $EUID == 0 ]]; then
252 if [[ ! -e /home/iank/.ssh/authorized_keys && ! -L /home/iank/.ssh/authorized_keys ]]; then
253 sudo -u iank mkdir -p /home/iank/.ssh
254 chmod 0700 /home/iank/.ssh
255 sudo -u iank ln -sf /p/c/machine_specific/vps/subdir_files/.ssh/authorized_keys /home/iank/.ssh
256 fi
257 echo "$0: running as root. exiting now that users are setup"
258 exit 0
259 fi
260
261
262 #### setup bash for root
263 for x in /a/c/{.bashrc,brc,brc2,.bash_profile,.profile,.inputrc,path_add_function}; do
264 sudo -i <<EOF
265 PATH="/a/exe:$PATH"
266 lnf $x /root
267 EOF
268 done
269
270 ###### link files
271 # convenient to just do all file linking in one place
272 sudo /a/exe/lnf -T /a/bin /b
273 sudo /a/exe/lnf -T /a/f /f
274 sudo /a/exe/lnf -T /var/log/exim4 /el
275 sudo /a/exe/lnf -T /a/f/ans /c
276 sudo /a/exe/lnf -T /nocow/t /t
277 if has_p; then
278 lnf -T /p/News ~/News
279 fi
280 dirs=(/q/root /q/root/.editor-backups /q/root/.undo-tree-history)
281 sudo mkdir -p ${dirs[@]}
282 sudo chmod 600 ${dirs[@]}
283 sudo /a/exe/lnf /q/root/.editor-backups /q/root/.undo-tree-history \
284 /a/opt /a/c/.emacs.d $HOME/mw_vars /k/backup /root
285 /a/bin/ds/install-my-scripts # needed for rootsshsync cronjob
286 sudo /a/exe/lnf /a/c/.vim /a/c/.vimrc /a/c/.gvimrc /root
287
288
289 ###### do conflink
290 # vps needs bind group before conflink
291 if vps; then
292 pi-nostart bind9
293 fi
294 if bitfolk; then
295 pi-nostart unbound
296 fi
297 # this needs to be before installing pacserve so we have gpg conf.
298 conflink
299 rootsshsync
300 if [[ -e /etc/rootsudoenv ]]; then
301 source /etc/rootsudoenv
302 fi
303
304
305
306 ###### bash environment setup
307 set +x
308 err-allow
309 source /etc/profile.d/environment.sh
310 export LC_USEBASHRC=t
311 # shellcheck source=./.bashrc
312 source ~/.bashrc
313 err-catch
314 $interactive || set -x
315
316 ##### use systemd-resolved for glibc resolutions
317
318 pi libnss-resolve
319
320 if [[ ! -L /etc/nsswitch.conf ]]; then
321 sudo mkdir -p /etc/resolved-nsswitch
322 sudo mv /etc/nsswitch.conf /etc/resolved-nsswitch
323 sudo ln -sf /etc/resolved-nsswitch/nsswitch.conf /etc
324 fi
325
326 f=/etc/basic-nsswitch/nsswitch.conf
327 if [[ ! -e $f ]]; then
328 sudo mkdir -p ${f%/*}
329 sudo cp /etc/nsswitch.conf $f
330 sudo sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files dns myhostname/' $f
331 fi
332 case $HOSTNAME in
333 bk|je)
334 # je should be able to get along systemd-resolved, but ive had some odd
335 # very intermittent dns failures with spamassassin, it seems it might only
336 # be happening with systemd-resolved, so just use unbound
337 # to make it consistent with the other hosts.
338 sudo sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files dns myhostname/' /etc/nsswitch.conf
339 soff systemd-resolved
340 sudo ln -sf 127.0.0.1-resolv/stub-resolv.conf /etc/resolv.conf
341 sgo unbound
342 # cautious measure to make sure resolution is working
343 sleep 1
344 ;;
345 *)
346 # default is
347 # files mdns4_minimal [NOTFOUND=return] dns myhostname
348 # mdns4 is needed for my printer and for bbb webrtc, not sure exactly why.
349 # https://www.freedesktop.org/software/systemd/man/nss-resolve.html#
350 # seems more important than some potential use case.
351 # Interestingly, t9/t10 man page says use files before resolve, debian 10 says the opposite.
352 # removing files makes hostname -f not actually give the fully qualified domain name.
353 sudo sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files resolve [!UNAVAIL=return] mdns4_minimal [NOTFOUND=return] myhostname/' /etc/resolved-nsswitch/nsswitch.conf
354 ;;
355 esac
356
357 case $HOSTNAME in
358 bk)
359 sgo named
360 ;;
361 esac
362
363
364 lines=(
365 "/etc/resolved-nsswitch/nsswitch.conf r,"
366 "/etc/basic-nsswitch/nsswitch.conf r,"
367 # Aug 06 23:09:11 kd audit[3995]: AVC apparmor="DENIED" operation="connect" profile="/usr/bin/freshclam" name="/run/systemd/resolve/io.systemd.Resolve" pid=3995 comm="freshclam" requested_mask="wr" denied_mask="wr" fsuid=109 ouid=101
368 # I dont know if this is quite the right fix, but I saw other sockets
369 # in the nameservice files that were rw, so figured it was ok to add this and it worked.
370 "/run/systemd/resolve/io.systemd.Resolve rw,"
371 )
372 f=/etc/apparmor.d/abstractions/nameservice
373 apparmor_reload=false
374 if [[ -e $f ]]; then
375 for l in "${lines[@]}"; do
376 if ! grep -qF "$l" $f; then
377 sudo sed -i "/\/nsswitch.conf/a $l" $f
378 apparmor_reload=true
379 if ! grep -qF "$l" $f; then
380 echo "$0: failed editing $f. investigate"
381 exit 1
382 fi
383 fi
384 done
385 if $apparmor_reload && systemctl is-enabled apparmor; then
386 m ser reload apparmor
387 fi
388 fi
389
390
391
392 if dpkg -s -- nscd &>/dev/null; then
393 sudo apt-get -y remove --purge --auto-remove nscd
394 sudo systemctl stop nscd ||: # fails if already stopped
395 fi
396
397 # http://strugglers.net/~andy/blog/2020/12/03/starting-services-only-when-the-network-is-ready-on-debiansystemd/
398 if systemctl cat ifupdown-wait-online.service &>/dev/null; then
399 sudo systemctl enable ifupdown-wait-online.service
400 fi
401
402 if bitfolk; then
403 # remove line like this: 85.119.82.128 je.iankelling.org je
404 # it messes with hostname -f.
405 sudo sed -ri "/^127\./n;/[[:space:]]$HOSTNAME\$/d" /etc/hosts
406 fi
407
408 if isdeb && [[ $(debian-codename) == aramo ]]; then
409 sudo dd of=/etc/apt/preferences.d/aramo-jammy-missing <<'EOF'
410 Package: linux-libc-dev libmysqlclient21
411 Pin: release n=jammy,o=Ubuntu
412 Pin-Priority: 500
413 EOF
414 fi
415
416 # libfdk just has some patent worries.
417 # https://www.gnu.org/licenses/license-list.en.html#fdk
418 if isdeb && [[ $(debian-codename) == nabia ]]; then
419 sudo dd of=/etc/apt/preferences.d/nabia-focal-missing <<'EOF'
420 Package: libfdk-aac1
421 Pin: release n=focal,o=Ubuntu
422 Pin-Priority: 500
423 EOF
424
425 # it has a dependency python-paramiko that should be
426 # python3-paramiko. the backport version is pretty close to the normal
427 # version, so i just set the pin priority low for the backport and it
428 # doesnt bother me
429 sudo dd of=/etc/apt/preferences.d/nabia-backport <<'EOF'
430 Package: ansible
431 Pin: release a=nabia-backports
432 Pin-Priority: -100
433 EOF
434
435 fi
436
437
438 # to test when these become available in trisquel, copy the package list, remove the * chars, repaplace PACKAGES below
439 # for x in PACKAGES; do hr; e $x; if [[ $x == *- ]]; then s="^$x"; dpkg -l "$x*" | sed '0,/^+++/d'; else s="^$x\$"; fi; aptitude search "~O Trisquel ~n $s"; done
440
441
442 #### setup firefox backport
443 ## ian: disabled. backports are not being published atm due to rust packaging issue
444 # if isdeb; then
445 # codename=$(debian-codename)
446 # if isdebian-stable && has_x; then
447 # s dd of=/etc/apt/sources.list.d/mozilla-iceweasel.list <<EOF
448 # deb http://mozilla.debian.net/ $codename-backports firefox-release
449 # deb-src http://mozilla.debian.net/ $codename-backports firefox-release
450 # EOF
451 # p update
452 # # take care of mozilla signing errors in previous command
453 # pi pkg-mozilla-archive-keyring
454 # fi
455 # p update
456 # fi
457
458
459 ###### arch aur wrapper setup
460 if isarch; then
461 #https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages
462 sudo pacman -S --noconfirm --needed base-devel jq
463 # pacaur seems to be the best, although it + cower has a few minor bugs,
464 # its design goals seem good, so, going for it.
465
466 aurpi() {
467 for p in "$@"; do
468 tempdir=$(mktemp -d)
469 pushd $tempdir
470 aurex "$p"
471 makepkg -sri --skippgpcheck --noconfirm
472 popd
473 rm -rf $tempdir
474 done
475 }
476 aurpi cower pacaur
477
478 pi pacserve
479
480 x=$(mktemp); /usr/bin/pacman.conf-insert_pacserve >$x
481 sudo dd of=/etc/pacman.conf if=$x; rm $x
482 sudo systemctl enable pacserve.service
483 sudo systemctl start pacserve.service
484
485 fi
486
487 #### update all packages
488 # shellcheck disable=SC2119 # obvious
489 pup
490
491
492 ###### p1 packages install ######
493 pi ${p1[@]}
494
495
496 ######## fix evbug bug ######
497 case $(debian-codename-compat) in
498 xenial|bionic|focal|jammy)
499 # noticed in flidas. dunno if it affects any others
500 #https://bugs.launchpad.net/ubuntu/+source/module-init-tools/+bug/240553
501 #https://wiki.debian.org/KernelModuleBlacklisting
502 #common advice when searching is to use /etc/modprobe.d/blacklist.conf,
503 #but that file won't work and will get automatically reverted
504 sudo rmmod evbug ||: # might not be loaded yet
505 file=/etc/modprobe.d/evbug.conf
506 line="blacklist evbug"
507 if [[ $(cat $file) != "$line" ]]; then
508 sudo dd of=$file status=none <<<"$line"
509 sudo depmod -a
510 sudo update-initramfs -u
511 fi
512 ;;
513 esac
514
515
516
517 #### arch specific early packages
518 case $(distro-name) in
519 arch)
520 # pkgfile is like apt-cache
521 pi pkgfile
522 sudo pkgfile --update
523 ;;
524 esac
525
526 #### enable trim
527 # enable trim for volume delete, other rare commands
528 sudo $sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc/lvm/lvm.conf
529 if encrypted; then
530 # flidas or so, these units arent built-in
531 if isdeb && ! systemctl list-unit-files | grep ^fstrim.timer &>/dev/null ; then
532 sudo cp /usr/share/doc/util-linux/examples/fstrim.{service,timer} /etc/systemd/system
533 fi
534 # does weekly trim
535 sudo systemctl enable fstrim.timer
536 fi
537
538 ##### make extra dirs
539 dirs=()
540 for dir in /mnt/{1,2,3,4,5,6,7,8,9} /nocow/t; do
541 [[ -e $dir ]] && continue
542 dirs+=($dir)
543 done
544 if (( ${#dirs[@]} )); then
545 # mkdir -p on a mounted directory will fail. so will chown if its an ro mount
546 sudo mkdir -p "${dirs[@]}"
547 sudo chown $USER:$USER "${dirs[@]}"
548 fi
549
550
551 # disabled temporarily
552 ###### setup /i
553 # if home_network; then
554 # tu /etc/fstab <<'EOF'
555 # /i/w /w none bind,noauto 0 0
556 # /i/k /k none bind,noauto 0 0
557 # EOF
558 # if ! mountpoint /kr; then
559 # sudo mkdir -p /kr
560 # sudo chown $USER:user2 /kr
561 # fi
562 # if [[ $HOSTNAME == frodo ]]; then
563 # tu /etc/fstab <<'EOF'
564 # /k /kr none bind,noauto 0 0
565 # EOF
566 # else
567 # tu /etc/fstab <<'EOF'
568 # frodo:/k /kr nfs noauto 0 0
569 # EOF
570 # fi
571 # sudo mkdir -p /i/{w,k}
572 # for dir in /{i,w,k}; do
573 # if mountpoint $dir; then continue; fi # already mounted
574 # sudo mkdir -p $dir
575 # sudo chown $USER:$USER $dir
576 # done
577 # # debian auto mounting of multi-disk encrypted btrfs is busted. It is
578 # # in jessie, and in stretch as of 11/26/2016 I have 4 disks in cryptab,
579 # # based on 3 of those, it creates .device units for /dev/mapper/dev...
580 # # then waits endlessly for them on bootup, after the /dev/mapper disks
581 # # have already been created and exist. todo: create a simple repro
582 # # for this in a vm and report it upstream.
583 # pi nfs-common
584 # sudo dd of=/root/imount <<'EOF'
585 # #!/bin/bash
586 # [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
587 # set -eE -o pipefail
588 # trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
589 # for dir in /i /k /kr /w; do
590 # if ! mountpoint $dir &>/dev/null && \
591 # awk '{print $2}' /etc/fstab | grep -xF $dir &>/dev/null; then
592 # if awk '{print $3}' /etc/fstab | grep -xF nfs &>/dev/null; then
593 # mount $dir || echo "warning: failed to mount nfs on $dir"
594 # else
595 # mount $dir
596 # fi
597 # fi
598 # done
599 # EOF
600 # sudo chmod +x /root/imount
601 # sudo dd of=/etc/systemd/system/imount.service <<EOF
602 # [Unit]
603 # Description=Mount /i and related mountpoints
604 # Before=syncthing@$USER.service
605
606 # [Service]
607 # Type=oneshot
608 # ExecStart=/root/imount
609
610 # [Install]
611 # RequiredBy=syncthing@$USER.service
612 # # note /kr needs networking, this target is the simplest way to
613 # # time it when the network should be up, but not do something
614 # # dumb like delay startup until the network is up. It happens
615 # # at some time after network.target
616 # WantedBy=multi-user.target
617 # EOF
618 # sudo systemctl daemon-reload # needed if the file was already there
619 # sudo systemctl enable imount.service
620 # sudo systemctl start imount.service
621 # fi
622 ###### end setup /i
623
624 ##### setup /nocow.
625 # a nocow dir that is common to multiple distros installed on the same system
626 dir=/nocow
627 if has_btrfs; then
628 if ! mountpoint $dir; then
629 subvol=/mnt/root/nocow
630 if [[ ! -e $subvol ]]; then
631 sudo btrfs subvolume create $subvol
632 sudo chown root:1000 $subvol
633 sudo chattr +C $subvol
634 fi
635
636 first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab)
637 tu /etc/fstab <<EOF
638 $first_root_crypt /nocow btrfs noatime,subvol=nocow$( (( $(nproc) > 2)) && echo ,compress=zstd ) 0 0
639 EOF
640 sudo mkdir -p $dir
641 sudo chown $USER:$USER $dir
642 sudo mount $dir
643 fi
644 else
645 sudo mkdir -p $dir
646 fi
647
648 case $HOSTNAME in
649 kd)
650 tu /etc/fstab <<'EOF'
651 /dev/mapper/crypt_dev_ata-Samsung_SSD_870_QVO_8TB_S5VUNG0N900656V-part7 /d btrfs nofail,x-systemd.device-timeout=30s,x-systemd.mount-timeout=30s,noatime,compress=zstd,subvol=d 0 0
652 /d/m /i none bind,compress=zstd 0 0
653 EOF
654 if ! mountpoint /d &>/dev/null; then
655 sudo mkdir -p /d
656 if [[ -d /mnt/r7/d ]]; then
657 sudo mount /d
658 fi
659 fi
660 if ! mountpoint /i &>/dev/null; then
661 sudo mkdir -p /i
662 sudo mount /i
663 fi
664 ;;
665 frodo)
666 tu /etc/fstab <<'EOF'
667 /dev/mapper/crypt_dev_ata-ata-Hitachi_HDS722020ALA330_JK1121YAG7SXWS-part1 /i btrfs nofail,x-systemd.device-timeout=30s,x-systemd.mount-timeout=30s,noatime,subvol=i 0 0
668 EOF
669 if ! mountpoint /i &>/dev/null; then
670 sudo mkdir -p /i
671 if [[ -d /mnt/i/i ]]; then
672 sudo mount /i
673 fi
674 fi
675 ;;
676 esac
677
678 if bitfolk; then
679 sudo systemctl disable systemd-networkd
680 fi
681
682 ##### setup email
683 primary-setup
684
685 #### ubuntu nicety
686 if isubuntu; then
687 # disable crash report annoying dialogs.
688 sudo dd of=/etc/default/apport <<<'enabled=0'
689 fi
690
691 ##### install laptop hardware packages
692 if tp || x2 || x3 || bo || sy; then
693 case $distro in
694 debian)
695 pi task-laptop
696 ;;
697 ubuntu|trisquel)
698 # the exact packages that task-laptop would install, since ubuntu
699 # doesn\'t have this virtual in practice package.
700 pi avahi-autoipd bluetooth powertop iw wireless-tools wpasupplicant
701 ;;
702 # todo: other distros unknown
703 esac
704 fi
705
706 if has_monitor; then
707
708 # sway not packaged for t9, not bothering to build it yet since
709 # i3 doesnt seem to tear and stutter on video anymore.
710 if [[ $codename == buster ]]; then
711 pi sway xwayland
712 fi
713
714
715 ###### install X
716 pi i3
717
718 ##### install xinput
719 case $(distro-name) in
720 trisquel|ubuntu|debian)
721 pi xinput
722 ;;
723 esac
724
725 # recommends gets us geoclue (for darkening automatically at night i assume),
726 # which recommends modemmanager, which is annoying to fix for the model01 keyboard.
727 # commented because I dont use it much, and in nabia its named changed to redshift-gtk
728 #pi --no-install-recommends gtk-redshift
729
730 ##### setup X autostart
731 # install for multiple display managers in case we use one
732 dir=/etc/X11/xinit/xinitrc.d/
733 sudo mkdir -p $dir
734 sudo cp /a/bin/distro-setup/desktop-20-autostart.sh $dir
735
736 ## disabled since i'm not using gdm atm
737 # dir=/etc/gdm3
738 # sudo mkdir -p $dir/PostLogin
739 # sudo cp /a/bin/distro-setup/desktop-20-autostart.sh $dir/PostLogin/Default
740 sudo mkdir -p /etc/lightdm/lightdm.conf.d
741 # etiona lightdm.log:
742 # [SeatDefaults] is now called [Seat:*], please update this configuration
743 sudo dd of=/etc/lightdm/lightdm.conf.d/12-iank.conf <<'EOF'
744 [Seat:*]
745 # display-setup-script=/a/bin/ds/lightdm-start
746 session-setup-script=/a/bin/distro-setup/desktop-20-autostart.sh
747 EOF
748
749
750 # originally used xkbcomp, documented in input-setup.sh, this doesnt
751 # work under wayland, but its still useful for creating the config,
752 # then modifying the system files.
753 sudo sed -i.orig '/key *<KPMU> *{/,/}/s/KP_Multiply/underscore/g' /usr/share/X11/xkb/symbols/keypad
754
755 ##### basic graphical packages
756 pi konsole suckless-tools ssh-askpass
757 fi
758
759
760
761 ##### install emacs
762 if $emacs; then
763 if isarch; then
764 # emacs git build was broken last time i checked,
765 x=$(mktemp -d)
766 pushd $x
767 aurex emacs-git
768 makepkg -si --noconfirm
769 popd
770 rm -rf $x
771 pi hunspell hunspell-en
772 else
773 if $recompile; then
774 /a/bin/buildscripts/emacs
775 /a/bin/buildscripts/mu4e
776 else
777 /a/bin/buildscripts/emacs --no-r
778 /a/bin/buildscripts/mu4e --no-r
779 fi
780 fi
781 # the first pup command can kill off our /etc/ mod, so rerun this
782 /a/exe/ssh-emacs-setup
783 fi
784
785 if [[ $HOSTNAME == kd ]] && ! mountpoint /d &>/dev/null; then
786 cat <<'EOFOUTER'
787 # if this is a fresh reinstall, need to run something like this
788 # to restore data:
789 mkdir /mnt/r7/btrbk
790 btrbk archive /mnt/rust1/btrbk /mnt/r7/btrbk
791 btrfs sub snap /mnt/r7/btrbk/LATEST /mnt/r7/d
792 mount /d
793 EOFOUTER
794 fi
795
796
797 echo 0 >~/.local/distro-begin
798 echo "$0: $(date): ending now"
799 echo "exiting with status 0"
800 exit 0