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