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