mostly fixes, a few improvements
[distro-setup] / distro-end
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4
5 # shellcheck source=/a/bin/ds/.bashrc
6 export LC_USEBASHRC=t; if [[ -s ~/.bashrc ]]; then . ~/.bashrc; fi
7
8 ### setup
9 source /a/bin/bash-bear-trap/bash-bear
10 src="$(readlink -f -- "${BASH_SOURCE[0]}")"; src=${src%/*} # directory of this file
11
12 if [[ $EUID == 0 ]]; then
13 echo "$0: error: run as regular user" >&2
14 exit 1
15 fi
16
17 err-cleanup() {
18 echo 1 >~/.local/distro-end
19 }
20
21 # shellcheck source=./pkgs
22 source $src/pkgs
23
24 echo "$0: $(date) starting now)"
25 # see example of usage to understand.
26 end_msg() {
27 local y
28 IFS= read -r -d '' y ||:
29 end_msg_var+="$y"
30 }
31 end() {
32 e "$end_msg_var"
33 echo 0 >~/.local/distro-end
34 if $pending_reboot; then
35 echo "$0: pending reboot and then finished. doing it now."
36 echo "exiting with status 0"
37 sudo reboot now
38 else
39 echo "$0: $(date): ending now)"
40 echo "exiting with status 0"
41 fi
42 exit 0
43 }
44 pre="${0##*/}:"
45 sudo() {
46 printf "$pre sudo %s\n" "$*"
47 SUDOD="$PWD" command sudo "$@";
48 }
49 m() { printf "$pre %s\n" "$*"; "$@"; }
50 e() { printf "$pre %s\n" "$*"; }
51 distro=$(distro-name)
52 codename=$(debian-codename)
53 codename_compat=$(debian-codename-compat)
54 pending_reboot=false
55 sed="sed --follow-symlinks"
56
57 # when we schroot, it will fail if we are in a directory that doesnt exist in the chroot
58 cd /
59
60 ## template:
61 # case $distro in
62 # esac
63
64 case $HOSTNAME in
65 li|bk|je) : ;;
66 *)
67 # get sudo pass cached right away
68 if ! sudo -nv 2>/dev/null; then
69 sudo -v
70 fi
71 ;;
72 esac
73
74 # old repo. remove when all machines updated
75 sudo rm -fv /etc/apt/sources.list.d/wireguard-ubuntu-wireguard-bionic.list
76 # remove old file
77 sudo rm -fv /etc/apt/preferences.d/minetest
78
79 #### initial packages
80 pup
81 if isdeb; then
82 pi aptitude
83 fi
84
85 # avoid prompts
86 sudo debconf-set-selections <<EOF
87 popularity-contest popularity-contest/participate boolean true
88 EOF
89
90 ########### begin section including vps ################
91 pi ${p2[@]}
92
93 conflink
94
95 sudo rm -fv
96
97 # no equivalent in other distros:
98 if isdeb && pcheck apt-file; then
99 # this condition is just a speed optimization
100 pi apt-file
101 sudo apt-file update
102 fi
103
104
105 # disable motd junk.
106 case $distro in
107 debian)
108 # allows me to pipe with ssh -t, and gets rid of spam
109 # http://forums.debian.net/viewtopic.php?f=5&t=85822
110 # i'd rather disable the service than comment the init file
111 # this says disabling the service, it will still get restarted
112 # but this script doesn't do anything on restart, so it should be fine
113 sudo truncate -s0 /var/run/motd.dynamic
114 ;;
115 trisquel|ubuntu)
116 # this isn't a complete solution. It still shows me when updates are available,
117 # but it's no big deal.
118 sudo rm -fv /etc/update-motd.d/10-help-text /etc/update-motd.d/00-header
119 ;;
120 esac
121
122
123
124
125
126 pi debootstrap
127 ######### begin universal pinned packages ######
128 case $(debian-codename) in
129 etiona|flidas|nabia|aramo)
130 sudo rm -fv /etc/apt/preferences.d/etiona-buster
131 sd /etc/apt/preferences.d/trisquel-debian <<EOF
132 Explanation: Debian* includes Debian + Debian Backports
133 Package: *
134 Pin: release o=Debian*
135 Pin-Priority: -100
136 EOF
137 ;;&
138 # needed for debootstrap scripts for fai since fai requires debian
139 flidas)
140 # moved to fai
141 #curl http://archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg | s apt-key add -
142 sd /etc/apt/preferences.d/flidas-xenial <<EOF
143 Package: *
144 Pin: release a=xenial
145 Pin-Priority: -100
146
147 Package: *
148 Pin: release a=xenial-updates
149 Pin-Priority: -100
150
151 Package: *
152 Pin: release a=xenial-security
153 Pin-Priority: -100
154
155 Package: firefox
156 Pin: release n=xenial
157 Pin-Priority: 500
158 EOF
159 sd /etc/apt/sources.list.d/xenial.list 2>/dev/null <<EOF
160 deb http://us.archive.ubuntu.com/ubuntu/ xenial main
161 deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main
162 deb http://us.archive.ubuntu.com/ubuntu/ xenial-security main
163 EOF
164
165 if ! apt-key list | grep /C0B21F32 &>/dev/null; then
166 # moved to fai
167 #sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
168 sd /etc/apt/preferences.d/flidas-bionic <<EOF
169 Package: *
170 Pin: release a=bionic
171 Pin-Priority: -100
172
173 Package: *
174 Pin: release a=bionic-updates
175 Pin-Priority: -100
176
177 Package: *
178 Pin: release a=bionic-security
179 Pin-Priority: -100
180 EOF
181 fi
182
183 # better to run btrfs-progs which matches our kernel version
184 # (note, renamed from btrfs-tools)
185 sd /etc/apt/preferences.d/btrfs-progs <<EOF
186 Package: btrfs-progs libzstd1
187 Pin: release a=bionic
188 Pin-Priority: 1005
189
190 Package: btrfs-progs libzstd1
191 Pin: release a=bionic-updates
192 Pin-Priority: 1005
193
194 Package: btrfs-progs libzstd1
195 Pin: release a=bionic-security
196 Pin-Priority: 1005
197 EOF
198
199
200 t=$(mktemp)
201 cat >$t <<EOF
202 deb http://us.archive.ubuntu.com/ubuntu/ bionic main
203 deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main
204 deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main
205 EOF
206 f=/etc/apt/sources.list.d/bionic.list
207 if ! diff -q $t $f; then
208 sudo cp $t $f
209 sudo chmod 644 $f
210 m p update
211 fi
212
213 # no special reason, but its better for btrfs-progs to
214 # be closer to our kernel version
215 pi btrfs-progs
216
217 if [[ ! -e /usr/share/debootstrap/scripts/xenial ]]; then
218 t=$(mktemp -d)
219 cd $t
220 m aptitude download debootstrap/xenial
221 m ex ./*
222 sudo cp ./usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
223 fi
224
225 sd /etc/apt/preferences.d/flidas-etiona <<EOF
226 Package: *
227 Pin: release a=etiona
228 Pin-Priority: -100
229
230 Package: *
231 Pin: release a=etiona-updates
232 Pin-Priority: -100
233
234 Package: *
235 Pin: release a=etiona-security
236 Pin-Priority: -100
237
238 Package: *
239 Pin: release a=etiona-backports
240 Pin-Priority: -100
241 EOF
242
243 t=$(mktemp)
244 cat >$t <<EOF
245 deb http://mirror.fsf.org/trisquel/ etiona main
246 deb http://mirror.fsf.org/trisquel/ etiona-updates main
247 deb http://archive.trisquel.info/trisquel/ etiona-security main
248 deb http://mirror.fsf.org/trisquel/ etiona-backports main
249 EOF
250 f=/etc/apt/sources.list.d/etiona.list
251 if ! diff -q $t $f; then
252 sudo cp $t $f
253 n s chmod 644 $f
254 m p update
255 fi
256
257 sd /etc/apt/preferences.d/debian-goodies <<EOF
258 Package: debian-goodies
259 Pin: release n=etiona
260 Pin-Priority: 1005
261 EOF
262
263
264 # dont use buster because it causes dist-upgrade to think its downgrading
265 # packages while really just reinstalling the same version.
266 f=/etc/apt/apt.conf.d/01iank
267 sudo rm -fv $f
268 # # stupid buster uses some key algorithm not supported by flidas gpg that apt uses.
269 # sd /etc/apt/apt.conf.d/01iank <<'EOF'
270 # Acquire::AllowInsecureRepositories "true";
271 # EOF
272
273 f=/etc/apt/sources.list.d/buster.list
274 sudo rm -fv $f
275
276 # newer version needed for false positive in checkrestart.
277 # I did buster at first, but other problem above with having
278 # buster repos. not sure if the false positive exists in etiona.
279 pi debian-goodies
280
281 sd /etc/apt/preferences.d/shellcheck <<EOF
282 Package: shellcheck
283 Pin: release a=etiona
284 Pin-Priority: 1005
285
286 Package: shellcheck
287 Pin: release a=etiona-updates
288 Pin-Priority: 1005
289
290 Package: shellcheck
291 Pin: release a=etiona-security
292 Pin-Priority: 1005
293 EOF
294
295 sd /etc/apt/preferences.d/bash <<EOF
296 Package: bash
297 Pin: release a=etiona
298 Pin-Priority: 1005
299
300 Package: bash
301 Pin: release a=etiona-updates
302 Pin-Priority: 1005
303
304 Package: bash
305 Pin: release a=etiona-security
306 Pin-Priority: 1005
307 EOF
308
309
310 ;;&
311 aramo|nabia|etiona)
312 # for ziva
313 #p install --no-install-recommends minetest/buster libleveldb1d/buster libncursesw6/buster libtinfo6/buster
314 doupdate=false
315 # shellcheck disable=SC2043 # in case we want more than 1 in the loop later.
316 for n in bullseye; do
317 f=/etc/apt/sources.list.d/$n.list
318 t=$(mktemp)
319 case $n in
320 bullseye)
321 cat >$t <<'EOF'
322 EOF
323 cat >$t <<EOF
324 deb http://deb.debian.org/debian bullseye main
325 deb-src http://deb.debian.org/debian bullseye main
326
327 deb http://deb.debian.org/debian-security/ bullseye-security main
328 deb-src http://deb.debian.org/debian-security/ bullseye-security main
329
330 deb http://deb.debian.org/debian bullseye-updates main
331 deb-src http://deb.debian.org/debian bullseye-updates main
332
333 deb http://http.debian.net/debian bullseye-backports main
334 deb-src http://http.debian.net/debian bullseye-backports main
335 EOF
336 ;;
337 esac
338
339 if ! diff -q $t $f; then
340 doupdate=true
341 s cp $t $f
342 s chmod 644 $f
343 fi
344 done
345 if $doupdate; then
346 curl -s https://ftp-master.debian.org/keys/archive-key-10-security.asc | sudo apt-key add -
347 curl -s https://ftp-master.debian.org/keys/archive-key-10.asc | sudo apt-key add -
348 p update
349 fi
350
351 if [[ ! -e /usr/share/debootstrap/scripts/bullseye ]]; then
352 t=$(mktemp -d)
353 cd $t
354 m aptitude download debootstrap/bullseye
355 m ex ./*
356 sudo cp ./usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
357 fi
358
359 ;;&
360 etiona)
361 sd /etc/apt/preferences.d/focal <<'EOF'
362 Package: *
363 Pin: release n=focal,o=Ubuntu
364 Pin-Priority: -100
365 EOF
366
367 sd /etc/apt/preferences.d/spamassassin <<'EOF'
368 Package: spamassassin sa-compile spamc
369 Pin: release n=focal,o=Ubuntu
370 Pin-Priority: 500
371 EOF
372 sd /etc/apt/preferences.d/spamassassin <<'EOF'
373 Package: spamassassin sa-compile spamc
374 Pin: release n=focal,o=Ubuntu
375 Pin-Priority: 500
376 EOF
377 sd /etc/apt/preferences.d/psd <<'EOF'
378 Package: profile-sync-daemon
379 Pin: release n=focal,o=Ubuntu
380 Pin-Priority: 500
381 EOF
382
383 f=/etc/apt/sources.list.d/focal.list
384 t=$(mktemp)
385 cat >$t <<'EOF'
386 deb http://us.archive.ubuntu.com/ubuntu/ focal main universe
387 deb http://us.archive.ubuntu.com/ubuntu/ focal-updates main universe
388 deb http://us.archive.ubuntu.com/ubuntu/ focal-security main universe
389 EOF
390 if ! diff -q $t $f; then
391 sudo dd if=$t of=$f status=none
392 p update
393 fi
394
395
396
397 sd /etc/apt/preferences.d/nabia-etiona <<'EOF'
398 Package: *
399 Pin: release n=nabia*,o=Trisquel
400 Pin-Priority: -100
401 EOF
402
403 f=/etc/apt/sources.list.d/nabia.list
404 t=$(mktemp)
405 cat >$t <<'EOF'
406 deb http://mirror.fsf.org/trisquel/ nabia main
407 deb-src http://mirror.fsf.org/trisquel/ nabia main
408
409 deb http://mirror.fsf.org/trisquel/ nabia-updates main
410 deb-src http://mirror.fsf.org/trisquel/ nabia-updates main
411
412 deb http://archive.trisquel.info/trisquel/ nabia-security main
413 deb-src http://archive.trisquel.info/trisquel/ nabia-security main
414
415 # Uncomment this lines to enable the backports optional repository
416 deb http://mirror.fsf.org/trisquel/ nabia-backports main
417 deb-src http://mirror.fsf.org/trisquel/ nabia-backports main
418 EOF
419 if ! diff -q $t $f; then
420 sudo dd if=$t of=$f status=none
421 p update
422 fi
423
424 # duplicated in fai. Pin for bionic + ubuntu so that ppas dont get
425 # matched.
426 sd /etc/apt/preferences.d/etiona-bionic <<'EOF'
427 Package: *
428 Pin: release n=bionic,o=Ubuntu
429 Pin-Priority: -100
430 Package: firefox
431 Pin: release n=bionic,o=Ubuntu
432 Pin-Priority: 500
433 EOF
434
435 sd /etc/apt/preferences.d/etiona-sa <<'EOF'
436 Package: *
437 Pin: release n=bionic,o=Ubuntu
438 Pin-Priority: -100
439 EOF
440
441 ;;&
442 nabia)
443 sd /etc/apt/preferences.d/aramo-nabia <<'EOF'
444 Package: *
445 Pin: release n=aramo*,o=Trisquel
446 Pin-Priority: -100
447 EOF
448 f=/etc/apt/sources.list.d/aramo.list
449 t=$(mktemp)
450 cat >$t <<'EOF'
451 deb http://mirror.fsf.org/trisquel/ aramo main
452 deb-src http://mirror.fsf.org/trisquel/ aramo main
453
454 deb http://mirror.fsf.org/trisquel/ aramo-updates main
455 deb-src http://mirror.fsf.org/trisquel/ aramo-updates main
456
457 deb http://archive.trisquel.info/trisquel/ aramo-security main
458 deb-src http://archive.trisquel.info/trisquel/ aramo-security main
459
460 # Uncomment this lines to enable the backports optional repository
461 deb http://mirror.fsf.org/trisquel/ aramo-backports main
462 deb-src http://mirror.fsf.org/trisquel/ aramo-backports main
463 EOF
464 if ! diff -q $t $f; then
465 sudo dd if=$t of=$f status=none
466 p update
467 fi
468
469 ;;&
470 *)
471 if isdeb; then
472 pi debian-goodies shellcheck
473 fi
474 ;;
475 esac
476
477 case $codename_compat in
478 jammy)
479 s systemctl enable --now ssh-agent-iank
480 ;;
481 esac
482
483 case $codename_compat in
484 focal)
485 sd /etc/apt/preferences.d/nabia-btrfs-progs <<'EOF'
486 Package: btrfs-progs
487 Pin: release a=buster-backports
488 Pin-Priority: 500
489 EOF
490 p install btrfs-progs
491 ;;
492 esac
493
494
495 # 2020-03-03 old file
496 s rm -fv /etc/apt/preferences.d/radicale
497 ######### end universal pinned packages ######
498
499
500 case $codename in
501 etiona)
502 sd /etc/apt/preferences.d/obs <<EOF
503 Package: libfdk-aac1
504 Pin: release n=bionic
505 Pin-Priority: 500
506 EOF
507 sd /etc/apt/preferences.d/chromium <<EOF
508 Package: chromium-*
509 Pin: release n=bionic
510 Pin-Priority: 500
511 EOF
512 ;;
513 nabia)
514 # note, to get the latest, it would be n=bullseye*
515 # but that has conflicting package versions, so this does the old one.
516 # I only use it for special rare purposes. Just keep in mind it is an
517 # outdated insecure version.
518 sd /etc/apt/preferences.d/chromium-bullseye <<EOF
519 Package: chromium chromium-* libicu67 libjpeg62-turbo libjsoncpp24 libre2-9 libwebpmux3
520 Pin: release o=Debian*,n=bullseye
521 Pin-Priority: 500
522 EOF
523 ;;
524 aramo)
525 # obs dependency not in trisquel
526 sd /etc/apt/preferences.d/obs <<EOF
527 Package: libfdk-aac2
528 Pin: release n=jammy,o=Ubuntu
529 Pin-Priority: 500
530 EOF
531 ;;
532 esac
533
534
535
536 ##### begin automatic upgrades (after checkrestart has been installed) ####
537 # if apt-config-auto-update is installed,
538 # it also has similar config, in a file 10something,
539 # but i think this overrides it since its higher number.
540 # This file was part of the automatic-updates package,
541 # and it has a config option to not get new package lists,
542 # which seems pretty stupid to me, you cant actually upgrade
543 # anything if you dont have the new package list.
544 sd /etc/apt/apt.conf.d/20auto-upgrades <<'EOF'
545 # note: man apt.conf says
546 # /usr/share/doc/apt/examples/configure-index.gz is a configuration file showing
547 # example values for all possible options.
548 # but that is a incorrect.
549 # Periodic and other options are only documented in
550 # /usr/lib/apt/apt.systemd.daily
551 # That filename can be found through poking around in apt daily cronjob.
552 APT::Periodic::Update-Package-Lists "1";
553 APT::Periodic::Download-Upgradeable-Packages "1";
554 # 0 means disabled. I used to set this to 7, however, trisquel doesn't
555 # have an archive of old package versions, so I want to
556 # keep around old versions so I can easily downgrade.
557 APT::Periodic::AutocleanInterval "0";
558 # daily expire old files /var/cache/apt if it gets above this MB
559 APT::Periodic::MaxSize "50000";
560 APT::Periodic::Unattended-Upgrade "1";
561 EOF
562
563 # fyi: default file has comments about available options,
564 # you may want to read that, do pkx unattended-upgrades
565 # default is just security updates. this list found from reading
566 # match_whitelist_string() in $(which unattended-upgrades)
567 sd /etc/apt/apt.conf.d/50unattended-upgrades <<EOF
568 Unattended-Upgrade::Mail "root";
569 Unattended-Upgrade::MailOnlyOnError "true";
570 Unattended-Upgrade::Remove-Unused-Dependencies "true";
571 Unattended-Upgrade::Origins-Pattern {
572 "o=*,l=*,a=*,c=*,site=*,n=*";
573 };
574 EOF
575
576 # old files
577 sudo rm -f /etc/cron.d/unattended-upgrade-reboot /usr/local/bin/zelous-unattended-reboot /etc/cron.d/myupgrade
578
579 # myupgrade cron exists in /etc/cron.d/ian
580
581 ##### end automatic upgrades ####
582
583
584 # commented in case i want to use this sometime later
585 # sd /etc/apt/preferences.d/buster-backports <<EOF
586 # Package: *
587 # Pin: release a=buster-backports
588 # Pin-Priority: 500
589 # EOF
590
591
592 ###### begin website setup
593 case $HOSTNAME in
594 li|bk|je)
595 pi bind9
596 f=/var/lib/bind/db.b8.nz
597 if [[ ! -e $f ]]; then
598 dnsb8
599 fi
600
601 sudo /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter -l 127.0.0.1
602
603 # ex for exporter
604 web-conf -p 9101 -f 9100 - apache2 ${HOSTNAME}ex.b8.nz <<'EOF'
605 <Location "/">
606 AuthType Basic
607 AuthName "basic_auth"
608 # created with
609 # htpasswd -c prometheus-export-htpasswd USERNAME
610 AuthUserFile "/etc/prometheus-export-htpasswd"
611 Require valid-user
612 </Location>
613 EOF
614 ;;&
615
616 bk)
617 sgo wg-quick@wgmail
618
619 # i just dont feel like setting up a special purpose ssh key to do this automatically.
620 end_msg <<'EOF'
621 # run this once for bk on local machine:
622 # only used for old openvpn setup
623 /a/exe/vpn-mk-client-cert -c bk.b8.nz -b expertpath -n mail li.iankelling.org
624 EOF
625 end
626 ;;
627 je)
628 end
629 ;;
630 li)
631
632 p build-dep eggdrop
633 if [[ ! -L ~/eggdrop/eggdrop ]]; then
634 cd
635 git clone https://github.com/eggheads/eggdrop eggdrop-src
636 cd eggdrop-src
637 ./configure
638 make config
639 make
640 make install
641 fi
642
643 # dunno if this is really needed. it was part of the documented eggdrop systemd install script
644 sudo loginctl enable-linger
645 systemctl --user enable fsysbot
646 systemctl --user start fsysbot
647
648 m /a/h/setup.sh iankelling.org
649
650 # start mumble only when im going to use it, since i dont use it much
651 pi-nostart mumble-server
652 sudo $sed -ri "s/^ *(serverpassword=).*/\1$(< /a/bin/bash_unpublished/mumble_pass)/" /etc/mumble-server.ini
653
654 # do certificate to avoid warning about unsigned cert,
655 # which is overkill for my use, but hey, I'm cool, I know
656 # how to do this.
657 m web-conf apache2 mumble.iankelling.org
658 sudo rm -fv /etc/apache2/sites-enabled/mumble.iankelling.org
659
660 # general vpn for as needed use
661 vpn-server-setup -d -r -4 10.5.5 -p 443 -n hole
662
663 # todo: consider if this should exist for the
664 # other vpn server
665 teeu /etc/openvpn/server/hole.conf <<'EOF'
666 client-to-client
667 EOF
668
669
670 ngset
671 files=(/etc/openvpn/client-config-hole/*)
672 if (( ${#files[@]} >= 1 )); then
673 rm -f ${files[@]}
674 fi
675 ngreset
676 for host in ${!vpn_ips[@]}; do
677 sd /etc/openvpn/client-config-hole/$host <<EOF
678 ifconfig-push 10.5.5.${vpn_ips[$host]} 255.255.255.0
679 EOF
680 done
681
682
683 # for adding cert to system with /p
684 #
685 # host=frodo
686 #mkc /p/c/machine_specific/$host/filesystem/etc/openvpn/client
687 #vpn-mk-client-cert -b $host -n hole -r iankelling.org
688 #s chown -R iank:iank .
689 #
690 # example of adding to remote system 107,
691 # vpn-mk-client-cert -n hole -c 10.2.0.107 -b hd8 iankelling.org
692 #
693 # for wireguard hole vpn, use function:
694 # wghole
695 # eg:
696 # wghole bo 28
697 # if it is going to want to connect to transmission-daemon on ok
698 # wghole bo 28 10.174.2.2/32
699
700 # requested from linode via a support ticket.
701 # https://www.linode.com/docs/networking/an-overview-of-ipv6-on-linode/
702 # ipv6 stuff pieced together
703 # via slightly wrong information from
704 # https://github.com/angristan/openvpn-install/blob/master/openvpn-install.sh
705 # https://community.openvpn.net/openvpn/wiki/IPv6
706 # and man openvpn.
707 #
708 # This uses a public /64, but afaik, that is not needed for my
709 # current use case, since I'm doing ipv6 nat, they could be private
710 # and nat to a public address. I'm doing ipv6 nat in order to have 2
711 # vpn clients that externally share the same ip when sending so they
712 # share ip reputation. Note, the eth0 and tunx needed to be
713 # different subnets. On the same, I saw some neighbor packet go
714 # unanswered, tcpdump showed packets getting lost. I tried splitting the
715 # /64, it didn't work but I didn't investigate closely.
716
717
718 # not starting as i intend to replace it
719 m vpn-server-setup -s -i tunmail -n mail -d -6 2600:3c00:e002:3800::/64 2600:3c00:e002:3800::1/64
720 sudo tee /etc/openvpn/client-config-mail/mailclient <<'EOF'
721 ifconfig-push 10.8.0.4 255.255.255.0
722 ifconfig-ipv6-push 2600:3c00:e002:3800::4/64
723 EOF
724 sudo tee /etc/openvpn/client-config-mail/expertpath <<'EOF'
725 ifconfig-push 10.8.0.5 255.255.255.0
726 ifconfig-ipv6-push 2600:3c00:e002:3800::5/64
727 EOF
728
729
730 sudo dd of=/etc/systemd/system/vpn-mail-forward.service <<'EOF'
731 [Unit]
732 Description=Turns on iptables mail nat
733 BindsTo=openvpn-server@mail.service
734
735 [Service]
736 Type=oneshot
737 RemainAfterExit=yes
738 ExecStart=/a/bin/distro-setup/vpn-mail-forward tunmail start
739 ExecStop=/a/bin/distro-setup/vpn-mail-forward tunmail stop
740
741 [Install]
742 RequiredBy=openvpn-server@mail.service
743 EOF
744 ser daemon-reload
745
746
747 # needed for li's local mail delivery.
748 tu /etc/hosts <<<"10.8.0.4 mx.iankelling.org"
749
750 # wgmail handles this.
751 #sgo vpn-mail-forward.service
752 # old:
753 #sgo openvpn-server@mail
754 sgo wg-quick@wgmail
755
756 # setup let's encrypt cert
757 m web-conf apache2 mail.iankelling.org
758 # TODO, i expanded the above cert manually to mx.iankelling.org, this should be captured
759 # in the automation here. We use mail.iankelling.org as our ehlo name when sending mail
760 # but our mx record is mx.iankelling.org. Initially I was just using mail.iankelling.org,
761 # but the problem is I want multiple ips to be able to identify as mail.iankelling.org,
762 # but a subset to be mx.iankelling.org. Afaik, there is no problem with having
763 # our mail cert be for mail.iankelling.org, and have people connect to mx.ian...,
764 # but it doesn't make logical sense to do this.
765 sudo rm -fv /etc/apache2/sites-enabled/mail.iankelling.org{,-redir}.conf
766 ser reload apache2
767
768 a2enmod -q proxy proxy_http
769 domain=cal.iankelling.org
770 web-conf -f 10.8.0.4:5232 - apache2 $domain <<'EOF'
771 # https://radicale.org/2.1.html
772 #https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype
773 # https://stackoverflow.com/questions/5011102/apache-reverse-proxy-with-basic-authentication
774
775 # this doesn't exactly fit with the documentation.
776 # We need location / to do an auth, it cant be done outside,
777 # in order to pass on X-Remote-User. And we need
778 # the other location in order to remove the /radicale/ for
779 # requests which have it. This could be done with a rewrite,
780 # but i just get something working and call it a day.
781
782 <Location "/">
783 AllowOverride None
784 AuthType Basic
785 AuthName "Authentication Required"
786 # setup one time, with root:www-data, 640
787 AuthUserFile "/etc/caldav-htpasswd"
788 Require valid-user
789 RequestHeader set X-Remote-User expr=%{REMOTE_USER}
790 </Location>
791 <Location "/radicale/">
792 Options +FollowSymLinks +Multiviews -Indexes
793 RequestHeader set X-Script-Name /radicale/
794 RequestHeader set X-Remote-User expr=%{REMOTE_USER}
795 ProxyPass "http://10.8.0.4:5232/" retry=0
796 ProxyPassReverse "http://10.8.0.4:5232/"
797 </Location>
798 EOF
799 # nginx version of above would be:
800 # auth_basic "Not currently available";
801 # auth_basic_user_file /etc/nginx/caldav/htpasswd;
802
803
804
805 ###### begin znc setup #####
806 pi znc
807
808 # https://wiki.znc.in/FAQ seems to imply that znc doesn\'t need restart after cert change.
809 # to get into the web interface,
810 # then use non-main browser or else it doebsn't allow it based on ocsp stapling from my main site.
811 # https://iankelling.org:12533/
812 # login as ian, pass is in pass store, the part after :
813
814 # znc config generated by doing
815 # znc --makeconf
816 # selected port is also used in erc config
817 # comma separated channel list worked.
818 # while figuring things out, running znc -D for debug in foreground.
819 # to exit and save config:
820 # /msg *status shutdown
821 # configed auth on freenode by following
822 # https://wiki.znc.in/Sasl:
823 # /query *sasl
824 # RequireAuth yes
825 # Mechanism PLAIN
826 # Set MyNickservName pa$$w0rd
827 # created the system service after, and had to do
828 # mv /home/iank/.znc/* /var/lib/znc
829 # sed -i 's,/home/iank/.znc/,/var/lib/znc,' /var/lib/znc/config/znc.conf
830 # and made a copy of the config files into /p/c
831 # /msg *status LoadMod --type=global log -sanitize
832 # todo: in config file AllowWeb = true should be false. better security if that is off unless we need it.
833 # /msg *status LoadMod --type=network perform
834 # /query *perform add PRIVMSG ChanServ :invite #fsf-office
835 # /msg *perform add JOIN #fsf-office
836 # /msg *status LoadMod NickServ
837 #
838 # i set Buffer = 500
839 # also ran /znc LoadMod clearbufferonmsg
840 # it would be nice if erc supported erc query buffers by doing
841 # /msg *status clearbuffer <name of the query/receiver
842 # on killing the,
843 # an example seems to be here: https://github.com/zenspider/elisp/blob/master/rwd-irc.el
844 # if that was the case i could remove the module clearbufferonmsg
845 # also would be nice if erc supported
846 # https://wiki.znc.in/self-message
847 # https://wiki.znc.in/Query_buffers \
848 #
849 # for geekshed, there was no sasl support as far as I can tell,
850 # so I set to msg nickserv to identify upon connect.
851 if ! getent passwd znc > /dev/null; then
852 sudo useradd --create-home -d /var/lib/znc --system --shell /sbin/nologin --comment "Account to run ZNC daemon" --user-group znc
853 fi
854 sudo chmod 700 /var/lib/znc
855 sudo chown -R znc:znc /var/lib/znc
856 # Avoid restarting if possible, reconnecting to irc is annoying.
857 # The unit file was made active with conflink.
858 # Note, avoid using ser here because we wrap sudo to prints the command first.
859 if [[ $(systemctl is-active znc) != active ]]; then
860 sgo znc
861 fi
862 ###### stop znc setup #####
863
864 end
865 ;;
866 esac
867
868 case $HOSTNAME in
869 bk)
870 pi icecast2
871 # todo, save the config
872 /etc/cron.daily/stream-cert
873 web-conf -c /etc/cert-live.fsf.org -p 443 -f 8000 apache2 live.fsf.org
874 ;;
875 esac
876
877 ###### end website setup
878
879 ########### end section including li/lj ###############
880
881
882 #### desktop stuff
883
884 ### system76 things ###
885 case $HOSTNAME in
886 bo) # sy| sy doesnt seem to really need this.
887 # note, i stored the initial popos packages at /a/bin/data/popos-pkgs
888 if [[ ! -e /etc/apt/sources.list.d/system76.list ]]; then
889 # https://blog.zackad.dev/en/2017/08/17/add-ppa-simple-way.html
890 sd /etc/apt/sources.list.d/system76.list <<EOF
891 deb http://ppa.launchpad.net/system76-dev/stable/ubuntu $codename_compat main
892 deb-src http://ppa.launchpad.net/system76-dev/stable/ubuntu $codename_compat main
893 EOF
894 # ubuntu keyserver is prone to intermittent failures
895 trysleep 4 15 s apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5D1F3A80254F6AFBA254FED5ACD442D1C8B7748B
896 p update
897 # https://support.system76.com/articles/install-ubuntu/
898 # but i'm hoping this is not needed
899 # sd /etc/apt/preferences.d/system76 <<'EOF'
900 # Package: *
901 # Pin: release o=LP-PPA-system76-dev-stable
902 # Pin-Priority: 1001
903 # EOF
904 #
905 # TODO: I had to uninstall linux-image-generic-hwe-20.04 because of a conflict
906 # about linux-firmware. Should probably install it to begin with in fai if
907 # i'm going to use.
908 pi system76-driver system76-firmware
909 # if you get a notice about a firmware update, the notifier on i3
910 # is too dumb to do anything when you click it. so to see
911 # a changelog, cd to
912 # /var/cache/system76-firmware-daemon
913 # extract the xz files there, one will contain a changelog.
914 # then to install an update:
915 # s system76-firmware-cli schedule
916 fi
917 ;;
918 esac
919 ### end system76 things ###
920
921 case $distro in
922 trisquel|ubuntu)
923
924 # ppa:obsproject/obs-studio
925 if [[ ! -s /etc/apt/sources.list.d/obs.list ]]; then
926 # https://blog.zackad.dev/en/2017/08/17/add-ppa-simple-way.html
927 sd /etc/apt/sources.list.d/obs.list <<EOF
928 deb http://ppa.launchpad.net/obsproject/obs-studio/ubuntu $codename_compat main
929 deb-src http://ppa.launchpad.net/obsproject/obs-studio/ubuntu $codename_compat main
930 EOF
931 trysleep 4 15 s apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BC7345F522079769F5BBE987EFC71127F425E228
932 p update
933 fi
934 ;;
935 esac
936
937 case $codename_compat in
938 xenial)
939 # mate-indicator-applet and beyond are msc things I noticed diffing a
940 # standard install with mine.
941 pi xorg lightdm mate-desktop-environment mate-desktop-environment-extras mate-indicator-applet anacron
942 ;;
943 stretch)
944 pi task-mate-desktop
945 ;;
946 buster)
947 # todo: figure out mate for buster
948 # pi task-gnome-desktop
949 ;;
950 bionic|focal)
951 # i had installing mate-indicator-applet, but im not sure why so i removed
952 pi xorg lightdm mate-desktop-environment mate-desktop-environment-extras anacron
953
954 # pi gnome-core
955 # # apt-get update periodically fails with an appstream error.
956 # # this removes gnome-core, but its just a package for dependencies
957 # p -y remove appstream
958
959
960 # by default, it sleeps when not logged in to x/wayland and on ac power.
961 # stop that.
962 if id -u gdm &>/dev/null; then
963 sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
964 fi
965 ;;&
966 focal)
967 # lightdm startup fails without this. on etiona, we got unity-greeter installed automatically,
968 # it would probably work on nabia too, but google just lead me to this and it works fine.
969 pi lightdm-gtk-greeter
970 # ok, this is really weird
971 # normally this file has
972 sd /etc/X11/Xsession.d/99x11-common_start <<'EOF'
973 # this is very odd.
974 # this file normally just has: exec $STARTUP
975 # but then ~/.xsession-errors
976 # says $STARTUP is not found, which appears to be the real
977 # error, but normal bash doesnt operate that way.
978 # https://bugs.launchpad.net/ubuntu/+source/im-config/+bug/1879352
979 eval exec $STARTUP
980 EOF
981 # also, gdm wayland was default, had to do
982 # dpkg-reconfigure gdm3
983 # and choose lightdm.
984 #
985 ;;
986 jammy)
987 # not yet bothering with mate
988 pi lightdm-gtk-greeter lightdm
989 ;;
990 esac
991
992
993 if [[ $codename_compat == flidas ]]; then
994 # doesnt exist in newer
995 pi gnupg-doc
996 fi
997
998
999 case $distro in
1000 trisquel)
1001 case $codename in
1002 *)
1003 # firefox would work here too, apt would select abrowser.
1004 # and the update-alternatives thing i think is becuz firefox is
1005 # generally available before abrowser and this helps fix things
1006 # up when we have both.
1007 pi abrowser
1008 s update-alternatives --set x-www-browser /usr/bin/abrowser
1009 ;;
1010 esac
1011 ;;
1012 ubuntu)
1013 pi firefox
1014 ;;
1015 debian)
1016 pi firefox-esr
1017 ;;
1018 esac
1019
1020 # newer distros just use adb for package name it seems
1021 case $codename_compat in
1022 bionic|stretch)
1023 pi android-tools-adbd
1024 ;;
1025 esac
1026
1027 case $codename_compat in
1028 focal)
1029 pi libext2fs-dev libzstd-dev
1030 cd /a/opt/btrfs-progs
1031 ;;
1032 esac
1033
1034
1035 case $codename_compat in
1036 bionic)
1037 pi python-vte
1038 ;;
1039 *)
1040 pi reportbug-gtk
1041 ;;
1042 esac
1043
1044 # not packaged in newer distros it seems
1045 case $codename_compat in
1046 bionic|buster|stretch)
1047 pi dtrx
1048 ;;
1049 esac
1050
1051
1052 # TODO: some of the X programs can be removed from pall when using wayland
1053
1054 # depends gcc is a way to install suggests. this is apparently the only
1055 # way to install suggests even if the main package is already
1056 # installed. reinstall doesn't work, uninstalling can cause removing
1057 # dependent packages.
1058 # shellcheck disable=SC2046 # word splitting is intended
1059 pi ${pall[@]} $(apt-cache search ruby[.0-9]+-doc| awk '{print $1}') $($src/distro-pkgs)
1060
1061 # schroot service will restart schroot sessions after reboot.
1062 # I dont want that.
1063 pi-nostart schroot
1064
1065 # fix systemd unit failure. i dont know of any actual impact
1066 # other than systemd showing in degraded state. So, we dont bother
1067 # fixing the current state, let it fix on the next reboot.
1068 # https://gitlab.com/cjwatson/binfmt-support/-/commit/54f0e1af8a
1069 tmp=$(systemctl cat binfmt-support.service | grep ^After=)
1070 if [[ $tmp != *systemd-binfmt.service* ]]; then
1071 s u /etc/systemd/system/binfmt-support.service.d/override.conf <<EOF
1072 [Unit]
1073 $tmp systemd-binfmt.service
1074 EOF
1075 fi
1076
1077
1078 # commented, not worth the hassle i think.
1079 #seru enable psd
1080 #seru start psd
1081
1082
1083 # old filename
1084 sudo rm -fv /etc/systemd/resolved.conf.d/iank.conf
1085
1086 # website is dead june 14 2019. back in october, but meh
1087 sudo rm -fv /etc/apt/sources.list.d/iridium-browser.list
1088 # case $distro in
1089 # debian)
1090 # pi chromium ;;
1091 # trisquel|ubuntu)
1092 # wget -qO - https://downloads.iridiumbrowser.de/ubuntu/iridium-release-sign-01.pub|sudo apt-key add -
1093 # t=$(mktemp)
1094 # cat >$t <<EOF
1095 # deb [arch=amd64] https://downloads.iridiumbrowser.de/deb/ stable main
1096 # #deb-src https://downloads.iridiumbrowser.de/deb/ stable main
1097 # EOF
1098 # f=/etc/apt/sources.list.d/iridium-browser.list
1099 # if ! diff -q $t $f; then
1100 # s cp $t $f
1101 # s chmod 644 $f
1102 # p update
1103 # fi
1104 # pi iridium-browser
1105 # ;;
1106 # esac
1107
1108
1109 ##### rss2email
1110 if mountpoint /p &>/dev/null; then
1111 # note, see bashrc for more documentation.
1112 pi rss2email
1113 sd /etc/systemd/system/rss2email.service <<'EOF'
1114 [Unit]
1115 Description=rss2email
1116 After=multi-user.target
1117
1118 [Service]
1119 User=iank
1120 Type=oneshot
1121 # about 24 hours of failures
1122 # it copies over its files without respecting symlinks, so
1123 # we pass options to use different location.
1124 ExecStart=/usr/local/bin/sysd-mail-once -288 rss2email r2e -d /p/c/rss2email.json -c /p/c/rss2email.cfg run
1125 EOF
1126 sd /etc/systemd/system/rss2email.timer <<'EOF'
1127 [Unit]
1128 Description=rss2email
1129
1130 [Timer]
1131 # for initial run. required.
1132 OnActiveSec=30
1133 # for subsequent runs.
1134 OnUnitInactiveSec=300
1135
1136 [Install]
1137 WantedBy=timers.target
1138 EOF
1139 sudo systemctl daemon-reload
1140 fi
1141
1142
1143 ######### begin irc periodic backup #############
1144 if [[ $HOSTNAME == frodo ]]; then
1145 sd /etc/systemd/system/ircbackup.service <<'EOF'
1146 [Unit]
1147 Description=irc li backup
1148 After=multi-user.target
1149
1150 [Service]
1151 User=iank
1152 Type=oneshot
1153 ExecStart=/usr/local/bin/sysd-mail-once irc-backup rsync -rlptDhSAX root@iankelling.org:/var/lib/znc/moddata/log/iank/freenode/ /k/irclogs
1154 EOF
1155 sd /etc/systemd/system/ircbackup.timer <<'EOF'
1156 [Unit]
1157 Description=irc li backup hourly
1158
1159 [Timer]
1160 OnCalendar=hourly
1161
1162 [Install]
1163 WantedBy=timers.target
1164 EOF
1165 sudo systemctl daemon-reload
1166 sgo ircbackup.timer
1167 fi
1168
1169
1170 ######### end irc periodic backup #############
1171
1172
1173 pi-nostart openvpn
1174 # pi-nostart does not disable
1175 ser disable openvpn
1176
1177
1178 if [[ -e /p/c/gen-fsf-vpn ]]; then
1179 /p/c/gen-fsf-vpn
1180 fi
1181
1182 if [[ -e /p/c/machine_specific/$HOSTNAME/filesystem/etc/openvpn/client/hole.crt ]]; then
1183 sgo openvpn-client@hole
1184 fi
1185
1186 ############# begin syncthing setup ###########
1187 case $HOSTNAME in
1188 kd|frodo)
1189 f=/usr/share/keyrings/syncthing-archive-keyring.gpg
1190 if [[ ! -e $f ]]; then
1191 s curl -s -o $f https://syncthing.net/release-key.gpg
1192 fi
1193 s="deb [signed-by=/usr/share/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable"
1194 if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != "$s" ]]; then
1195 echo "$s" | sd /etc/apt/sources.list.d/syncthing.list
1196 p update
1197 fi
1198 pi syncthing
1199 ;;&
1200 frodo)
1201 m lnf -T /w/syncthing /home/iank/.config/syncthing
1202 ser daemon-reload # syncthing likely not properly packaged
1203 sgo syncthing@iank # runs as iank
1204 ;;
1205 kd)
1206
1207 # 1003 just happens to be what was on my system
1208 if ! getent passwd ziva; then
1209 s groupadd -g 1003 ziva
1210 # syncthing state / config / db are all in ~/.config/syncthing
1211 s useradd -g 1003 -u 1003 -d /d/ziva-home -c ziva -s /bin/bash ziva
1212 fi
1213 sgo syncthing@ziva
1214 ;;
1215 esac
1216
1217 # user for short term use dropping of privileges
1218
1219 if ! getent group zu &>/dev/null; then
1220 s groupadd -g 1023 zu
1221 fi
1222 if ! getent passwd zu &>/dev/null; then
1223 s useradd -g 1023 -u 1023 -c zu -s /bin/bash zu
1224 fi
1225
1226
1227 # these things persist in ~/.config/syncthing, which I save in
1228 # /w/syncthing (not in /p, because syncthing should continue to
1229 # run on home server even when using laptop as primary device)
1230 # open http://localhost:8384/
1231 # change listen address from default to tcp://:22001,
1232 # this is because we do port forward so it doesn\'t have to use
1233 # some external server, but the syncthing is broken for port forward,
1234 # you get a message, something "like connected to myself, this should not happen"
1235 # when connecting to other local devices, so I bump the port up by 1,
1236 # based on
1237 # https://forum.syncthing.net/t/connected-to-myself-should-not-happen/1763/19.
1238 # Without this, it was being stuck syncing at 0%.
1239 # Set gui username and password.
1240 #
1241 # install syncthing via f-droid,
1242 # folder setting, turn off send only.
1243 # on phone, add device, click bar code icon
1244 # on dekstop, top right, actions, device id
1245 # after adding, notification will appear on desktop to confirm
1246 #
1247 # syncing folder. from phone to desktop: select desktop in the
1248 # folder on phone\'s sync options, notification will appear in
1249 # desktop\'s web ui within a minute. For the reverse, the
1250 # notification will appear in android\'s notifications, you have to
1251 # swipe down and tap it to add the folder. It won\'t appear in the
1252 # syncthing ui, which would be intuitive, but don\'t wait for it
1253 # there. The notification may not work, instead open the web gui
1254 # from in the app, there should be a notification within there.
1255 #
1256 # On phone, set settings to run syncthing all the time, and
1257 # show no notification.
1258 #
1259 # Folder versioning would make sense if I didn\'t already use btrfs
1260 # for backups. I would choose staggered, or trash can for more space.
1261 #
1262 # if needed to install on a remote comp:
1263 # ssh -L 8384:localhost:8384 -N frodo
1264 # open http://localhost:8384/
1265 #
1266 # Note, the other thing i did was port forward port 22000,
1267 # per https://docs.syncthing.net/users/firewall.html
1268
1269 ############# end syncthing setup ###########
1270
1271
1272
1273 ####### begin misc packages ###########
1274
1275 # old location, 2023.
1276 sudo rm -fv /etc/systemd/system/profanity.service
1277 case $HOSTNAME in
1278 kd)
1279 ln -sfT /d/p/profanity ~/.local/share/profanity
1280 ln -sfT /d/p/profanity-config ~/.config/profanity
1281 source /a/bin/bash_unpublished/source-state
1282 if [[ $HOSTNAME == "$HOST2" || ! -e /p/profanity-here ]]; then
1283 systemctl --user --now enable profanity
1284 fi
1285 ;;
1286 *)
1287
1288 ln -sfT /p/profanity ~/.local/share/profanity
1289 ln -sfT /p/profanity-config ~/.config/profanity
1290 ;;
1291 esac
1292
1293 # template
1294 case $codename in
1295 flidas)
1296 :
1297 ;;
1298 esac
1299
1300 sudo update-alternatives --set pinentry /usr/bin/pinentry-gtk-2
1301
1302
1303 # sakura config is owned by ian
1304 m reset-sakura
1305 m reset-konsole
1306 m sudo -u user2 -i reset-konsole
1307 # user2 xscreensaver we don't want to reset
1308 m reset-xscreensaver
1309
1310
1311 # this would install from cabal for newer / consistent version across os, but it screws up xmonad, so disabled for now.
1312 # this is also in primary-setup
1313 # pi libxss-dev # dependency based on build failure
1314 # cabal update
1315 # cabal install --upgrade-dependencies --force-reinstalls arbtt
1316 # also, i assume syncing this between machines somehow messed up the data.
1317
1318 ## not using arbtt for now
1319 # if mountpoint /p &>/dev/null; then
1320 # case $codename in
1321 # etiona|nabia)
1322 # pi arbtt
1323 # # same as seru enable arbtt, but works over ssh when systemctl --user causes error:
1324 # # Failed to connect to bus: No such file or directory
1325 # lnf -T /a/bin/ds/subdir_files/.config/systemd/user/arbtt.service /home/iank/.config/systemd/user/default.target.wants/arbtt.service
1326 # # allow failure
1327 # seru start arbtt ||:
1328 # ;;
1329 # esac
1330 # fi
1331 rm -fv /home/iank/.config/systemd/user/default.target.wants/arbtt.service
1332
1333
1334 m primary-setup
1335
1336 if [[ ! -e ~/.linphonerc && -e /p/.linphonerc-initial ]]; then
1337 m cp /p/.linphonerc-initial ~/.linphonerc
1338 fi
1339
1340 # linphone in t10 wont do dns with systemd-resolved or something
1341 s teeu /etc/hosts <<'EOF'
1342 74.94.156.215 watson.fsf.org
1343 EOF
1344
1345
1346
1347 ### begin spd install
1348 if mountpoint /p &>/dev/null; then
1349 pi libswitch-perl libdigest-md5-file-perl libgnupg-interface-perl
1350 t=$(mktemp)
1351 m wget -O $t http://mirror.fsf.org/fsfsys-trisquel/fsfsys-trisquel/pool/main/s/spd-perl/spd-perl_0.2-1_amd64.deb
1352 sudo dpkg -i $t
1353 m rm $t
1354 # this guesses at the appropriate directory, adjust if needed
1355 perldir=(/usr/lib/x86_64-linux-gnu/perl/5.*)
1356 m sudo ln -sf ../../../perl/5.18.2/SPD/ ${perldir[0]}
1357 # newer distro had gpg2 as default, older one, flidas, need to make it that way
1358 gpgpath=$(which gpg2) ||:
1359 if [[ $gpgpath ]]; then
1360 sudo mkdir -p /usr/local/spdhackfix
1361 s lnf -T $gpgpath /usr/local/spdhackfix/gpg
1362 fi
1363 fi
1364 ### end spd install
1365
1366
1367 # nagstamon setting which were set through the ui
1368 # monitor url https://klaxon.fsf.org/cgi-bin
1369 # monitor url cgi https://klaxon.fsf.org/cgi-bin
1370 # in filters tab:
1371 # all unknown services
1372 # all warning services
1373 # acknowledged hosts & services
1374 # hosts & services down for maintenence
1375 # services on down hosts
1376 # services on hosts in maintenece
1377 # services on unreachable osts
1378 # hosts in soft state
1379 # services in soft state
1380 # in display tab: fullscreen
1381
1382 # these translate to these settings I think
1383 # filter_acknowledged_hosts_services = True
1384 # filter_all_unknown_services = True
1385 # filter_all_warning_services = True
1386 # filter_hosts_in_soft_state = True
1387 # filter_hosts_services_maintenance = True
1388 # filter_services_in_soft_state = True
1389 # filter_services_on_down_hosts = True
1390 # filter_services_on_hosts_in_maintenance = True
1391 # filter_services_on_unreachable_hosts = True
1392 # notify_if_up = False
1393 # statusbar_floating = False
1394 # fullscreen = True
1395 # but i'm just going to rely on the webpage plus sms for now.
1396
1397
1398 # it asks if it should make users in it's group capture packets without root,
1399 # which is arguably more secure than running wireshark as root. default is no,
1400 # which is what i prefer, since I plan to use tcpdump to input to wireshark.
1401 s DEBIAN_FRONTEND=noninteractive pi wireshark-gtk
1402
1403 # /run and /dev/shm are listed as required for pulseaudio. All 4 in the group
1404 # listed in the default config as suggested.
1405 # /run/usr/1000 i noticed was missing for pulseaudio
1406 # /run/user/0 just seemed like a not bad idea, given the above
1407 tu /etc/schroot/desktop/fstab <<'EOF'
1408 /p /p none rw,bind 0 0
1409 /a /a none rw,bind 0 0
1410 /run /run none rw,bind 0 0
1411 /run/lock /run/lock none rw,bind 0 0
1412 /dev/shm /dev/shm none rw,bind 0 0
1413 /run/shm /run/shm none rw,bind 0 0
1414 /run/user/1000 /run/user/1000 none rw,bind 0 0
1415 /run/user/1001 /run/user/1001 none rw,bind 0 0
1416 /run/user/0 /run/user/0 none rw,bind 0 0
1417 EOF
1418
1419 # todo: consider if this should use the new sysd-prom-fail
1420 sd /etc/systemd/system/schrootupdate.service <<'EOF'
1421 [Unit]
1422 Description=schrootupdate
1423 After=multi-user.target
1424
1425 [Service]
1426 Type=oneshot
1427 ExecStart=/usr/local/bin/sysd-mail-once schrootupdate /a/bin/distro-setup/schrootupdate
1428 EOF
1429 sd /etc/systemd/system/schrootupdate.timer <<'EOF'
1430 [Unit]
1431 Description=schrootupdate
1432
1433 [Timer]
1434 OnCalendar=*-*-* 04:20:00 America/New_York
1435
1436 [Install]
1437 WantedBy=timers.target
1438 EOF
1439 ser daemon-reload
1440 sgo schrootupdate.timer
1441
1442
1443
1444 # for my roommate
1445 case $distro in
1446 trisquel)
1447 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/bullseye.list/BULLSEYE_FREE \
1448 debian bullseye firefox-esr pulseaudio chromium anki
1449 case $(debian-codename) in
1450 etiona|nabia)
1451 # we have a lot of t8 stuff, useful to have
1452 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/flidas.list/FLIDAS \
1453 trisquel flidas
1454 tu /nocow/schroot/flidas/etc/sudoers <<EOF
1455 $USER ALL=(ALL) NOPASSWD: ALL
1456 Defaults env_keep += SUDOD
1457 Defaults always_set_home
1458 Defaults !umask
1459 EOF
1460 sd /nocow/schroot/flidas//etc/locale.gen <<'EOF'
1461 en_US.UTF-8 UTF-8
1462 EOF
1463 s schroot -c flidas locale-gen
1464 s schroot -c flidas update-locale LANG=en_US.UTF-8
1465
1466 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/testing.list/TESTING_NONFREE debian unstable debootstrap
1467 sudo cp -a /nocow/schroot/unstable/usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
1468
1469 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/impish.list/IMPISH ubuntu impish
1470
1471 ;;
1472 esac
1473 ;;
1474 debian)
1475 pi chromium
1476 ;;
1477 esac
1478
1479 sudo mkdir -p /nocow/user
1480 sudo chown $USER:$USER /nocow/user
1481 pi anki
1482
1483
1484 ####### begin transmission
1485
1486 case $HOSTNAME in
1487 frodo)
1488 tdir=/i/k
1489 ;;
1490 kd)
1491 tdir=/d/tor
1492 ;;
1493 *)
1494 tdir=/nocow/user/tor
1495 ;;
1496 esac
1497
1498 sudo mkdir -p $tdir
1499
1500 # adapted from /var/lib/dpkg/info/transmission-daemon.postinst
1501 # 450 seems likely to be unused. we need to specify one or else
1502 # it won't be stable across installs.
1503 if ! getent passwd debian-transmission > /dev/null; then
1504 sudo groupadd -g 450 debian-transmission
1505 sudo adduser --quiet \
1506 --gid 450 \
1507 --uid 450 \
1508 --system \
1509 --no-create-home \
1510 --disabled-password \
1511 --home /var/lib/transmission-daemon \
1512 debian-transmission
1513 fi
1514 # We want group writable stuff from transmission.
1515 # However, after setting this, I learn that transmission sets it's
1516 # own umask based on it's settings file. Well, no harm leaving this
1517 # so it's set right from the beginning.
1518 sudo chfn debian-transmission -o umask=0002
1519
1520 # note i had to do this, which is persistent:
1521 # cd /i/k
1522 # s chgrp debian-transmission torrents partial-torrents
1523
1524 # syslog says things like
1525 # 'Failed to set receive buffer: requested 4194304, got 425984'
1526 # google suggets giving it even more than that
1527 tu /etc/sysctl.conf<<'EOF'
1528 net.core.rmem_max = 67108864
1529 net.core.wmem_max = 16777216
1530 EOF
1531 sudo sysctl -p
1532
1533 # some reason it doesn\'t seem to start automatically anyways
1534 pi-nostart transmission-daemon
1535 # be extra sure its not started
1536 ser disable transmission-daemon
1537 ser stop transmission-daemon
1538
1539 # the folder was moved here after an install around 02/2017.
1540 # it contains runtime data,
1541 # plus a simple symlink to the config file which it\'s
1542 # not worth separating out.
1543 # between comps, the uid can change
1544
1545 f=$tdir/transmission-daemon
1546 for d in $tdir/partial-torrents $tdir/torrents $f; do
1547 if [[ ! -d $d ]]; then
1548 sudo mkdir -p $d
1549 fi
1550 sudo chown -R debian-transmission:user2 $d
1551 done
1552 s lnf -T $f /var/lib/transmission-daemon/.config/transmission-daemon
1553 s lnf -T /etc/transmission-daemon/settings.json $f/settings.json
1554 sudo chown -R debian-transmission:debian-transmission $f
1555 sudo chown -R debian-transmission:debian-transmission /var/lib/transmission-daemon
1556 #
1557 # config file documented here, and it\'s the same config
1558 # for daemon vs client, so it\'s documented in the gui.
1559 # https://trac.transmissionbt.com/wiki/EditConfigFiles#Options
1560 #
1561 # I originaly setup rpc-whitelist, but after using
1562 # routing to a network namespace, it doesn\'t see the
1563 # real source address, so it\'s disabled.
1564 #
1565 # Changed the cache-size to 256 mb, reduces disk use.
1566 # It is a read & write cache.
1567 #
1568 # just fyi: default rpc port is 9091
1569 if ! systemctl is-active transmission-daemon-nn &>/dev/null && \
1570 ! systemctl is-active transmission-daemon; then
1571 tmp=$(mktemp)
1572 command sudo ruby <<EOF >$tmp
1573 require 'json'
1574 p = '/etc/transmission-daemon/settings.json'
1575 s = {
1576 'rpc-whitelist-enabled' => false,
1577 'rpc-authentication-required' => false,
1578 'incomplete-dir' => '$tdir/partial-torrents',
1579 'incomplete-dir-enabled' => true,
1580 'download-dir' => '$tdir/torrents',
1581 "speed-limit-up" => 800,
1582 "speed-limit-up-enabled" => true,
1583 "peer-port" => 61486,
1584 "cache-size-mb" => 256,
1585 "ratio-limit" => 5.0,
1586 "ratio-limit-enabled" => false,
1587 }
1588 puts(JSON.pretty_generate(JSON.parse(File.read(p)).merge(s)))
1589 EOF
1590 cat $tmp | sudo dd of=/etc/transmission-daemon/settings.json
1591
1592 fi
1593
1594 ####### end transmission
1595
1596 case $HOSTNAME in
1597 kd)
1598 # to persist upload/dl metadata. initially, moved all the stuff
1599 # in /var/lib/transmission-daemon to /d/tor
1600 s usermod --home /d/tor debian-transmission
1601 sgo transmission-daemon-nn
1602
1603 ;;
1604 esac
1605
1606
1607 ######### begin transmission client setup ######
1608
1609 # to connect from a remote client, trans-remote-route in brc2
1610
1611
1612 if [[ -e /p/transmission-rpc-pass ]]; then
1613 # arch had a default config,
1614 # debian had nothing until you start it.
1615 # With a little trial an error, here is a minimal config
1616 # taken from the generated one, plus changes that the
1617 # settings ui does, without a bunch of ui crap settings.
1618 #
1619 # only settings I set were
1620 # hostname
1621 # auto-connect
1622 # password
1623
1624 # the password is randomly generated on first run, i copied it out
1625 # so it could be used by other hosts.
1626 sudo ruby <<'EOF'
1627 require 'json'
1628 p = '/etc/transmission-daemon/settings.json'
1629 s = JSON.parse(File.read(p))
1630 s["rpc-password"] = File.read("/p/transmission-rpc-pass").chomp
1631 # default is 0022 (18 in decimal)
1632 s["umask"] = 2
1633 File.write p, JSON.pretty_generate(s)
1634 EOF
1635
1636 rpc_pass=$(</p/transmission-rpc-pass)
1637 for f in /home/*; do
1638 u=${f##*/}
1639 uid=$(id -u $u 2>/dev/null) || continue
1640 if [[ ! $uid -ge 1000 ]]; then
1641 continue
1642 fi
1643 d=$f/.config/transmission-remote-gtk
1644 sudo -u $u mkdir -p $d
1645 # i tried setting hostname to transmission.b8.nz, so i could dynamically change where
1646 # this connects to, but it said some 421 denied error when I did that. Then it
1647 # froze X when i ran it under strace. Whatever.
1648 sudo -u $u dd of=$d/config.json <<EOF
1649 {
1650 "profiles" : [
1651 {
1652 "profile-name" : "Default",
1653 "hostname" : "10.174.2.2",
1654 "rpc-url-path" : "/transmission/rpc",
1655 "username" : "",
1656 "password" : "$rpc_pass",
1657 "auto-connect" : true,
1658 "ssl" : false,
1659 "timeout" : 40,
1660 "retries" : 3,
1661 "update-active-only" : false,
1662 "activeonly-fullsync-enabled" : false,
1663 "activeonly-fullsync-every" : 2,
1664 "update-interval" : 3,
1665 "min-update-interval" : 3,
1666 "session-update-interval" : 60,
1667 "exec-commands" : [],
1668 "destinations" : []
1669 }
1670 ],
1671 "profile-id" : 0,
1672 "add-options-dialog" : false
1673 }
1674 EOF
1675 done
1676 fi
1677 ######### end transmission client setup ######
1678
1679
1680 ### printer setup
1681 pi cups
1682
1683 sudo gpasswd -a $USER lpadmin # based on ubuntu wiki
1684 # goto http://127.0.0.1:631
1685 # administration tab, add new printer button.
1686 # In debian, I could use hte recommended driver,
1687 # in arch, I had to pick out the 6L driver.
1688
1689
1690 # bridge networking as user fails. google lead here, but it doesn\'t work:
1691 # oh well, I give up.
1692 # http://wiki.qemu.org/Features-Done/HelperNetworking
1693 # s mkdir /etc/qemu
1694 # f=/etc/qemu/bridge.conf
1695 # sd $f <<'EOF'
1696 # allow br0
1697 # EOF
1698 # #s chown root:qemu $f # debian has somethig like qemu-libvirt. equivalent?
1699 # s chmod 640 $f
1700
1701 # general known for debian/ubuntu, not for fedora
1702
1703 m /a/bin/buildscripts/go
1704 # only needed for rg. cargo takes up 11 gigs, filled up the disk on je.
1705 m /a/bin/buildscripts/rust
1706 m /a/bin/buildscripts/misc
1707 m /a/bin/buildscripts/pithosfly
1708 #m /a/bin/buildscripts/alacritty
1709 #m /a/bin/buildscripts/kitty
1710
1711 pi-nostart virtinst virt-manager
1712 soff libvirtd
1713 # i cant if this is whats causing it to start even though
1714 # its disabled. note: it leaves around dnsmasq instances even
1715 # if you stop it. what the hell systemd?
1716 soff libvirt-guests
1717 # allow user to run vms, from debian handbook. libvirt-qemu
1718 # based on https://www.whonix.org/wiki/KVM#First-time_User.3F
1719 for x in iank user2; do s usermod -a -G libvirt,kvm,libvirt-qemu $x; done
1720
1721
1722 pi --no-install-recommends kdeconnect
1723 ### kdeconnect for gnome. started in /a/bin/distro-setup/desktop-20-autostart.sh
1724 ### but gnome + xmonad not working in flidas, so i disabled it
1725 # pi libgtk-3-dev python3-requests-oauthlib valac cmake python-nautilus libappindicator3-dev
1726 # cd /a/opt/indicator-kdeconnect
1727 # mkdir -p build
1728 # cd build
1729 # cmake .. -DCMAKE_INSTALL_PREFIX=/usr
1730 # make
1731 # sudo make install
1732 # # we can start it manually with /usr/lib/x86_64-linux-gnu/libexec/kdeconnectd
1733 # # it seems, according to
1734 # # /etc/xdg/autostart/kdeconnectd.desktop
1735 # # I'm not seeing the icon, but the clipboard replication is working
1736
1737
1738 ### begin model 01 arduino support ###
1739 # https://github.com/keyboardio/Kaleidoscope/wiki/Install-Arduino-support-on-Linux
1740 # also built latest arduino in /a/opt/Arduino, (just cd build; ant build; ant run )
1741 # set arduino var in bashrc,
1742 # have system config file setup too.
1743 sudo adduser $USER dialout
1744
1745 # as of 2022-05,
1746 # download arduino ide, extract in /a/opt, ignore the install script, run ./arduino,
1747 # toolbar, preferences, add board manager url:
1748 # https://raw.githubusercontent.com/keyboardio/boardsmanager/master/package_keyboardio_index.json
1749 # toolbar, board manager, add keyboardio
1750 # toolbar, select model01 board
1751 # toolbar, examples, model01, compile
1752
1753 ###
1754
1755 # this is for the mail command too. update-alternatives is kind of misleading
1756 # since at least it's main commands pretend mail does not exist.
1757 # bsd's mail got pulled in on some dumb dependency, i dunno how.
1758 sudo update-alternatives --set mailx /usr/bin/mail.mailutils
1759
1760 ######### end misc packages #########
1761
1762
1763 # packages I once used before and liked, but don\'t want installed now for
1764 # various reasons:
1765 # python-sqlite is used for offlineimap
1766 # lxappearance python-sqlite dolphin paman dconf-editor
1767
1768
1769
1770 ######## unfinished
1771
1772 # todo, finish configuring smart.
1773
1774 pi smartmontools
1775 # mostly from https://wiki.archlinux.org/index.php/S.M.A.R.T.
1776 # turn on smart. background on options:
1777 # first line, -a = test everyting on all devices.
1778 # -S on, turn on disk internal saving of vendor specific info,
1779 # from google, seems like this is usually already on and fairly standard.
1780 # -o on, turn on 4 hour period non-performance degrading testing.
1781 # short test daily 2-3am, extended tests Saturdays between 3-4am:
1782 sched="-s (S/../.././02|L/../../6/03)"
1783 sudo sed -i --follow-symlinks "s#^[[:space:]]*DEVICESCAN.*#\
1784 DEVICESCAN -a -o on -S on -n standby,q $sched \
1785 -m root@mail.iankelling.org -M exec /usr/local/bin/smart-notify#" /etc/smartd.conf
1786
1787 # in the default configuration of at least ubuntu 14.04, resolvconf is
1788 # configured to order any nameservers associated with tun* or tap*
1789 # before the normal internet interfaces, which means they are always
1790 # consulted first. This is often slower and undesirable, ie. local dns
1791 # queries go from 0ms to 10+ or 100+ ms. To reverse the ordering, you
1792 # can do:
1793 #sudo sed -i --follow-symlinks '/tun\*\|tap\*/d' /etc/resolvconf/interface-order
1794 # however, this breaks dns lookup for hosts on the openvpn lan.
1795 # I can\'t figure out why hosts on the normal lan would not be
1796 # broken under the default ordering, except the host I was
1797 # testing with previously had an entry in /etc/hosts.
1798
1799 ############# end unfinished
1800
1801 ########### misc stuff
1802
1803
1804 xdg-settings set default-web-browser abrowser.desktop
1805 # see current with:
1806 # xdg-settings get default-web-browser
1807
1808 # pressing tab after sdf here:
1809 # scp sdfbash: set +o noglob: command not found
1810 # in t11, bash 5.1.16. this fixes it.
1811 sudo sed -ri 's/([[:space:]]*)(\$reset)$/\1set +o noglob #$reset/' /usr/share/bash-completion/bash_completion
1812
1813 rm -fv /home/iank/.mpv/watch_later
1814 rm -rf /home/iank/.mpv
1815
1816 if [[ ! -e ~/.local/bin/pip ]]; then
1817 tmp=$(mktemp)
1818 wget -O$tmp https://bootstrap.pypa.io/get-pip.py
1819 python3 $tmp --user
1820 hash -r
1821 fi
1822
1823 ## begin beets
1824 # soo, apt install beets fails due to wanting a pip package,
1825 # we find out why it wants this through
1826 # apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances beets | less
1827 # python-mediafile requires tox, which requires virtualenv, which requires pip.
1828 # but, python-mediafile doesn't really require tox, it is specified in
1829 # ./usr/lib/python3/dist-packages/mediafile-0.9.0.dist-info/METADATA
1830 # as being required only for testing, but the debian package
1831 # included it anyways, due to a mistake or bad tooling or something.
1832 # I don't plan to use tox, so, according to https://serverfault.com/a/251091,
1833 # we can create and install a dummy package by:
1834 #
1835 # "equivs-control <name>, edit the file produced to provide the right
1836 # dependency and have a nice name, then run equivs-build <name> and
1837 # finally dpkg -i the resulting .deb file"
1838 # as of 2023-02, the tox dependency was removed in debian unstable, so
1839 # this hack will probably go away in t12.
1840
1841 if pcheck beets; then
1842 tmpdir="$(mktemp -d)"
1843 cd "$tmpdir"
1844 # edited from output of equivs-control tox
1845 cat >tox <<'EOF'
1846 Section: python
1847 Priority: optional
1848 Standards-Version: 3.9.2
1849 Package: tox
1850 Description: tox-dummy
1851 EOF
1852 equivs-build tox
1853 sudo dpkg -i tox_1.0_all.deb
1854 rm -rf ./tox*
1855 pi beets python3-discogs-client
1856 cd
1857 rm -r "$tmpdir"
1858 fi
1859
1860 # get rid of annoying message
1861 s sed -ri "s/^([[:space:]]*ui.print_\('Playing)/#\1/" /usr/share/beets/beetsplug/play.py
1862
1863
1864 # notes about barrier
1865 # run barrier, do the gui config,
1866 # setup the 2 screens, using hostnames for the new screen.
1867 # save the server config
1868 # $HOME/.local/share/barrier/.barrier.conf
1869 # per the man page.
1870 #
1871 # ssl errors, resolved via advice here: https://github.com/debauchee/barrier/issues/231
1872 # BARRIER_SSL_PATH=~/.local/share/barrier/SSL/
1873 # mkdir -p "${BARRIER_SSL_PATH}"
1874 # openssl req -x509 -nodes -days 365 -subj /CN=Barrier -newkey rsa:4096 -keyout ${BARRIER_SSL_PATH}/Barrier.pem -out ${BARRIER_SSL_PATH}/Barrier.pem
1875 # ran on both machines.
1876 # When pressing start in the gui, the cli options used are printed to the console,
1877 # they are useful. So on server, just run barriers, client run barrierc SERVER_IP
1878
1879 ### begin timetrap setup
1880 if mountpoint /p &>/dev/null; then
1881 mkdir -p ~/.timetrap/
1882 ln -sf /a/opt/timetrap_formatters ~/.timetrap/formatters
1883 if ! type -p t &>/dev/null; then
1884 pi ruby-dev libsqlite3-dev
1885 gem install --user timetrap
1886 fi
1887 fi
1888 ### end timetrap setup
1889
1890 # leftover cleanup for t9
1891 pu resolvconf
1892
1893 case $codename in
1894 # needed for debootstrap scripts for fai since fai requires debian
1895 flidas)
1896 pi dnsmasq
1897 pi-nostart network-manager
1898 # i hate networkmanager. noo, of course disabling it doesnt work
1899 # unless you add a hack. found this by doing
1900 # systemd-analyze dot > x.dot
1901 # less x.dot
1902 # /networkman
1903 soff NetworkManager
1904 soff NetworkManager-wait-online.service
1905 # make networkmanager use resolvconf instead of its own dnsmasq which
1906 # conflicts with the normal dnsmasq package.
1907 f=/etc/NetworkManager/NetworkManager.conf
1908 m=$(md5sum $f)
1909 sudo sed -ri '/ *\[main\]/,/^ *\[[^]]+\]/{/^\s*dns[[:space:]=]/d}' $f
1910 sudo sed -ri '/ *\[main\]/a dns=default' $f
1911 if [[ $m != $(md5sum $f) ]]; then
1912 srestart NetworkManager
1913 fi
1914 # networkmanager has this nasty behavior on flidas: if the machine
1915 # crashes with dnsmasq running, on subsequent boot, it adds an entry to
1916 # resolvconf for 127.0.0.1 in some stupid attempt to restore
1917 # nameservers.
1918 # This can be manually fixed by stoping dnsmasq,
1919 # then based on whats in /run/dnsmasq/, i see we can run
1920 # s resolvconf -d NetworkManager
1921 # oh ya, and stoping NetworkManager leaves this crap behind without cleaning it up.
1922 ser disable NetworkManager
1923 ;;
1924 esac
1925
1926 # I have no use for avahi,
1927 # had to run this twice when doing manually, i dunno why
1928 soff avahi-daemon ||:
1929 sleep 1
1930 soff avahi-daemon
1931
1932 # make my /etc/fonts/conf.d/ get used.
1933 # I have a new sans-serif font there because the default one
1934 # displays l and I as the same char, grrrrr.
1935 sudo fc-cache
1936
1937 pi desktop-file-utils
1938 m /a/bin/distro-setup/mymimes
1939
1940 if type -p dbus-launch >/dev/null; then
1941 # stop autopoping windows when i plug in an android phone.
1942 # dbus-launch makes this work within an ssh connection, otherwise you get this message,
1943 # with still 0 exit code.
1944 # dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
1945 m dbus-launch gsettings set org.gnome.desktop.media-handling automount-open false
1946 fi
1947
1948 # on grub upgrade, we get prompts unless we do this
1949 devs=()
1950 for dev in $(s btrfs fil show /boot | sed -nr 's#.*path\s+(\S+)$#\1#p'); do
1951 devs+=("$(devbyid $dev),")
1952 done
1953 devs[-1]=${devs[-1]%,} # jonied by commas
1954 sudo debconf-set-selections <<EOF
1955 grub-pc grub-pc/install_devices multiselect ${devs[*]}
1956 EOF
1957
1958
1959 sysd-prom-fail-install dynamicipupdate
1960 sysd-prom-fail-install systemstatus
1961 sysd-prom-fail-install btrfsmaintstop
1962 sgo btrfsmaint.timer
1963 sgo btrfsmaintstop
1964 sgo systemstatus
1965 sgo dynamicipupdate
1966
1967
1968 if grep -xFq $HOSTNAME /a/bin/ds/machine_specific/btrbk.hosts; then
1969 sgo btrbk.timer
1970 fi
1971
1972 # note: to see when a timer was last run,
1973 # ser list-timers
1974
1975
1976 ### begin prometheus ###
1977
1978 case $HOSTNAME in
1979 kd)
1980 # Font awesome is needed for the alertmanager ui.
1981 pi prometheus-alertmanager prometheus fonts-font-awesome
1982 /c/roles/prom/files/simple/usr/local/bin/fsf-install-prometheus
1983 # make it available for other machines
1984 rsync -a /usr/local/bin/amtool /a/opt/bin
1985 web-conf -p 9091 -f 9090 - apache2 i.b8.nz <<'EOF'
1986 <Location "/">
1987 AuthType Basic
1988 AuthName "basic_auth"
1989 # created with
1990 # htpasswd -c prometheus-htpasswd USERNAME
1991 AuthUserFile "/etc/prometheus-htpasswd"
1992 Require valid-user
1993 </Location>
1994 EOF
1995
1996 web-conf -p 9094 -f 9093 - apache2 i.b8.nz <<'EOF'
1997 <Location "/">
1998 AuthType Basic
1999 AuthName "basic_auth"
2000 # created with
2001 # htpasswd -c prometheus-htpasswd USERNAME
2002 AuthUserFile "/etc/prometheus-htpasswd"
2003 Require valid-user
2004 </Location>
2005 EOF
2006
2007 # by default, the alertmanager web ui is not enabled other than a page
2008 # that suggests to use the amtool cli. that tool is good, but you cant
2009 # silence things nearly as easily as with the gui.
2010 if [[ ! -e /usr/share/prometheus/alertmanager/ui/index.html ]]; then
2011 # default script didnt work, required some changes to get elm 19.1,
2012 # which is a dependency of the latest alertmanager. I modified
2013 # and copied it into /b/ds. In future, might need some other
2014 # solution.
2015 #sudo /usr/share/prometheus/alertmanager/generate-ui.sh
2016 sudo /b/ds/generate-ui.sh
2017 ser restart prometheus-alertmanager
2018 fi
2019
2020 s /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter -l 127.0.0.1
2021
2022 for ser in prometheus-node-exporter prometheus-alertmanager prometheus; do
2023 sysd-prom-fail-install $ser
2024 done
2025
2026 ;;
2027 *)
2028 s /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter
2029 ;;
2030 esac
2031
2032 # cleanup old files. 2023-02
2033 x=(/var/lib/prometheus/node-exporter/*.premerge)
2034 if [[ -e ${x[0]} ]]; then
2035 s rm /var/lib/prometheus/node-exporter/*
2036 fi
2037
2038
2039 case $HOSTNAME in
2040 # todo, for limiting node exporter http,
2041 # either use iptables or, in
2042 # /etc/default/prometheus-node-exporter
2043 # listen on the wireguard interface
2044
2045 *)
2046 wgip=$(command sudo sed -rn 's,^ *Address *= *([^/]+).*,\1,p' /etc/wireguard/wghole.conf)
2047 # old filename. remove once all hosts are updated.
2048 s rm -fv /etc/apache2/sites-enabled/${HOSTNAME}wg.b8.nz.conf
2049 web-conf -i -a $wgip -p 9101 -f 9100 - apache2 ${HOSTNAME}wg.b8.nz <<'EOF'
2050 <Location "/">
2051 AuthType Basic
2052 AuthName "basic_auth"
2053 # created with
2054 # htpasswd -c prometheus-export-htpasswd USERNAME
2055 AuthUserFile "/etc/prometheus-export-htpasswd"
2056 Require valid-user
2057 </Location>
2058 EOF
2059 # For work, i think we will just use the firewall for hosts in the main data center, and
2060 # vpn for hosts outside it.
2061
2062 # TODO: figure out how to detect the ping failure and try again.
2063
2064 # Binding to the wg interface, it might go down, so always restart, and wait for it on boot.
2065 s mkdir /etc/systemd/system/apache2.service.d
2066 sd /etc/systemd/system/apache2.service.d/restart.conf <<EOF
2067 [Unit]
2068 After=wg-quick@wghole.service
2069 StartLimitIntervalSec=0
2070
2071 [Service]
2072 Restart=always
2073 RestartSec=30
2074 EOF
2075
2076 ;;
2077 esac
2078
2079 ### end prometheus ###
2080
2081 ### begin nagios ###
2082
2083 pi nagios-nrpe-server
2084
2085 case $HOSTNAME in
2086 kd)
2087 # the backport is for this bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=800345
2088 pi nagios4 nagios-nrpe-plugin monitoring-plugins-basic/bullseye-backports
2089 s rm -fv /etc/apache2/conf-enabled/nagios4-cgi.conf
2090
2091 # to add a password for admin:
2092 # htdigest /etc/nagios4/htdigest.users Nagios4 iank
2093 # now using the same pass as prometheus
2094
2095 # nagstamon auth settings, set to digest instead of basic.
2096
2097 web-conf -p 3005 - apache2 i.b8.nz <<'EOF'
2098 # adapted from /etc/apache2/conf-enabled/nagios4-cgi.conf
2099
2100 ScriptAlias /cgi-bin/nagios4 /usr/lib/cgi-bin/nagios4
2101 ScriptAlias /nagios4/cgi-bin /usr/lib/cgi-bin/nagios4
2102
2103 # Where the stylesheets (config files) reside
2104 Alias /nagios4/stylesheets /etc/nagios4/stylesheets
2105
2106 # Where the HTML pages live
2107 Alias /nagios4 /usr/share/nagios4/htdocs
2108
2109 <DirectoryMatch (/usr/share/nagios4/htdocs|/usr/lib/cgi-bin/nagios4|/etc/nagios4/stylesheets)>
2110 Options FollowSymLinks
2111 DirectoryIndex index.php index.html
2112 AllowOverride AuthConfig
2113 #
2114 # The default Debian nagios4 install sets use_authentication=0 in
2115 # /etc/nagios4/cgi.cfg, which turns off nagos's internal authentication.
2116 # This is insecure. As a compromise this default apache2 configuration
2117 # only allows private IP addresses access.
2118 #
2119 # The <Files>...</Files> below shows how you can secure the nagios4
2120 # web site so anybody can view it, but only authenticated users can issue
2121 # commands (such as silence notifications). To do that replace the
2122 # "Require all granted" with "Require valid-user", and use htdigest
2123 # program from the apache2-utils package to add users to
2124 # /etc/nagios4/htdigest.users.
2125 #
2126 # A step up is to insist all users validate themselves by moving
2127 # the stanza's in the <Files>..<Files> into the <DirectoryMatch>.
2128 # Then by setting use_authentication=1 in /etc/nagios4/cgi.cfg you
2129 # can configure which people get to see a particular service from
2130 # within the nagios configuration.
2131 #
2132 AuthDigestDomain "Nagios4"
2133 AuthDigestProvider file
2134 AuthUserFile "/etc/nagios4-htdigest.users"
2135 AuthGroupFile "/etc/group"
2136 AuthName "Nagios4"
2137 AuthType Digest
2138 Require valid-user
2139 </DirectoryMatch>
2140
2141 <Directory /usr/share/nagios4/htdocs>
2142 Options +ExecCGI
2143 </Directory>
2144 EOF
2145 ;;
2146 esac
2147
2148 # when you alter a service through the web, it changes vars in /var/lib/nagios4/status.dat. for example:
2149 # notifications_enabled=1
2150 # note, the same variable exists in the correspdonding "define service {"
2151
2152 # in the default config, we have these definitions
2153
2154 # 11 define command {
2155 # 2 define contact {
2156 # 1 define contactgroup {
2157 # 9 define host {
2158 # 4 define hostgroup {
2159 # 23 define service {
2160 # 5 define timeperiod {
2161
2162
2163 # on klaxon
2164
2165 # klaxon:/etc/nagios3 # grep -rho '^ *define [^{ ]*' | sort | uniq -c
2166 # 76 define command
2167 # 11 define contact
2168 # 6 define contactgroup
2169 # 162 define host
2170 # 1 define hostextinfo
2171 # 16 define hostgroup
2172 # 3040 define service
2173 # 2 define servicedependency
2174 # 6 define timeperiod
2175
2176
2177
2178
2179 ### end nagios ###
2180
2181 ### begin bitcoin ###
2182
2183 case $HOSTNAME in
2184 sy|kd)
2185 sudo install -m 0755 -o root -g root -t /usr/bin /a/opt/bitcoin-26.0/bin/*
2186 # Note: i leave it to system-status to start and stop bitcoin.
2187 # note: the bitcoin user & group are setup in fai
2188 sudo usermod -a -G bitcoin iank
2189 # todo: make bitcoin have a stable uid/gid
2190 sudo mkdir -p /var/lib/bitcoind
2191 sudo chown bitcoin:bitcoin /var/lib/bitcoind
2192 # 710 comes from the upstream bitcoin unit file
2193 sudo chmod 710 /var/lib/bitcoind
2194 # note, there exists
2195 # /a/bin/ds/disabled/bitcoin
2196 ;;
2197 esac
2198
2199 ### end bitcoin
2200
2201 ### begin gh ####
2202
2203 # from https://raw.githubusercontent.com/cli/cli/trunk/docs/install_linux.md
2204 # One time setup afterwards:
2205 # gh auth login
2206 #
2207 # When it gets to the page where it asks to authorize github, the button
2208 # is grayed out. You can just open browser dev tools, inspect the
2209 # button, remove disabled="", then click it and it works.
2210 #
2211 # Auth token gets saved into /p/c/subdir_files/.local/share/keyrings/
2212 #
2213 # initial config goes to /home/iank/.config/gh
2214 curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
2215 && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
2216 && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
2217 && sudo apt update \
2218 && sudo apt install gh -y
2219
2220 ### end gh ####
2221
2222 # remove trisquel banner. it is cool but takes up too much space.
2223 sudo rm -f /etc/update-motd.d/01-banner
2224
2225 case $HOSTNAME in
2226 kw|x3)
2227 sd /etc/cups/client.conf <<'EOF'
2228 ServerName printserver1.office.fsf.org
2229 EOF
2230 ;;
2231 esac
2232
2233
2234 end_msg <<'EOF'
2235 In mate settings settings, change scrolling to two-finger,
2236 because the default edge scroll doesn\'t work. Originally found this in debian.
2237 EOF
2238
2239 # Remove dep that came in with desktop to fix associations.
2240 m pu transmission-gtk
2241
2242 case $HOSTNAME in
2243 kd)
2244 lnf -T /d/vidshare /home/iank/Videos
2245 ;;
2246 esac
2247
2248 # # Based on guix manual instructions, also added code to profile.
2249 # # disabled since i'm not using it now.
2250 # pi nscd
2251 # if ! type -p guix >/dev/null; then
2252 # cd $(mktemp -d)
2253 # wget https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
2254 # # added some stuff to envonment.sh for profile based on
2255 # # manual instructions
2256 # # wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -
2257 # # echo is to get past prompt
2258 # yes | sudo -E HOME=$HOME bash guix-install.sh || [[ $? == 141 ]]
2259 # guix install glibc-utf8-locales
2260 # guix package --install guile
2261 # fi
2262
2263 lnf -T /a/opt ~/src
2264
2265 pi tor
2266 m /a/bin/buildscripts/tor-browser
2267 # one root command needed to install
2268 s ln -sf /a/opt/tor-browser/Browser/start-tor-browser /usr/local/bin
2269
2270
2271 # nfs server
2272 pi-nostart nfs-kernel-server
2273
2274 # todo, this is old, probably needs removing
2275 if [[ $HOSTNAME == tp ]]; then
2276 sd /etc/wireguard/wg0.conf <<EOF
2277 [Interface]
2278 PrivateKey = $(cat /p/c/machine_specific/tp/filesystem/root/wg.key)
2279 Address = 10.3.0.2/24, fdfd::2/64
2280
2281 [Peer]
2282 PresharedKey = $(cat /p/c/machine_specific/tp/filesystem/root/wg.psk)
2283 PublicKey = 9RnAsJB+ISrA/9lmDKBoT08oBiKwzA64exBBj+rO+ng=
2284 Endpoint = b8.nz:26000
2285 AllowedIPs = 10.3.0.1/24, fdfd::1/64
2286 PersistentKeepalive = 20
2287 EOF
2288 sudo systemctl enable wg-quick@wg0
2289 sudo systemctl start wg-quick@wg0
2290 fi
2291
2292
2293 if [[ $HOSTNAME == kw ]]; then
2294 # hosts 1-199. 200+ are dynamic, avoid those
2295 tu /etc/exports <<'EOF'
2296 /root/.ianktrisquel_9/.iank/e/e 192.168.0.0/25(rw,no_root_squash,async,no_subtree_check) 192.168.0.128/26(rw,no_root_squash,async,no_subtree_check) 192.168.0.192/29(rw,no_root_squash,async,no_subtree_check)
2297 /home/iank/.iank/e/e 192.168.0.0/25(rw,no_root_squash,async,no_subtree_check) 192.168.0.128/26(rw,no_root_squash,async,no_subtree_check) 192.168.0.192/29(rw,no_root_squash,async,no_subtree_check)
2298 EOF
2299 ekw
2300 sgo nfs-server
2301 sudo exportfs -rav
2302 fi
2303
2304
2305 # if I was going to create a persistent vm, i might do it like this:
2306 # variant=something # from: virt-install --os-variant list
2307 # s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
2308 # --disk=/a/images/some_name.qcow2,bus=virtio --vcpus 2 -r 4096 -w bridge=br0 \
2309 # -n some_name --import --os-variant $variant --cpu host-model-only
2310
2311
2312 # for brother HL-2270DW, this worked:
2313 # https://askubuntu.com/questions/1067234/cant-use-wireless-brother-printer-2270dw-ubuntu-18-04
2314 # /a/opt/linux-brprinter-installer-2.2.2-1
2315 # answer n when it asks about uri.
2316 # Then go to cups, delete the existing printer, added on with dnssd url. browsed to
2317 # ppd at /usr/share/ppd/HL2270DW.ppd, which is duplicated at /usr/share/cups/model/HL2270DW.ppd
2318 # ppd file got installed from bash -x ./usr/local/Brother/Printer/HL2270DW/cupswrapper/cupswrap,
2319 # which I downloaded from their driver. but dont do that again, i copied it to /a/opt/HL2270DW.ppd,
2320 # use that.
2321
2322 # I had to reset it to use wired instead of wifi. it only uses 1 at a time. boot with go button held, after lights turn off, tap go 6 times.
2323 # Then it was already configured, but if i needed to, go to its web ui, default pass is "access".
2324
2325 ######### begin stuff belonging at the end ##########
2326
2327 end