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