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