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