mostly 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 this overrides it since its higher number.
573 # This file was part of the automatic-updates package,
574 # and it has a config 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 # note: man apt.conf says
579 # /usr/share/doc/apt/examples/configure-index.gz is a configuration file showing
580 # example values for all possible options.
581 # but that is a incorrect.
582 # Periodic and other options are only documented in
583 # /usr/lib/apt/apt.systemd.daily
584 # That filename can be found through poking around in apt daily cronjob.
585 APT::Periodic::Update-Package-Lists "1";
586 APT::Periodic::Download-Upgradeable-Packages "1";
587 # 0 means disabled. I used to set this to 7, however, trisquel doesn't
588 # have an archive of old package versions, so I want to
589 # keep around old versions so I can easily downgrade.
590 APT::Periodic::AutocleanInterval "0";
591 # daily expire old files /var/cache/apt if it gets above this MB
592 APT::Periodic::MaxSize "50000";
593 APT::Periodic::Unattended-Upgrade "1";
594 EOF
595
596 # fyi: default file has comments about available options,
597 # you may want to read that, do pkx unattended-upgrades
598 # default is just security updates. this list found from reading
599 # match_whitelist_string() in $(which unattended-upgrades)
600 sd /etc/apt/apt.conf.d/50unattended-upgrades <<EOF
601 Unattended-Upgrade::Mail "root";
602 Unattended-Upgrade::MailOnlyOnError "true";
603 Unattended-Upgrade::Remove-Unused-Dependencies "true";
604 Unattended-Upgrade::Origins-Pattern {
605 "o=*,l=*,a=*,c=*,site=*,n=*";
606 };
607 EOF
608
609 # old files
610 sudo rm -f /etc/cron.d/unattended-upgrade-reboot /usr/local/bin/zelous-unattended-reboot /etc/cron.d/myupgrade
611
612 # myupgrade cron exists in /etc/cron.d/ian
613
614 ##### end automatic upgrades ####
615
616
617 # commented in case i want to use this sometime later
618 # sd /etc/apt/preferences.d/buster-backports <<EOF
619 # Package: *
620 # Pin: release a=buster-backports
621 # Pin-Priority: 500
622 # EOF
623
624
625 ###### begin website setup
626 case $HOSTNAME in
627 li|bk|je)
628 pi bind9
629 f=/var/lib/bind/db.b8.nz
630 if [[ ! -e $f ]]; then
631 dnsb8
632 fi
633
634 s /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter -l 127.0.0.1
635
636 # ex for exporter
637 web-conf -p 9101 -f 9100 - apache2 ${HOSTNAME}ex.b8.nz <<'EOF'
638 <Location "/">
639 AuthType Basic
640 AuthName "basic_auth"
641 # created with
642 # htpasswd -c prometheus-export-htpasswd USERNAME
643 AuthUserFile "/etc/prometheus-export-htpasswd"
644 Require valid-user
645 </Location>
646 EOF
647 ;;&
648
649 bk)
650 sgo wg-quick@wgmail
651
652 # i just dont feel like setting up a special purpose ssh key to do this automatically.
653 end_msg <<'EOF'
654 # run this once for bk on local machine:
655 # only used for old openvpn setup
656 /a/exe/vpn-mk-client-cert -c bk.b8.nz -b expertpath -n mail li.iankelling.org
657 EOF
658 end
659 ;;
660 je)
661 end
662 ;;
663 li)
664
665 m /a/h/setup.sh iankelling.org
666
667 # start mumble only when im going to use it, since i dont use it much
668 pi-nostart mumble-server
669 sudo $sed -ri "s/^ *(serverpassword=).*/\1$(< /a/bin/bash_unpublished/mumble_pass)/" /etc/mumble-server.ini
670
671 # do certificate to avoid warning about unsigned cert,
672 # which is overkill for my use, but hey, I'm cool, I know
673 # how to do this.
674 m web-conf apache2 mumble.iankelling.org
675 sudo rm -fv /etc/apache2/sites-enabled/mumble.iankelling.org
676
677 # general vpn for as needed use
678 vpn-server-setup -d -r -4 10.5.5 -p 443 -n hole
679
680 # todo: consider if this should exist for the
681 # other vpn server
682 teeu /etc/openvpn/server/hole.conf <<'EOF'
683 client-to-client
684 EOF
685
686
687 ngset
688 files=(/etc/openvpn/client-config-hole/*)
689 if (( ${#files[@]} >= 1 )); then
690 rm -f ${files[@]}
691 fi
692 ngreset
693 for host in ${!vpn_ips[@]}; do
694 sd /etc/openvpn/client-config-hole/$host <<EOF
695 ifconfig-push 10.5.5.${vpn_ips[$host]} 255.255.255.0
696 EOF
697 done
698
699
700 # for adding cert to system with /p
701 #
702 # host=frodo
703 #mkc /p/c/machine_specific/$host/filesystem/etc/openvpn/client
704 #vpn-mk-client-cert -b $host -n hole -r iankelling.org
705 #s chown -R iank:iank .
706 #
707 # example of adding to remote system 107,
708 # vpn-mk-client-cert -n hole -c 10.2.0.107 -b hd8 iankelling.org
709 #
710 # for wireguard hole vpn, use function:
711 # wghole
712 # eg:
713 # wghole bo 28
714 # if it is going to want to connect to transmission-daemon on ok
715 # wghole bo 28 10.174.2.2/32
716
717 # requested from linode via a support ticket.
718 # https://www.linode.com/docs/networking/an-overview-of-ipv6-on-linode/
719 # ipv6 stuff pieced together
720 # via slightly wrong information from
721 # https://github.com/angristan/openvpn-install/blob/master/openvpn-install.sh
722 # https://community.openvpn.net/openvpn/wiki/IPv6
723 # and man openvpn.
724 #
725 # This uses a public /64, but afaik, that is not needed for my
726 # current use case, since I'm doing ipv6 nat, they could be private
727 # and nat to a public address. I'm doing ipv6 nat in order to have 2
728 # vpn clients that externally share the same ip when sending so they
729 # share ip reputation. Note, the eth0 and tunx needed to be
730 # different subnets. On the same, I saw some neighbor packet go
731 # unanswered, tcpdump showed packets getting lost. I tried splitting the
732 # /64, it didn't work but I didn't investigate closely.
733
734
735 # not starting as i intend to replace it
736 m vpn-server-setup -s -i tunmail -n mail -d -6 2600:3c00:e002:3800::/64 2600:3c00:e002:3800::1/64
737 sudo tee /etc/openvpn/client-config-mail/mailclient <<'EOF'
738 ifconfig-push 10.8.0.4 255.255.255.0
739 ifconfig-ipv6-push 2600:3c00:e002:3800::4/64
740 EOF
741 sudo tee /etc/openvpn/client-config-mail/expertpath <<'EOF'
742 ifconfig-push 10.8.0.5 255.255.255.0
743 ifconfig-ipv6-push 2600:3c00:e002:3800::5/64
744 EOF
745
746
747 sudo dd of=/etc/systemd/system/vpn-mail-forward.service <<'EOF'
748 [Unit]
749 Description=Turns on iptables mail nat
750 BindsTo=openvpn-server@mail.service
751
752 [Service]
753 Type=oneshot
754 RemainAfterExit=yes
755 ExecStart=/a/bin/distro-setup/vpn-mail-forward tunmail start
756 ExecStop=/a/bin/distro-setup/vpn-mail-forward tunmail stop
757
758 [Install]
759 RequiredBy=openvpn-server@mail.service
760 EOF
761 ser daemon-reload
762
763
764 # needed for li's local mail delivery.
765 tu /etc/hosts <<<"10.8.0.4 mx.iankelling.org"
766
767 # wgmail handles this.
768 #sgo vpn-mail-forward.service
769 # old:
770 #sgo openvpn-server@mail
771 sgo wg-quick@wgmail
772
773 # setup let's encrypt cert
774 m web-conf apache2 mail.iankelling.org
775 # TODO, i expanded the above cert manually to mx.iankelling.org, this should be captured
776 # in the automation here. We use mail.iankelling.org as our ehlo name when sending mail
777 # but our mx record is mx.iankelling.org. Initially I was just using mail.iankelling.org,
778 # but the problem is I want multiple ips to be able to identify as mail.iankelling.org,
779 # but a subset to be mx.iankelling.org. Afaik, there is no problem with having
780 # our mail cert be for mail.iankelling.org, and have people connect to mx.ian...,
781 # but it doesn't make logical sense to do this.
782 sudo rm -fv /etc/apache2/sites-enabled/mail.iankelling.org{,-redir}.conf
783 ser reload apache2
784
785 a2enmod -q proxy proxy_http
786 domain=cal.iankelling.org
787 web-conf -f 10.8.0.4:5232 - apache2 $domain <<'EOF'
788 # https://radicale.org/2.1.html
789 #https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype
790 # https://stackoverflow.com/questions/5011102/apache-reverse-proxy-with-basic-authentication
791
792 # this doesn't exactly fit with the documentation.
793 # We need location / to do an auth, it cant be done outside,
794 # in order to pass on X-Remote-User. And we need
795 # the other location in order to remove the /radicale/ for
796 # requests which have it. This could be done with a rewrite,
797 # but i just get something working and call it a day.
798
799 <Location "/">
800 AllowOverride None
801 AuthType Basic
802 AuthName "Authentication Required"
803 # setup one time, with root:www-data, 640
804 AuthUserFile "/etc/caldav-htpasswd"
805 Require valid-user
806 RequestHeader set X-Remote-User expr=%{REMOTE_USER}
807 </Location>
808 <Location "/radicale/">
809 Options +FollowSymLinks +Multiviews -Indexes
810 RequestHeader set X-Script-Name /radicale/
811 RequestHeader set X-Remote-User expr=%{REMOTE_USER}
812 ProxyPass "http://10.8.0.4:5232/" retry=0
813 ProxyPassReverse "http://10.8.0.4:5232/"
814 </Location>
815 EOF
816 # nginx version of above would be:
817 # auth_basic "Not currently available";
818 # auth_basic_user_file /etc/nginx/caldav/htpasswd;
819
820
821
822 ###### begin znc setup #####
823 pi znc
824
825 # https://wiki.znc.in/FAQ seems to imply that znc doesn\'t need restart after cert change.
826 # to get into the web interface,
827 # then use non-main browser or else it doebsn't allow it based on ocsp stapling from my main site.
828 # https://iankelling.org:12533/
829 # login as ian, pass is in pass store, the part after :
830
831 # znc config generated by doing
832 # znc --makeconf
833 # selected port is also used in erc config
834 # comma separated channel list worked.
835 # while figuring things out, running znc -D for debug in foreground.
836 # to exit and save config:
837 # /msg *status shutdown
838 # configed auth on freenode by following
839 # https://wiki.znc.in/Sasl:
840 # /query *sasl
841 # RequireAuth yes
842 # Mechanism PLAIN
843 # Set MyNickservName pa$$w0rd
844 # created the system service after, and had to do
845 # mv /home/iank/.znc/* /var/lib/znc
846 # sed -i 's,/home/iank/.znc/,/var/lib/znc,' /var/lib/znc/config/znc.conf
847 # and made a copy of the config files into /p/c
848 # /msg *status LoadMod --type=global log -sanitize
849 # todo: in config file AllowWeb = true should be false. better security if that is off unless we need it.
850 # /msg *status LoadMod --type=network perform
851 # /query *perform add PRIVMSG ChanServ :invite #fsf-office
852 # /msg *perform add JOIN #fsf-office
853 # /msg *status LoadMod NickServ
854 #
855 # i set Buffer = 500
856 # also ran /znc LoadMod clearbufferonmsg
857 # it would be nice if erc supported erc query buffers by doing
858 # /msg *status clearbuffer <name of the query/receiver
859 # on killing the,
860 # an example seems to be here: https://github.com/zenspider/elisp/blob/master/rwd-irc.el
861 # if that was the case i could remove the module clearbufferonmsg
862 # also would be nice if erc supported
863 # https://wiki.znc.in/self-message
864 # https://wiki.znc.in/Query_buffers \
865 #
866 # for geekshed, there was no sasl support as far as I can tell,
867 # so I set to msg nickserv to identify upon connect.
868 if ! getent passwd znc > /dev/null; then
869 sudo useradd --create-home -d /var/lib/znc --system --shell /sbin/nologin --comment "Account to run ZNC daemon" --user-group znc
870 fi
871 sudo chmod 700 /var/lib/znc
872 sudo chown -R znc:znc /var/lib/znc
873 # Avoid restarting if possible, reconnecting to irc is annoying.
874 # The unit file was made active with conflink.
875 # Note, avoid using ser here because we wrap sudo to prints the command first.
876 if [[ $(systemctl is-active znc) != active ]]; then
877 sgo znc
878 fi
879 ###### stop znc setup #####
880
881 end
882 ;;
883 esac
884
885 case $HOSTNAME in
886 bk)
887 pi icecast2
888 # todo, save the config
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 # old location, 2023.
1293 sudo rm -fv /etc/systemd/system/profanity.service
1294 case $HOSTNAME in
1295 kd)
1296 ln -sfT /d/p/profanity ~/.local/share/profanity
1297 ln -sfT /d/p/profanity-config ~/.config/profanity
1298 source /a/bin/bash_unpublished/source-state
1299 if [[ $HOSTNAME == "$HOST2" || ! -e /p/profanity-here ]]; then
1300 systemctl --user --now enable profanity
1301 fi
1302 ;;
1303 *)
1304
1305 ln -sfT /p/profanity ~/.local/share/profanity
1306 ln -sfT /p/profanity-config ~/.config/profanity
1307 ;;
1308 esac
1309
1310 # template
1311 case $codename in
1312 flidas)
1313 :
1314 ;;
1315 esac
1316
1317 sudo update-alternatives --set pinentry /usr/bin/pinentry-gtk-2
1318
1319
1320 # sakura config is owned by ian
1321 m reset-sakura
1322 m reset-konsole
1323 m sudo -u user2 -i reset-konsole
1324 # user2 xscreensaver we don't want to reset
1325 m reset-xscreensaver
1326
1327
1328 # this would install from cabal for newer / consistent version across os, but it screws up xmonad, so disabled for now.
1329 # this is also in primary-setup
1330 # pi libxss-dev # dependency based on build failure
1331 # cabal update
1332 # cabal install --upgrade-dependencies --force-reinstalls arbtt
1333 # also, i assume syncing this between machines somehow messed up the data.
1334
1335 ## not using arbtt for now
1336 # if mountpoint /p &>/dev/null; then
1337 # case $codename in
1338 # etiona|nabia)
1339 # pi arbtt
1340 # # same as seru enable arbtt, but works over ssh when systemctl --user causes error:
1341 # # Failed to connect to bus: No such file or directory
1342 # lnf -T /a/bin/ds/subdir_files/.config/systemd/user/arbtt.service /home/iank/.config/systemd/user/default.target.wants/arbtt.service
1343 # # allow failure
1344 # seru start arbtt ||:
1345 # ;;
1346 # esac
1347 # fi
1348 rm -fv /home/iank/.config/systemd/user/default.target.wants/arbtt.service
1349
1350
1351 m primary-setup
1352
1353 if [[ ! -e ~/.linphonerc && -e /p/.linphonerc-initial ]]; then
1354 m cp /p/.linphonerc-initial ~/.linphonerc
1355 fi
1356
1357 # linphone in t10 wont do dns with systemd-resolved or something
1358 s teeu /etc/hosts <<'EOF'
1359 74.94.156.215 watson.fsf.org
1360 EOF
1361
1362
1363
1364 ### begin spd install
1365 if mountpoint /p &>/dev/null; then
1366 pi libswitch-perl libdigest-md5-file-perl libgnupg-interface-perl
1367 t=$(mktemp)
1368 m wget -O $t http://mirror.fsf.org/fsfsys-trisquel/fsfsys-trisquel/pool/main/s/spd-perl/spd-perl_0.2-1_amd64.deb
1369 sudo dpkg -i $t
1370 m rm $t
1371 # this guesses at the appropriate directory, adjust if needed
1372 perldir=(/usr/lib/x86_64-linux-gnu/perl/5.*)
1373 m sudo ln -sf ../../../perl/5.18.2/SPD/ ${perldir[0]}
1374 # newer distro had gpg2 as default, older one, flidas, need to make it that way
1375 gpgpath=$(which gpg2) ||:
1376 if [[ $gpgpath ]]; then
1377 sudo mkdir -p /usr/local/spdhackfix
1378 s lnf -T $gpgpath /usr/local/spdhackfix/gpg
1379 fi
1380 fi
1381 ### end spd install
1382
1383
1384 # nagstamon setting which were set through the ui
1385 # monitor url https://klaxon.fsf.org/cgi-bin
1386 # monitor url cgi https://klaxon.fsf.org/cgi-bin
1387 # in filters tab:
1388 # all unknown services
1389 # all warning services
1390 # acknowledged hosts & services
1391 # hosts & services down for maintenence
1392 # services on down hosts
1393 # services on hosts in maintenece
1394 # services on unreachable osts
1395 # hosts in soft state
1396 # services in soft state
1397 # in display tab: fullscreen
1398
1399 # these translate to these settings I think
1400 # filter_acknowledged_hosts_services = True
1401 # filter_all_unknown_services = True
1402 # filter_all_warning_services = True
1403 # filter_hosts_in_soft_state = True
1404 # filter_hosts_services_maintenance = True
1405 # filter_services_in_soft_state = True
1406 # filter_services_on_down_hosts = True
1407 # filter_services_on_hosts_in_maintenance = True
1408 # filter_services_on_unreachable_hosts = True
1409 # notify_if_up = False
1410 # statusbar_floating = False
1411 # fullscreen = True
1412 # but i'm just going to rely on the webpage plus sms for now.
1413
1414
1415 # it asks if it should make users in it's group capture packets without root,
1416 # which is arguably more secure than running wireshark as root. default is no,
1417 # which is what i prefer, since I plan to use tcpdump to input to wireshark.
1418 s DEBIAN_FRONTEND=noninteractive pi wireshark-gtk
1419
1420 # /run and /dev/shm are listed as required for pulseaudio. All 4 in the group
1421 # listed in the default config as suggested.
1422 # /run/usr/1000 i noticed was missing for pulseaudio
1423 # /run/user/0 just seemed like a not bad idea, given the above
1424 tu /etc/schroot/desktop/fstab <<'EOF'
1425 /p /p none rw,bind 0 0
1426 /a /a none rw,bind 0 0
1427 /run /run none rw,bind 0 0
1428 /run/lock /run/lock none rw,bind 0 0
1429 /dev/shm /dev/shm none rw,bind 0 0
1430 /run/shm /run/shm none rw,bind 0 0
1431 /run/user/1000 /run/user/1000 none rw,bind 0 0
1432 /run/user/1001 /run/user/1001 none rw,bind 0 0
1433 /run/user/0 /run/user/0 none rw,bind 0 0
1434 EOF
1435
1436 # todo: consider if this should use the new sysd-prom-fail
1437 sd /etc/systemd/system/schrootupdate.service <<'EOF'
1438 [Unit]
1439 Description=schrootupdate
1440 After=multi-user.target
1441
1442 [Service]
1443 Type=oneshot
1444 ExecStart=/usr/local/bin/sysd-mail-once schrootupdate /a/bin/distro-setup/schrootupdate
1445 EOF
1446 sd /etc/systemd/system/schrootupdate.timer <<'EOF'
1447 [Unit]
1448 Description=schrootupdate
1449
1450 [Timer]
1451 OnCalendar=*-*-* 04:20:00 America/New_York
1452
1453 [Install]
1454 WantedBy=timers.target
1455 EOF
1456 ser daemon-reload
1457 sgo schrootupdate.timer
1458
1459
1460
1461 # for my roommate
1462 case $distro in
1463 trisquel)
1464 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/bullseye.list/BULLSEYE_FREE \
1465 debian bullseye firefox-esr pulseaudio chromium anki
1466 case $(debian-codename) in
1467 etiona|nabia)
1468 # we have a lot of t8 stuff, useful to have
1469 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/flidas.list/FLIDAS \
1470 trisquel flidas
1471 tu /nocow/schroot/flidas/etc/sudoers <<EOF
1472 $USER ALL=(ALL) NOPASSWD: ALL
1473 Defaults env_keep += SUDOD
1474 Defaults always_set_home
1475 Defaults !umask
1476 EOF
1477 sd /nocow/schroot/flidas//etc/locale.gen <<'EOF'
1478 en_US.UTF-8 UTF-8
1479 EOF
1480 s schroot -c flidas locale-gen
1481 s schroot -c flidas update-locale LANG=en_US.UTF-8
1482
1483 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/testing.list/TESTING_NONFREE debian unstable debootstrap
1484 sudo cp -a /nocow/schroot/unstable/usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
1485
1486 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/impish.list/IMPISH ubuntu impish
1487
1488 ;;
1489 esac
1490 ;;
1491 debian)
1492 pi chromium
1493 ;;
1494 esac
1495
1496 sudo mkdir -p /nocow/user
1497 sudo chown $USER:$USER /nocow/user
1498 pi anki
1499
1500
1501 ####### begin transmission
1502
1503 case $HOSTNAME in
1504 frodo)
1505 tdir=/i/k
1506 ;;
1507 kd)
1508 tdir=/d/tor
1509 ;;
1510 *)
1511 tdir=/nocow/user/tor
1512 ;;
1513 esac
1514
1515 sudo mkdir -p $tdir
1516
1517 # adapted from /var/lib/dpkg/info/transmission-daemon.postinst
1518 # 450 seems likely to be unused. we need to specify one or else
1519 # it won't be stable across installs.
1520 if ! getent passwd debian-transmission > /dev/null; then
1521 sudo groupadd -g 450 debian-transmission
1522 sudo adduser --quiet \
1523 --gid 450 \
1524 --uid 450 \
1525 --system \
1526 --no-create-home \
1527 --disabled-password \
1528 --home /var/lib/transmission-daemon \
1529 debian-transmission
1530 fi
1531 # We want group writable stuff from transmission.
1532 # However, after setting this, I learn that transmission sets it's
1533 # own umask based on it's settings file. Well, no harm leaving this
1534 # so it's set right from the beginning.
1535 sudo chfn debian-transmission -o umask=0002
1536
1537 # note i had to do this, which is persistent:
1538 # cd /i/k
1539 # s chgrp debian-transmission torrents partial-torrents
1540
1541 # syslog says things like
1542 # 'Failed to set receive buffer: requested 4194304, got 425984'
1543 # google suggets giving it even more than that
1544 tu /etc/sysctl.conf<<'EOF'
1545 net.core.rmem_max = 67108864
1546 net.core.wmem_max = 16777216
1547 EOF
1548 sudo sysctl -p
1549
1550 # some reason it doesn\'t seem to start automatically anyways
1551 pi-nostart transmission-daemon
1552 # be extra sure its not started
1553 ser disable transmission-daemon
1554 ser stop transmission-daemon
1555
1556 # the folder was moved here after an install around 02/2017.
1557 # it contains runtime data,
1558 # plus a simple symlink to the config file which it\'s
1559 # not worth separating out.
1560 # between comps, the uid can change
1561
1562 f=$tdir/transmission-daemon
1563 for d in $tdir/partial-torrents $tdir/torrents $f; do
1564 if [[ ! -d $d ]]; then
1565 sudo mkdir -p $d
1566 fi
1567 sudo chown -R debian-transmission:user2 $d
1568 done
1569 s lnf -T $f /var/lib/transmission-daemon/.config/transmission-daemon
1570 s lnf -T /etc/transmission-daemon/settings.json $f/settings.json
1571 sudo chown -R debian-transmission:debian-transmission $f
1572 sudo chown -R debian-transmission:debian-transmission /var/lib/transmission-daemon
1573 #
1574 # config file documented here, and it\'s the same config
1575 # for daemon vs client, so it\'s documented in the gui.
1576 # https://trac.transmissionbt.com/wiki/EditConfigFiles#Options
1577 #
1578 # I originaly setup rpc-whitelist, but after using
1579 # routing to a network namespace, it doesn\'t see the
1580 # real source address, so it\'s disabled.
1581 #
1582 # Changed the cache-size to 256 mb, reduces disk use.
1583 # It is a read & write cache.
1584 #
1585 # just fyi: default rpc port is 9091
1586 if ! systemctl is-active transmission-daemon-nn &>/dev/null && \
1587 ! systemctl is-active transmission-daemon; then
1588 tmp=$(mktemp)
1589 command sudo ruby <<EOF >$tmp
1590 require 'json'
1591 p = '/etc/transmission-daemon/settings.json'
1592 s = {
1593 'rpc-whitelist-enabled' => false,
1594 'rpc-authentication-required' => false,
1595 'incomplete-dir' => '$tdir/partial-torrents',
1596 'incomplete-dir-enabled' => true,
1597 'download-dir' => '$tdir/torrents',
1598 "speed-limit-up" => 800,
1599 "speed-limit-up-enabled" => true,
1600 "peer-port" => 61486,
1601 "cache-size-mb" => 256,
1602 "ratio-limit" => 5.0,
1603 "ratio-limit-enabled" => false,
1604 }
1605 puts(JSON.pretty_generate(JSON.parse(File.read(p)).merge(s)))
1606 EOF
1607 cat $tmp | sudo dd of=/etc/transmission-daemon/settings.json
1608
1609 fi
1610
1611 ####### end transmission
1612
1613 case $HOSTNAME in
1614 kd)
1615 # to persist upload/dl metadata. initially, moved all the stuff
1616 # in /var/lib/transmission-daemon to /d/tor
1617 s usermod --home /d/tor debian-transmission
1618 sgo transmission-daemon-nn
1619
1620 ;;
1621 esac
1622
1623
1624 ######### begin transmission client setup ######
1625
1626 # to connect from a remote client, trans-remote-route in brc2
1627
1628
1629 if [[ -e /p/transmission-rpc-pass ]]; then
1630 # arch had a default config,
1631 # debian had nothing until you start it.
1632 # With a little trial an error, here is a minimal config
1633 # taken from the generated one, plus changes that the
1634 # settings ui does, without a bunch of ui crap settings.
1635 #
1636 # only settings I set were
1637 # hostname
1638 # auto-connect
1639 # password
1640
1641 # the password is randomly generated on first run, i copied it out
1642 # so it could be used by other hosts.
1643 sudo ruby <<'EOF'
1644 require 'json'
1645 p = '/etc/transmission-daemon/settings.json'
1646 s = JSON.parse(File.read(p))
1647 s["rpc-password"] = File.read("/p/transmission-rpc-pass").chomp
1648 # default is 0022 (18 in decimal)
1649 s["umask"] = 2
1650 File.write p, JSON.pretty_generate(s)
1651 EOF
1652
1653 rpc_pass=$(</p/transmission-rpc-pass)
1654 for f in /home/*; do
1655 u=${f##*/}
1656 uid=$(id -u $u 2>/dev/null) || continue
1657 if [[ ! $uid -ge 1000 ]]; then
1658 continue
1659 fi
1660 d=$f/.config/transmission-remote-gtk
1661 sudo -u $u mkdir -p $d
1662 # i tried setting hostname to transmission.b8.nz, so i could dynamically change where
1663 # this connects to, but it said some 421 denied error when I did that. Then it
1664 # froze X when i ran it under strace. Whatever.
1665 sudo -u $u dd of=$d/config.json <<EOF
1666 {
1667 "profiles" : [
1668 {
1669 "profile-name" : "Default",
1670 "hostname" : "10.174.2.2",
1671 "rpc-url-path" : "/transmission/rpc",
1672 "username" : "",
1673 "password" : "$rpc_pass",
1674 "auto-connect" : true,
1675 "ssl" : false,
1676 "timeout" : 40,
1677 "retries" : 3,
1678 "update-active-only" : false,
1679 "activeonly-fullsync-enabled" : false,
1680 "activeonly-fullsync-every" : 2,
1681 "update-interval" : 3,
1682 "min-update-interval" : 3,
1683 "session-update-interval" : 60,
1684 "exec-commands" : [],
1685 "destinations" : []
1686 }
1687 ],
1688 "profile-id" : 0,
1689 "add-options-dialog" : false
1690 }
1691 EOF
1692 done
1693 fi
1694 ######### end transmission client setup ######
1695
1696
1697 ### printer setup
1698 pi cups
1699
1700 sudo gpasswd -a $USER lpadmin # based on ubuntu wiki
1701 # goto http://127.0.0.1:631
1702 # administration tab, add new printer button.
1703 # In debian, I could use hte recommended driver,
1704 # in arch, I had to pick out the 6L driver.
1705
1706
1707 # bridge networking as user fails. google lead here, but it doesn\'t work:
1708 # oh well, I give up.
1709 # http://wiki.qemu.org/Features-Done/HelperNetworking
1710 # s mkdir /etc/qemu
1711 # f=/etc/qemu/bridge.conf
1712 # sd $f <<'EOF'
1713 # allow br0
1714 # EOF
1715 # #s chown root:qemu $f # debian has somethig like qemu-libvirt. equivalent?
1716 # s chmod 640 $f
1717
1718 # general known for debian/ubuntu, not for fedora
1719
1720 m /a/bin/buildscripts/go
1721 # only needed for rg. cargo takes up 11 gigs, filled up the disk on je.
1722 m /a/bin/buildscripts/rust
1723 m /a/bin/buildscripts/misc
1724 m /a/bin/buildscripts/pithosfly
1725 #m /a/bin/buildscripts/alacritty
1726 #m /a/bin/buildscripts/kitty
1727
1728 pi-nostart virtinst virt-manager
1729 soff libvirtd
1730 # i cant if this is whats causing it to start even though
1731 # its disabled. note: it leaves around dnsmasq instances even
1732 # if you stop it. what the hell systemd?
1733 soff libvirt-guests
1734 # allow user to run vms, from debian handbook. libvirt-qemu
1735 # based on https://www.whonix.org/wiki/KVM#First-time_User.3F
1736 for x in iank user2; do s usermod -a -G libvirt,kvm,libvirt-qemu $x; done
1737
1738
1739 pi --no-install-recommends kdeconnect
1740 ### kdeconnect for gnome. started in /a/bin/distro-setup/desktop-20-autostart.sh
1741 ### but gnome + xmonad not working in flidas, so i disabled it
1742 # pi libgtk-3-dev python3-requests-oauthlib valac cmake python-nautilus libappindicator3-dev
1743 # cd /a/opt/indicator-kdeconnect
1744 # mkdir -p build
1745 # cd build
1746 # cmake .. -DCMAKE_INSTALL_PREFIX=/usr
1747 # make
1748 # sudo make install
1749 # # we can start it manually with /usr/lib/x86_64-linux-gnu/libexec/kdeconnectd
1750 # # it seems, according to
1751 # # /etc/xdg/autostart/kdeconnectd.desktop
1752 # # I'm not seeing the icon, but the clipboard replication is working
1753
1754
1755 ### begin model 01 arduino support ###
1756 # https://github.com/keyboardio/Kaleidoscope/wiki/Install-Arduino-support-on-Linux
1757 # also built latest arduino in /a/opt/Arduino, (just cd build; ant build; ant run )
1758 # set arduino var in bashrc,
1759 # have system config file setup too.
1760 sudo adduser $USER dialout
1761
1762 # as of 2022-05,
1763 # download arduino ide, extract in /a/opt, ignore the install script, run ./arduino,
1764 # toolbar, preferences, add board manager url:
1765 # https://raw.githubusercontent.com/keyboardio/boardsmanager/master/package_keyboardio_index.json
1766 # toolbar, board manager, add keyboardio
1767 # toolbar, select model01 board
1768 # toolbar, examples, model01, compile
1769
1770 ###
1771
1772 # this is for the mail command too. update-alternatives is kind of misleading
1773 # since at least it's main commands pretend mail does not exist.
1774 # bsd's mail got pulled in on some dumb dependency, i dunno how.
1775 sudo update-alternatives --set mailx /usr/bin/mail.mailutils
1776
1777 ######### end misc packages #########
1778
1779
1780 # packages I once used before and liked, but don\'t want installed now for
1781 # various reasons:
1782 # python-sqlite is used for offlineimap
1783 # lxappearance python-sqlite dolphin paman dconf-editor
1784
1785
1786
1787 ######## unfinished
1788
1789 # todo, finish configuring smart.
1790
1791 pi smartmontools
1792 # mostly from https://wiki.archlinux.org/index.php/S.M.A.R.T.
1793 # turn on smart. background on options:
1794 # first line, -a = test everyting on all devices.
1795 # -S on, turn on disk internal saving of vendor specific info,
1796 # from google, seems like this is usually already on and fairly standard.
1797 # -o on, turn on 4 hour period non-performance degrading testing.
1798 # short test daily 2-3am, extended tests Saturdays between 3-4am:
1799 sched="-s (S/../.././02|L/../../6/03)"
1800 sudo sed -i --follow-symlinks "s#^[[:space:]]*DEVICESCAN.*#\
1801 DEVICESCAN -a -o on -S on -n standby,q $sched \
1802 -m root@mail.iankelling.org -M exec /usr/local/bin/smart-notify#" /etc/smartd.conf
1803
1804 # in the default configuration of at least ubuntu 14.04, resolvconf is
1805 # configured to order any nameservers associated with tun* or tap*
1806 # before the normal internet interfaces, which means they are always
1807 # consulted first. This is often slower and undesirable, ie. local dns
1808 # queries go from 0ms to 10+ or 100+ ms. To reverse the ordering, you
1809 # can do:
1810 #sudo sed -i --follow-symlinks '/tun\*\|tap\*/d' /etc/resolvconf/interface-order
1811 # however, this breaks dns lookup for hosts on the openvpn lan.
1812 # I can\'t figure out why hosts on the normal lan would not be
1813 # broken under the default ordering, except the host I was
1814 # testing with previously had an entry in /etc/hosts.
1815
1816 ############# end unfinished
1817
1818 ########### misc stuff
1819
1820 # pressing tab after sdf here:
1821 # scp sdfbash: set +o noglob: command not found
1822 # in t11, bash 5.1.16. this fixes it.
1823 sudo sed -ri 's/([[:space:]]*)(\$reset)$/\1set +o noglob #$reset/' /usr/share/bash-completion/bash_completion
1824
1825 rm -fv /home/iank/.mpv/watch_later
1826 rm -rf /home/iank/.mpv
1827
1828 if [[ ! -e ~/.local/bin/pip ]]; then
1829 tmp=$(mktemp)
1830 wget -O$tmp https://bootstrap.pypa.io/get-pip.py
1831 python3 $tmp --user
1832 hash -r
1833 fi
1834
1835 ## begin beets
1836 # soo, apt install beets fails due to wanting a pip package,
1837 # we find out why it wants this through
1838 # apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances beets | less
1839 # python-mediafile requires tox, which requires virtualenv, which requires pip.
1840 # but, python-mediafile doesn't really require tox, it is specified in
1841 # ./usr/lib/python3/dist-packages/mediafile-0.9.0.dist-info/METADATA
1842 # as being required only for testing, but the debian package
1843 # included it anyways, due to a mistake or bad tooling or something.
1844 # I don't plan to use tox, so, according to https://serverfault.com/a/251091,
1845 # we can create and install a dummy package by:
1846 #
1847 # "equivs-control <name>, edit the file produced to provide the right
1848 # dependency and have a nice name, then run equivs-build <name> and
1849 # finally dpkg -i the resulting .deb file"
1850 # as of 2023-02, the tox dependency was removed in debian unstable, so
1851 # this hack will probably go away in t12.
1852
1853 if pcheck beets; then
1854 tmpdir="$(mktemp -d)"
1855 cd "$tmpdir"
1856 # edited from output of equivs-control tox
1857 cat >tox <<'EOF'
1858 Section: python
1859 Priority: optional
1860 Standards-Version: 3.9.2
1861 Package: tox
1862 Description: tox-dummy
1863 EOF
1864 equivs-build tox
1865 sudo dpkg -i tox_1.0_all.deb
1866 rm -rf ./tox*
1867 pi beets python3-discogs-client
1868 cd
1869 rm -r "$tmpdir"
1870 fi
1871
1872 # get rid of annoying message
1873 s sed -ri "s/^([[:space:]]*ui.print_\('Playing)/#\1/" /usr/share/beets/beetsplug/play.py
1874
1875
1876 # notes about barrier
1877 # run barrier, do the gui config,
1878 # setup the 2 screens, using hostnames for the new screen.
1879 # save the server config
1880 # $HOME/.local/share/barrier/.barrier.conf
1881 # per the man page.
1882 #
1883 # ssl errors, resolved via advice here: https://github.com/debauchee/barrier/issues/231
1884 # BARRIER_SSL_PATH=~/.local/share/barrier/SSL/
1885 # mkdir -p "${BARRIER_SSL_PATH}"
1886 # openssl req -x509 -nodes -days 365 -subj /CN=Barrier -newkey rsa:4096 -keyout ${BARRIER_SSL_PATH}/Barrier.pem -out ${BARRIER_SSL_PATH}/Barrier.pem
1887 # ran on both machines.
1888 # When pressing start in the gui, the cli options used are printed to the console,
1889 # they are useful. So on server, just run barriers, client run barrierc SERVER_IP
1890
1891 ### begin timetrap setup
1892 if mountpoint /p &>/dev/null; then
1893 mkdir -p ~/.timetrap/
1894 ln -sf /a/opt/timetrap_formatters ~/.timetrap/formatters
1895 if ! type -p t &>/dev/null; then
1896 pi ruby-dev libsqlite3-dev
1897 gem install --user timetrap
1898 fi
1899 fi
1900 ### end timetrap setup
1901
1902 # leftover cleanup for t9
1903 pu resolvconf
1904
1905 case $codename in
1906 # needed for debootstrap scripts for fai since fai requires debian
1907 flidas)
1908 pi dnsmasq
1909 pi-nostart network-manager
1910 # i hate networkmanager. noo, of course disabling it doesnt work
1911 # unless you add a hack. found this by doing
1912 # systemd-analyze dot > x.dot
1913 # less x.dot
1914 # /networkman
1915 soff NetworkManager
1916 soff NetworkManager-wait-online.service
1917 # make networkmanager use resolvconf instead of its own dnsmasq which
1918 # conflicts with the normal dnsmasq package.
1919 f=/etc/NetworkManager/NetworkManager.conf
1920 m=$(md5sum $f)
1921 sudo sed -ri '/ *\[main\]/,/^ *\[[^]]+\]/{/^\s*dns[[:space:]=]/d}' $f
1922 sudo sed -ri '/ *\[main\]/a dns=default' $f
1923 if [[ $m != $(md5sum $f) ]]; then
1924 srestart NetworkManager
1925 fi
1926 # networkmanager has this nasty behavior on flidas: if the machine
1927 # crashes with dnsmasq running, on subsequent boot, it adds an entry to
1928 # resolvconf for 127.0.0.1 in some stupid attempt to restore
1929 # nameservers.
1930 # This can be manually fixed by stoping dnsmasq,
1931 # then based on whats in /run/dnsmasq/, i see we can run
1932 # s resolvconf -d NetworkManager
1933 # oh ya, and stoping NetworkManager leaves this crap behind without cleaning it up.
1934 ser disable NetworkManager
1935 ;;
1936 esac
1937
1938 # I have no use for avahi,
1939 # had to run this twice when doing manually, i dunno why
1940 soff avahi-daemon ||:
1941 sleep 1
1942 soff avahi-daemon
1943
1944 # make my /etc/fonts/conf.d/ get used.
1945 # I have a new sans-serif font there because the default one
1946 # displays l and I as the same char, grrrrr.
1947 sudo fc-cache
1948
1949 pi desktop-file-utils
1950 m /a/bin/distro-setup/mymimes
1951
1952 if type -p dbus-launch >/dev/null; then
1953 # stop autopoping windows when i plug in an android phone.
1954 # dbus-launch makes this work within an ssh connection, otherwise you get this message,
1955 # with still 0 exit code.
1956 # dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
1957 m dbus-launch gsettings set org.gnome.desktop.media-handling automount-open false
1958 fi
1959
1960 # on grub upgrade, we get prompts unless we do this
1961 devs=()
1962 for dev in $(s btrfs fil show /boot | sed -nr 's#.*path\s+(\S+)$#\1#p'); do
1963 devs+=("$(devbyid $dev),")
1964 done
1965 devs[-1]=${devs[-1]%,} # jonied by commas
1966 sudo debconf-set-selections <<EOF
1967 grub-pc grub-pc/install_devices multiselect ${devs[*]}
1968 EOF
1969
1970
1971 sysd-prom-fail-install dynamicipupdate
1972 sysd-prom-fail-install systemstatus
1973 sysd-prom-fail-install btrfsmaintstop
1974 sgo btrfsmaint.timer
1975 sgo btrfsmaintstop
1976 sgo systemstatus
1977 sgo dynamicipupdate
1978
1979
1980 if grep -xFq $HOSTNAME /a/bin/ds/machine_specific/btrbk.hosts; then
1981 sgo btrbk.timer
1982 fi
1983
1984 # note: to see when a timer was last run,
1985 # ser list-timers
1986
1987
1988 ### begin prometheus ###
1989
1990 case $HOSTNAME in
1991 kd)
1992 # Font awesome is needed for the alertmanager ui.
1993 pi prometheus-alertmanager prometheus fonts-font-awesome
1994 /c/roles/prom/files/simple/usr/local/bin/fsf-install-prometheus
1995 # make it available for other machines
1996 rsync -a /usr/local/bin/amtool /a/opt/bin
1997 web-conf -p 9091 -f 9090 - apache2 i.b8.nz <<'EOF'
1998 <Location "/">
1999 AuthType Basic
2000 AuthName "basic_auth"
2001 # created with
2002 # htpasswd -c prometheus-htpasswd USERNAME
2003 AuthUserFile "/etc/prometheus-htpasswd"
2004 Require valid-user
2005 </Location>
2006 EOF
2007
2008 web-conf -p 9094 -f 9093 - apache2 i.b8.nz <<'EOF'
2009 <Location "/">
2010 AuthType Basic
2011 AuthName "basic_auth"
2012 # created with
2013 # htpasswd -c prometheus-htpasswd USERNAME
2014 AuthUserFile "/etc/prometheus-htpasswd"
2015 Require valid-user
2016 </Location>
2017 EOF
2018
2019 # by default, the alertmanager web ui is not enabled other than a page
2020 # that suggests to use the amtool cli. that tool is good, but you cant
2021 # silence things nearly as easily as with the gui.
2022 if [[ ! -e /usr/share/prometheus/alertmanager/ui/index.html ]]; then
2023 # default script didnt work, required some changes to get elm 19.1,
2024 # which is a dependency of the latest alertmanager. I modified
2025 # and copied it into /b/ds. In future, might need some other
2026 # solution.
2027 #sudo /usr/share/prometheus/alertmanager/generate-ui.sh
2028 sudo /b/ds/generate-ui.sh
2029 ser restart prometheus-alertmanager
2030 fi
2031
2032 s /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter -l 127.0.0.1
2033
2034 for ser in prometheus-node-exporter prometheus-alertmanager prometheus; do
2035 sysd-prom-fail-install $ser
2036 done
2037
2038 ;;
2039 *)
2040 s /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter
2041 ;;
2042 esac
2043
2044 # cleanup old files. 2023-02
2045 x=(/var/lib/prometheus/node-exporter/*.premerge)
2046 if [[ -e ${x[0]} ]]; then
2047 s rm /var/lib/prometheus/node-exporter/*
2048 fi
2049
2050
2051 case $HOSTNAME in
2052 # todo, for limiting node exporter http,
2053 # either use iptables or, in
2054 # /etc/default/prometheus-node-exporter
2055 # listen on the wireguard interface
2056
2057 *)
2058 wgip=$(command sudo sed -rn 's,^ *Address *= *([^/]+).*,\1,p' /etc/wireguard/wghole.conf)
2059 # old filename. remove once all hosts are updated.
2060 s rm -fv /etc/apache2/sites-enabled/${HOSTNAME}wg.b8.nz.conf
2061 web-conf -i -a $wgip -p 9101 -f 9100 - apache2 ${HOSTNAME}wg.b8.nz <<'EOF'
2062 <Location "/">
2063 AuthType Basic
2064 AuthName "basic_auth"
2065 # created with
2066 # htpasswd -c prometheus-export-htpasswd USERNAME
2067 AuthUserFile "/etc/prometheus-export-htpasswd"
2068 Require valid-user
2069 </Location>
2070 EOF
2071 # For work, i think we will just use the firewall for hosts in the main data center, and
2072 # vpn for hosts outside it.
2073
2074 # TODO: figure out how to detect the ping failure and try again.
2075
2076 # Binding to the wg interface, it might go down, so always restart, and wait for it on boot.
2077 s mkdir /etc/systemd/system/apache2.service.d
2078 sd /etc/systemd/system/apache2.service.d/restart.conf <<EOF
2079 [Unit]
2080 After=wg-quick@wghole.service
2081 StartLimitIntervalSec=0
2082
2083 [Service]
2084 Restart=always
2085 RestartSec=30
2086 EOF
2087
2088 ;;
2089 esac
2090
2091 ### end prometheus ###
2092
2093 ### begin nagios ###
2094
2095 pi nagios-nrpe-server
2096
2097 case $HOSTNAME in
2098 kd)
2099 # the backport is for this bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=800345
2100 pi nagios4 nagios-nrpe-plugin monitoring-plugins-basic/bullseye-backports
2101 s rm -fv /etc/apache2/conf-enabled/nagios4-cgi.conf
2102
2103 # to add a password for admin:
2104 # htdigest /etc/nagios4/htdigest.users Nagios4 iank
2105 # now using the same pass as prometheus
2106
2107 # nagstamon auth settings, set to digest instead of basic.
2108
2109 web-conf -p 3005 - apache2 i.b8.nz <<'EOF'
2110 # adapted from /etc/apache2/conf-enabled/nagios4-cgi.conf
2111
2112 ScriptAlias /cgi-bin/nagios4 /usr/lib/cgi-bin/nagios4
2113 ScriptAlias /nagios4/cgi-bin /usr/lib/cgi-bin/nagios4
2114
2115 # Where the stylesheets (config files) reside
2116 Alias /nagios4/stylesheets /etc/nagios4/stylesheets
2117
2118 # Where the HTML pages live
2119 Alias /nagios4 /usr/share/nagios4/htdocs
2120
2121 <DirectoryMatch (/usr/share/nagios4/htdocs|/usr/lib/cgi-bin/nagios4|/etc/nagios4/stylesheets)>
2122 Options FollowSymLinks
2123 DirectoryIndex index.php index.html
2124 AllowOverride AuthConfig
2125 #
2126 # The default Debian nagios4 install sets use_authentication=0 in
2127 # /etc/nagios4/cgi.cfg, which turns off nagos's internal authentication.
2128 # This is insecure. As a compromise this default apache2 configuration
2129 # only allows private IP addresses access.
2130 #
2131 # The <Files>...</Files> below shows how you can secure the nagios4
2132 # web site so anybody can view it, but only authenticated users can issue
2133 # commands (such as silence notifications). To do that replace the
2134 # "Require all granted" with "Require valid-user", and use htdigest
2135 # program from the apache2-utils package to add users to
2136 # /etc/nagios4/htdigest.users.
2137 #
2138 # A step up is to insist all users validate themselves by moving
2139 # the stanza's in the <Files>..<Files> into the <DirectoryMatch>.
2140 # Then by setting use_authentication=1 in /etc/nagios4/cgi.cfg you
2141 # can configure which people get to see a particular service from
2142 # within the nagios configuration.
2143 #
2144 AuthDigestDomain "Nagios4"
2145 AuthDigestProvider file
2146 AuthUserFile "/etc/nagios4-htdigest.users"
2147 AuthGroupFile "/etc/group"
2148 AuthName "Nagios4"
2149 AuthType Digest
2150 Require valid-user
2151 </DirectoryMatch>
2152
2153 <Directory /usr/share/nagios4/htdocs>
2154 Options +ExecCGI
2155 </Directory>
2156 EOF
2157 ;;
2158 esac
2159
2160 # when you alter a service through the web, it changes vars in /var/lib/nagios4/status.dat. for example:
2161 # notifications_enabled=1
2162 # note, the same variable exists in the correspdonding "define service {"
2163
2164 # in the default config, we have these definitions
2165
2166 # 11 define command {
2167 # 2 define contact {
2168 # 1 define contactgroup {
2169 # 9 define host {
2170 # 4 define hostgroup {
2171 # 23 define service {
2172 # 5 define timeperiod {
2173
2174
2175 # on klaxon
2176
2177 # klaxon:/etc/nagios3 # grep -rho '^ *define [^{ ]*' | sort | uniq -c
2178 # 76 define command
2179 # 11 define contact
2180 # 6 define contactgroup
2181 # 162 define host
2182 # 1 define hostextinfo
2183 # 16 define hostgroup
2184 # 3040 define service
2185 # 2 define servicedependency
2186 # 6 define timeperiod
2187
2188
2189
2190
2191 ### end nagios ###
2192
2193 ### begin bitcoin ###
2194
2195 case $HOSTNAME in
2196 sy|kd)
2197 sudo install -m 0755 -o root -g root -t /usr/bin /a/opt/bitcoin-24.0.1/bin/*
2198 sgo bitcoind
2199 # note: the bitcoin user & group are setup in fai
2200 sudo usermod -a -G bitcoin iank
2201 # todo: make bitcoin have a stable uid/gid
2202 if [[ ! $(readlink -f /var/lib/bitcoind/wallets) == /q/wallets ]]; then
2203 mkdir -p /var/lib/bitcoind
2204 chown bitcoin:bitcoin /var/lib/bitcoind
2205 # 710 comes from the upstream bitcoin unit file
2206 chmod 710 /var/lib/bitcoind
2207 s lnf /q/wallets /var/lib/bitcoind
2208 sudo chown -h bitcoin:bitcoin /var/lib/bitcoind/wallets
2209 fi
2210 # note, there exists
2211 # /a/bin/ds/disabled/bitcoin
2212 ;;
2213 esac
2214
2215 ### end bitcoin
2216
2217 case $HOSTNAME in
2218 kw|x3)
2219 sd /etc/cups/client.conf <<'EOF'
2220 ServerName printserver1.office.fsf.org
2221 EOF
2222 ;;
2223 esac
2224
2225
2226 end_msg <<'EOF'
2227 In mate settings settings, change scrolling to two-finger,
2228 because the default edge scroll doesn\'t work. Originally found this in debian.
2229 EOF
2230
2231 # Remove dep that came in with desktop to fix associations.
2232 m pu transmission-gtk
2233
2234 case $HOSTNAME in
2235 kd)
2236 lnf -T /d/vidshare /home/iank/Videos
2237 ;;
2238 esac
2239
2240 # # Based on guix manual instructions, also added code to profile.
2241 # # disabled since i'm not using it now.
2242 # pi nscd
2243 # if ! type -p guix >/dev/null; then
2244 # cd $(mktemp -d)
2245 # wget https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
2246 # # added some stuff to envonment.sh for profile based on
2247 # # manual instructions
2248 # # wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -
2249 # # echo is to get past prompt
2250 # yes | sudo -E HOME=$HOME bash guix-install.sh || [[ $? == 141 ]]
2251 # guix install glibc-utf8-locales
2252 # guix package --install guile
2253 # fi
2254
2255 lnf -T /a/opt ~/src
2256
2257 pi tor
2258 m /a/bin/buildscripts/tor-browser
2259 # one root command needed to install
2260 s ln -sf /a/opt/tor-browser/Browser/start-tor-browser /usr/local/bin
2261
2262
2263 # nfs server
2264 pi-nostart nfs-kernel-server
2265
2266 # todo, this is old, probably needs removing
2267 if [[ $HOSTNAME == tp ]]; then
2268 sd /etc/wireguard/wg0.conf <<EOF
2269 [Interface]
2270 PrivateKey = $(cat /p/c/machine_specific/tp/filesystem/root/wg.key)
2271 Address = 10.3.0.2/24, fdfd::2/64
2272
2273 [Peer]
2274 PresharedKey = $(cat /p/c/machine_specific/tp/filesystem/root/wg.psk)
2275 PublicKey = 9RnAsJB+ISrA/9lmDKBoT08oBiKwzA64exBBj+rO+ng=
2276 Endpoint = b8.nz:26000
2277 AllowedIPs = 10.3.0.1/24, fdfd::1/64
2278 PersistentKeepalive = 20
2279 EOF
2280 sudo systemctl enable wg-quick@wg0
2281 sudo systemctl start wg-quick@wg0
2282 fi
2283
2284
2285 if [[ $HOSTNAME == kw ]]; then
2286 # hosts 1-199. 200+ are dynamic, avoid those
2287 tu /etc/exports <<'EOF'
2288 /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)
2289 /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)
2290 EOF
2291 ekw
2292 sgo nfs-server
2293 sudo exportfs -rav
2294 fi
2295
2296
2297 # if I was going to create a persistent vm, i might do it like this:
2298 # variant=something # from: virt-install --os-variant list
2299 # s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
2300 # --disk=/a/images/some_name.qcow2,bus=virtio --vcpus 2 -r 4096 -w bridge=br0 \
2301 # -n some_name --import --os-variant $variant --cpu host-model-only
2302
2303
2304 # for brother HL-2270DW, this worked:
2305 # https://askubuntu.com/questions/1067234/cant-use-wireless-brother-printer-2270dw-ubuntu-18-04
2306 # /a/opt/linux-brprinter-installer-2.2.2-1
2307 # answer n when it asks about uri.
2308 # Then go to cups, delete the existing printer, added on with dnssd url. browsed to
2309 # ppd at /usr/share/ppd/HL2270DW.ppd, which is duplicated at /usr/share/cups/model/HL2270DW.ppd
2310 # ppd file got installed from bash -x ./usr/local/Brother/Printer/HL2270DW/cupswrapper/cupswrap,
2311 # which I downloaded from their driver. but dont do that again, i copied it to /a/opt/HL2270DW.ppd,
2312 # use that.
2313
2314 # 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.
2315 # Then it was already configured, but if i needed to, go to its web ui, default pass is "access".
2316
2317 ######### begin stuff belonging at the end ##########
2318
2319 end