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