lots of updates, server support in progress
[distro-setup] / distro-end
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
4 set -eE -o pipefail
5 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
6
7 set -x
8
9 exec &> >(sudo tee -a /var/log/distro-end)
10 echo "$0: $(date): starting now)"
11
12 src="${BASH_SOURCE%/*}"
13
14 end_msg() {
15 = local y
16 IFS= read -r -d '' y ||:
17 end_msg_var+="$y"
18 }
19
20 spa() { # simple package add
21 simple_packages+=($@)
22 }
23
24 distro=$(distro-name)
25
26 pending_reboot=false
27
28 # template
29 case $distro in
30 esac
31
32 pup
33
34 simple_packages=(
35 mailutils
36 nmon
37 ruby
38 ruby-rest-client
39 tree
40 vim
41 )
42
43 if [[ $HOSTNAME != lj && $HOSTNAME != lk ]]; then
44 # universal packages
45 simple_packages+=(
46 apache2
47 bwm-ng
48 chromium
49 duplicity
50 evince
51 fdupes
52 filelight
53 gdb
54 gnome-screenshot
55 jq
56 locate
57 meld
58 offlineimap
59 p7zip
60 paprefs
61 pavucontrol
62 pdfgrep
63 pianobar
64 pidgin
65 rdiff-backup
66 slock
67 squashfs-tools
68 tcpdump
69 transmission-remote-gtk
70 vlc
71 )
72 fi
73
74
75
76 ########### begin section including lj ################
77
78
79 case $distro in
80 fedora) spa unrar ;;
81 *) spa unrar-free ;;
82 esac
83
84
85 case $distro in
86 arch)
87 # ubuntu 14.04 uses b-cron,
88 # but its not maintained in arch.
89 # of the ones in the main repos, cronie is only one maintained.
90 # fcron appears abandoned software.
91 pi cronie
92 sgo cronie
93 ;;
94 *) : ;; # other distros come with cron.
95 esac
96
97
98 case $distro in
99 debian|ubuntu)
100 pi debian-goodies
101 ;;
102 esac
103
104
105 case $distro in
106 *) pi at ;;&
107 arch) sgo atd ;;
108 esac
109
110
111 case $distro in
112 debian) pi curl;;
113 arch) : ;;
114 # fedora: unknown
115 esac
116
117 case $distro in
118 # tk for gitk
119 arch) spa git tk ;;
120 *) spa git ;;
121 esac
122
123 case $distro in
124 arch) spa the_silver_searcher ;;
125 debian|ubuntu) spa silversearcher-ag ;;
126 # fedora unknown
127 esac
128
129 case $distro in
130 debian|ubuntu) spa ntp;;
131 arch)
132 pi ntp
133 sgo ntpd
134 ;;
135 # others unknown
136 esac
137
138
139 # no equivalent in other distros:
140 case $distro in
141 debian|ubuntu)
142 pi apt-file aptitude
143 s apt-file update
144 # for debconf-get-selections
145 spa debconf-utils
146 ;;
147 esac
148
149 case $distro in
150 ubuntu|debian) spa ack-grep ;;
151 arch|fedora) spa ack ;;
152 # fedora unknown
153 esac
154
155 case $distro in
156 arch|debian|ubuntu)
157 spa bash-completion
158 ;;
159 # others unknown
160 esac
161
162
163
164
165
166 # disable motd junk.
167 case $(distro-name) in
168 debian)
169 # allows me to pipe with ssh -t, and gets rid of spam
170 # http://forums.debian.net/viewtopic.php?f=5&t=85822
171 # i'd rather disable the service than comment the init file
172 # this says disabling the service, it will still get restarted
173 # but this script doesn't do anything on restart, so it should be fine
174 s dd of=/var/run/motd.dynamic if=/dev/null
175 s update-rc.d motd disable
176 ;;
177 ubuntu)
178 # this isn't a complete solution. It still shows me when updates are available,
179 # but it's no big deal.
180 s t /etc/update-motd.d/10-help-text /etc/update-motd.d/00-header
181 ;;
182 esac
183
184 # automatic updates
185 # reference:
186 # https://debian-handbook.info/browse/stable/sect.regular-upgrades.html
187 # /etc/cron.daily/apt calls unattended-upgrades
188 # /usr/share/doc/unattended-upgrades# cat README.md
189 # /etc/apt/apt.conf.d/50unattended-upgrades
190 if isdebian; then
191 pi unattended-upgrades
192 s dd of=/etc/apt/apt.conf.d/10periodic <<'EOF'
193 # this file was mostly just comments.
194 APT::Periodic::Update-Package-Lists "1";
195 APT::Periodic::Download-Upgradeable-Packages "1";
196 APT::Periodic::AutocleanInterval "7";
197 APT::Periodic::Unattended-Upgrade "1";
198 EOF
199
200
201 { cat <<'EOF'
202 Unattended-Upgrade::Mail "root";
203 Unattended-Upgrade::MailOnlyOnError "true";
204 Unattended-Upgrade::Remove-Unused-Dependencies "true";
205 Unattended-Upgrade::Origins-Pattern {
206 # default is just upgrade main and security, not updates.
207 EOF
208 if isdebian-testing; then
209 cat <<'EOF'
210 # for testing, only do security updates.
211 "origin=Debian,codename=${distro_codename},label=Debian-Security";
212 EOF
213 else
214 cat <<'EOF'
215 # These are stable packages only getting bugfixes anyways.
216 "origin=*";
217 EOF
218 fi
219 cat <<'EOF'
220 };
221 EOF
222 } | s dd of=/etc/apt/apt.conf.d/50unattended-upgrades
223
224
225 echo $- > /tmp/x
226 fi
227
228 # cron
229 /a/bin/crons/all
230
231
232 case $HOSTNAME in
233 lj|lk)
234
235 pi "${simple_packages[@]}"
236 $src/homepage-setup
237 $src/
238
239 # start=' *<source lang="bash"> *'
240 # end=' *<\/source> *'
241 # ruby <<'EOF' | sed -rn "/^$start$/,/^$end$/{s/^$start|$end$/# \0/;p}" | bash
242 # require 'json'
243 # puts JSON.parse(`curl 'https://ofswiki.org/w/api.php?\
244 # action=query&titles=Mediawiki_Setup_Guide&prop=revisions&rvprop=content&\
245 # format=json'`.chomp)['query']['pages'].values[0]['revisions'][0]['*']
246 # EOF
247 # nginx-site iankelling.org
248
249 echo "$0: $(date): ending now)"
250 exit 0
251 ;;
252 esac
253
254 ########### end section including lj ###############
255
256
257 case $distro in
258 arch) pi syncthing ;;
259 ubuntu|debian)
260 # google led me here:
261 # https://apt.syncthing.net/
262 curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
263 s="deb http://apt.syncthing.net/ syncthing release"
264 if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != $s ]]; then
265 echo "$s" | s dd of=/etc/apt/sources.list.d/syncthing.list
266 p update
267 fi
268 pi syncthing
269 ;;
270 esac
271 # installed via f-droid
272 # top right, actions, device id
273 #
274 # for installing on a remote comp:
275 # ssh -L 8384:localhost:8384 -N frodo
276 # went to http://localhost:8384/
277 #
278 # add folder to sync phone,
279 # staggered file versioning would be my normal choice, but choose
280 # trash can versioning for sake of space on phone, with
281 # clean out after 7 days.
282 #
283 # did ser syncthing@ian start
284 # then on phone, add device, hit bar code icon,
285 # install bar code scanner.
286
287
288 # no equivalent in other distros:
289 case $distro in
290 debian|ubuntu)
291 # for gui bug reporting
292 spa python-vte
293 ;;
294 esac
295
296
297 ####### misc packages ###########
298
299
300 if [[ $HOSTNAME == frodo ]]; then
301 case $distro in
302 debian|ubuntu)
303 # note i had to do this, which is persistent:
304 # cd /i/k
305 # s chgrp debian-transmission torrents partial-torrents
306
307 # syslog says things like
308 # 'Failed to set receive buffer: requested 4194304, got 425984'
309 # google suggets giving it even more than that
310 tu /etc/sysctl.conf<<'EOF'
311 net.core.rmem_max = 67108864
312 net.core.wmem_max = 16777216
313 EOF
314 s sysctl -p
315
316 # some reason it doesn't seem to start automatically anyways
317 pi-nostart transmission-daemon
318 # config file documented here, and it's the same config
319 # for daemon vs client, so it's documented in the gui.
320 # https://trac.transmissionbt.com/wiki/EditConfigFiles#Options
321 s ruby <<'EOF'
322 require 'json'
323 p = '/etc/transmission-daemon/settings.json'
324 File.write(p, JSON.pretty_generate(JSON.parse(File.read(p)).merge({
325 'rpc-whitelist' => '127.0.0.1,192.168.1.*',
326 'rpc-authentication-required' => false,
327 'incomplete-dir' => '/i/k/partial-torrents',
328 'download-dir' => '/i/k/torrents',
329 "speed-limit-up" => 700,
330 "speed-limit-up-enabled" => true,
331 "ratio-limit" => 1.4000,
332 "ratio-limit-enabled" => true,
333 })) + "\n")
334 EOF
335 sgo transmission-daemon
336 ;;
337 arch)
338 # todo, setup it's config file & daemon
339 pi transmission-cli
340 ;;
341 esac
342 fi
343
344 # adapted from /var/lib/dpkg/info/transmission-daemon.postinst
345 if ! getent passwd debian-transmission > /dev/null; then
346 case $distro in
347 arch)
348 s useradd \
349 --system \
350 --create-home \
351 --home-dir /var/lib/transmission-daemon \
352 --shell /bin/false \
353 debian-transmission
354 ;;
355 *)
356 s adduser --quiet \
357 --system \
358 --group \
359 --no-create-home \
360 --disabled-password \
361 --home /var/lib/transmission-daemon \
362 debian-transmission
363 ;;
364 esac
365 fi
366
367 # arch had a default config,
368 # debian had nothing until you start it.
369 # With a little trial an error, here is a minimal config
370 # taken from the generated one, plus changes that the
371 # settings ui does, without a bunch of ui crap settings.
372 #
373 # only settings I set were
374 # hostname
375 # auto-connect
376 #
377 for f in /home/*; do
378 d=$f/.config/transmission-remote-gtk
379 u=${f##*/}
380 s -u $u mkdir -p $d
381 s -u $u dd of=$d/config.json <<'EOF'
382 {
383 "profiles" : [
384 {
385 "profile-name" : "Default",
386 "hostname" : "frodo",
387 "rpc-url-path" : "/transmission/rpc",
388 "username" : "",
389 "password" : "",
390 "auto-connect" : true,
391 "ssl" : false,
392 "timeout" : 40,
393 "retries" : 3,
394 "update-active-only" : false,
395 "activeonly-fullsync-enabled" : false,
396 "activeonly-fullsync-every" : 2,
397 "update-interval" : 3,
398 "min-update-interval" : 3,
399 "session-update-interval" : 60,
400 "exec-commands" : [
401 ],
402 "destinations" : [
403 ]
404 }
405 ],
406 "profile-id" : 0,
407 "add-options-dialog" : false
408 }
409 EOF
410 done
411
412 case $distro in
413 debian|ubuntu)
414 pi-nostart openvpn
415 # pi-nostart this doesnt seem to be good enough?
416 ser disable openvpn@client
417 ser disable openvpn
418 ;;
419 *) pi openvpn ;;
420 esac
421
422 pi wget
423 case $HOSTNAME in
424 tp|frodo)
425 case $distro in
426 debian|ubuntu)
427 log=$(mktemp)
428 cd /a/opt
429 wget -N https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
430 set +e
431 s dpkg -i google-chrome-stable_current_amd64.deb &> $log
432 code=$?
433 set -e
434 case $code in
435 1)
436 if grep '^dpkg: dependency problems prevent configuration of' \
437 $log &>/dev/null; then
438 s apt-get -fy install
439 else
440 exit 1
441 fi
442 ;;
443 0) : ;;
444 *) exit $code
445 esac
446 ;;
447 arch)
448 pi google-chrome
449 ;;
450 esac
451 ;;
452 esac
453
454 # printer
455 case $distro in
456 arch)
457 pi cups ghostscript gsfonts # from arch wiki cups page
458 pi hplip # from google
459 s gpasswd -a $USER sys # from arch wiki
460 sgo org.cups.cupsd.service
461 # goto http://127.0.0.1:631
462 # administration tab, add new printer button.
463 # In debian, I could use hte recommended driver,
464 # in arch, I had to pick out the 6L driver.
465 ;;
466 debian|ubuntu)
467 spa hplip
468 ;;
469 # other distros unknown
470 esac
471
472
473 case $distro in
474 ubuntu|debian) pi --no-install-recommends mairix notmuch ;;
475 fedora|arch) spa mairix notmuch ;;
476 esac
477 case $distro in
478 arch) spa nfs-utils ;;
479 ubuntu|debian) spa nfs-client ;;
480 esac
481 case $distro in
482 ubuntu|debian) spa par2 ;;
483 arch|fedora) spa par2cmdline ;;
484 esac
485
486 # needed for my tex resume
487 case $distro in
488 ubuntu|debian) spa texlive-full ;;
489 arch) spa texlive-most ;;
490 # fedora unknown
491 esac
492
493 case $distro in
494 ubuntu)
495 # flash, unrar, codecs, ms fonts.
496 # This has a manual prompt.
497 spa ubuntu-restricted-extras
498 ;;
499 fedora)
500 pi yum-utils
501 # rpm fusion recommended codecs
502 s su -c "yum localinstall -y --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm"
503 pi gstreamer-plugins-ugly gstreamer-plugins-bad gstreamer-ffmpeg\
504 xine-lib-extras-freeworld
505 ;;
506 esac
507
508 case $distro in
509 # optional dep for firefox for h.264 video
510 arch) spa gst-libav ;;
511 # other distros, probably come by default
512 esac
513
514 case $distro in
515 fedora|ubuntu|debian) spa gnupg-agent ;;
516 arch) : ;;
517 esac
518
519
520 case $distro in
521 fedora) spa pinentry-gtk ;;
522 *) : ;; # comes default or with other packages
523 esac
524
525 case $distro in
526 arch) spa firefox pulseaudio;;
527 *) : ;; # comes default or with other packages
528 esac
529
530
531 case $distro in
532 arch) spa ttf-dejavu;;
533 debian|ubuntu) spa fonts-dejavu ;;
534 # others unknown
535 esac
536
537
538 case $distro in
539 arch) spa xorg-xev;;
540 debian|ubuntu) spa x11-utils ;;
541 # others unknown
542 esac
543
544 case $distro in
545 arch) pi virt-install;;&
546 debian|ubuntu) pi virtinst ;;&
547 *) pi virt-manager ;; # creates the libvirt group in debian at least
548 # others unknown
549 esac
550 # allow user to run vms, from debian handbook
551 for x in ian traci; do s usermod -a -G libvirt,kvm $x; done
552 # bridge networking as user fails. google lead here, but it doesn't work:
553 # oh well, I give up.
554 # http://wiki.qemu.org/Features-Done/HelperNetworking
555 # s mkdir /etc/qemu
556 # f=/etc/qemu/bridge.conf
557 # s dd of=$f <<'EOF'
558 # allow br0
559 # EOF
560 # #s chown root:qemu $f # debian has somethig like qemu-libvirt. equivalent?
561 # s chmod 640 $f
562
563
564 case $distro in
565 arch) spa cdrkit;;
566 debian|ubuntu) spa genisoimage;;
567 # others unknown
568 esac
569
570 case $distro in
571 arch) spa spice-gtk3 ;;
572 debian|ubuntu) spa spice-client-gtk;;
573 # others unknown
574 esac
575
576 # general known for debian/ubuntu, not for fedora
577 case $distro in
578 arch)
579 # cdrkit for cloud-init isos
580 # dnsmasq & ebtables for nat networking in libvirt
581 # qemu for qemu-img, bind-tools for dig
582 # dmidecode just because syslog complains
583 pi unzip xorg-xmodmap dmidecode ebtables\
584 bridge-utils dnsmasq qemu bind-tools
585 # otherwise we get error about accessing kvm module.
586 # seems like there might be a better way, but google was a bit vague.
587 s sed -ri '/^ *user *=/d' /etc/libvirt/qemu.conf
588 echo 'user = "root"' | s tee -a /etc/libvirt/qemu.conf
589 # https://bbs.archlinux.org/viewtopic.php?id=206206
590 # # this should prolly go in the wiki
591 sgo virtlogd.socket
592 # guessing this is not needed
593 #sgo virtlogd.service
594 sgo libvirtd
595
596 ;;
597 esac
598
599 case $distro in
600 arch) pi virtviewer ;;
601 *) : ;; # other distros have it as a dependency afaik.
602 esac
603
604
605
606 case $distro in
607 fedora) cabal install shellcheck ;;
608 *) spa shellcheck ;;
609 # unknown for older ubuntu
610 esac
611
612
613 case $distro in
614 arch|debian|ubuntu) spa pumpa ;;
615 # others unknown. do have a buildscript:
616 # /a/bin/buildscripts/pumpa ;;
617 esac
618
619
620 case $distro in
621 debian|ubuntu) spa android-tools-adb/unstable ;;
622 arch) spa android-tools ;;
623 # other distros unknown
624 esac
625
626 case $distro in
627 debian)
628 if [[ `debian-archive` == testing ]]; then
629 # has no unstable dependencies
630 spa bitcoin-qt/unstable
631 fi
632 ;;
633 # other distros unknown
634 esac
635
636
637 # proprietary flash. going without for now
638 # case $distro in
639 # debian)
640 # pi flashplugin-nonfree
641 # esac
642
643
644
645 case $distro in
646 fedora)
647 cd $(mktemp -d)
648 wget http://tamacom.com/global/global-6.3.2.tar.gz
649 ex global*
650 cd global-6.3.2
651 # based on https://github.com/leoliu/ggtags
652 ./configure --with-exuberant-ctags=/usr/bin/ctags
653 make
654 s make install
655 s pip install pygments
656 ;;
657 *)
658 pi global
659 ;;&
660 arch)
661 pi python2-pygments
662 ;;
663 debian|ubuntu)
664 pi python-pygments
665 ;;
666 esac
667
668
669 case $distro in
670 debian)
671 pi task-cinnamon-desktop
672 # in settings, change scrolling to two-finger,
673 # because the default edge scroll doesn\'t work.
674 pu transmission-gtk
675 ;;
676 # others unknown
677 esac
678
679 case $distro in
680 arch) spa apg ;;
681
682 # already in debian jessie
683 esac
684
685
686
687
688 # note this failed running at the beginning of this file,
689 # because no systemd user instance was running.
690 # Doing systemd --user resulted in
691 # Trying to run as user instance, but $XDG_RUNTIME_DIR is not set
692 case $distro in
693 # ubuntu unknown. probably the same as debian, just check if the
694 # init scripts come with the package.
695 debian)
696 # copied from arch, but moved to etc
697 s dd of=/etc/systemd/user/synergys.service <<'EOF'
698 [Unit]
699 Description=Synergy Server Daemon
700 After=network.target
701
702 [Service]
703 User=%i
704 ExecStart=/usr/bin/synergys --no-daemon --config /etc/synergy.conf
705 Restart=on-failure
706
707 [Install]
708 WantedBy=multi-user.target
709 EOF
710 s dd of=/etc/systemd/user/synergys.socket <<'EOF'
711 [Unit]
712 Conflicts=synergys@.service
713
714 [Socket]
715 ListenStream=24800
716 Accept=false
717
718 [Install]
719 WantedBy=sockets.target
720 EOF
721 ;;&
722 *)
723 pi synergy
724 # taken from arch wiki.
725 s dd of=/etc/systemd/system/synergyc@.service <<'EOF'
726 [Unit]
727 Description=Synergy Client
728 After=network.target
729
730 [Service]
731 User=%i
732 ExecStart=/usr/bin/synergyc --no-daemon treetowl
733 Restart=on-failure
734 # per man systemd.unit, StartLimitInterval, by default we
735 # restart more than 5 times in 10 seconds.
736 # And this param defaults too 200 miliseconds.
737 RestartSec=3s
738
739 [Install]
740 WantedBy=multi-user.target
741 EOF
742 case $HOSTNAME in
743 frodo)
744 ser enable synergyc@ian
745 ser start synergyc@ian ||: # X might not be running yet
746 systemctl --user start synergys ||:
747 systemctl --user enable synergys
748 ;;
749 treetowl) systemctl --user enable synergys ;;
750 esac
751 ;;
752 esac
753
754
755 ######### end misc packages #########
756
757
758 # packages I once used before and liked, but don't want installed now for
759 # various reasons:
760 # python-sqlite is used for offlineimap
761 # lxappearance python-sqlite dolphin paman dconf-editor
762
763
764
765 ######## unfinished
766
767 # todo, finish configuring smart.
768
769 pi smartmontools
770 # mostly from https://wiki.archlinux.org/index.php/S.M.A.R.T.
771 # turn on smart. background on options:
772 # first line, -a = test everyting on all devices.
773 # -S on, turn on disk internal saving of vendor specific info,
774 # from google, seems like this is usually already on and fairly standard.
775 # -o on, turn on 4 hour period non-performance degrading testing.
776 # short test daily 2-3am, extended tests Saturdays between 3-4am:
777 sched="-s (S/../.././02|L/../../6/03)"
778 s sed -i "s#^[[:space:]]*DEVICESCAN.*#\
779 DEVICESCAN -a -o on -S on -n standby,q $sched\
780 -m ian@iankelling.org -M exec /usr/local/bin/smart-notify#" /etc/smartd.conf
781
782 # in the default configuration of at least ubuntu 14.04, resolvconf is
783 # configured to order any nameservers associated with tun* or tap*
784 # before the normal internet interfaces, which means they are always
785 # consulted first. This is often slower and undesirable, ie. local dns
786 # queries go from 0ms to 10+ or 100+ ms. To reverse the ordering, you
787 # can do:
788 #sudo sed -i '/tun\*\|tap\*/d' /etc/resolvconf/interface-order
789 # however, this breaks dns lookup for hosts on the openvpn lan.
790 # I can\'t figure out why hosts on the normal lan would not be
791 # broken under the default ordering, except the host I was
792 # testing with previously had an entry in /etc/hosts.
793
794 ############# end unfinished
795
796 ########### misc stuff
797
798
799 case $distro in
800 debian|ubuntu)
801 case `debian-archive` in
802 stable)
803 s dd of=/etc/apt/preferences.d/unison-gtk <<'EOF'
804 Explanation: Allow unison-gtk to be upgraded
805 Package: unison-gtk
806 Pin: release a=unstable
807 Pin-Priority: 500
808 EOF
809 # dont think using testing is needed since I figured out how to
810 # deal with mismatching unison compilers, but I dont
811 # see any reason to revert it, since it only installs
812 # a single package which is primarily a single binary
813 pi unison-gtk/testing unison/testing
814 ;;
815 testing)
816 piunison unison-gtk
817 ;;
818 esac
819 ;;
820 arch)
821 pi unison gtk2
822 ;;
823 esac
824
825 case $distro in
826 arch)
827 # default is alsa, doesn\'t work with with pianobar
828 s dd of=/etc/libao.conf <<'EOF'
829 default_driver=pulse
830 EOF
831 ;;
832 esac
833
834 # not using it atm, and for jessie, it depends on a higher version of btrfs-tools
835 # case $distro in
836 # arch|debian|ubuntu) pi btrbk ;;
837 # # others unknown
838 # esac
839
840 if [[ $HOSTNAME == treetowl ]] && [[ `debian-archive` != testing ]]; then
841 # fail2 ban is broken, with a workaround, per
842 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=770171
843 # ill wait a while to see if it gets fixed
844 pi fail2ban
845 sgo fail2ban
846 fi
847
848
849
850
851
852 case $distro in
853 debian|ubuntu) s gpasswd -a ian adm ;; #needed for reading logs
854 esac
855
856 # tor
857 case $distro in
858 # based on
859 # https://www.torproject.org/docs/rpms.html.en
860 # https://www.torproject.org/docs/debian.html.en
861 # todo: figure out if the running service needs to be restarted upon updates
862
863
864 # todo on fedora: setup non-dev packages
865 fedora)
866 s dd of=/etc/yum.repos.d/torproject.repo <<'EOF'
867 [tor]
868 name=Tor experimental repo
869 enabled=1
870 baseurl=http://deb.torproject.org/torproject.org/rpm/tor-testing/fc/20/$basearch/
871 gpgcheck=1
872 gpgkey=http://deb.torproject.org/torproject.org/rpm/RPM-GPG-KEY-torproject.org.asc
873
874 [tor-source]
875 name=Tor experimental source repo
876 enabled=1
877 autorefresh=0
878 baseurl=http://deb.torproject.org/torproject.org/rpm/tor-testing/fc/20/SRPMS
879 gpgcheck=1
880 gpgkey=http://deb.torproject.org/torproject.org/rpm/RPM-GPG-KEY-torproject.org.asc
881 EOF
882
883 # to be secure, take a look at the fingerprint reported from the following install, and see if it matches from the link above:
884 # 3B9E EEB9 7B1E 827B CF0A 0D96 8AF5 653C 5AC0 01F1
885 sgo tor
886 /a/bin/buildscripts/tor-browser
887 ;;
888 ubuntu)
889 tu /etc/apt/sources.list "deb http://deb.torproject.org/torproject.org $(debian-codename) main"
890 gpg --keyserver keys.gnupg.net --recv 886DDD89
891 gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
892 p update
893 pi deb.torproject.org-keyring
894 pi tor
895 /a/bin/buildscripts/tor-browser
896 ;;
897 debian)
898 pi tor
899 /a/bin/buildscripts/tor-browser
900 ;;
901 arch)
902 pi tor tor-browser-en
903 sgo tor
904 ;;
905 # ubuntu unknown
906 esac
907
908 # nfs server
909 case $distro in
910 fedora)
911 end_msg <<'EOF'
912 fedora todo: disable the firewall or find a way to automate it.
913 there's an unused section in t.org for tramikssion firewall setup
914
915 fedora manual config for nfs:
916 s firewall-config
917 change to permanent configuration
918 check the box for nfs
919 was hard to figure this out, not sure if this is all needed, but
920 unblock these too
921 mountd: udp/tcp 20048
922 portmapper, in firewall-config its called rpc-bind: udp/tcp 111
923 troubleshooting, unblock things in rpcinfo -p
924 make sure to reload the firewall to load the persistent configuration
925
926
927 EOF
928 pi nfs-utils
929 sgo nfs-server
930 ;;
931 debian|ubuntu)
932 pi nfs-server
933 ;;
934 arch)
935 pi nfs-utils || pending_reboot=true
936 sgo rpcbind
937 # this failed until I rebooted
938 sgo nfs-server
939 ;;
940 esac
941
942 if [[ $HOSTNAME == frodo ]]; then
943 tu /etc/exports <<'EOF'
944 /k 192.168.1.0/24(rw,nohide,no_subtree_check,insecure)
945 EOF
946 s exportfs -rav
947 fi
948
949 if [[ -e /k/video ]]; then
950 # nohide = export filesystems mounted deeper than the export point
951 # fsid=0 makes this export the "root" export
952 # not documented in the man page, but this means
953 # 1. it can be mounted with a shorthand of server:/
954 # 2. exports that are subdirectories of this one will automatically be mounted
955 tu /etc/exports '/i/video 192.168.1.0/24(rw,fsid=0,nohide,no_root_squash,async,no_subtree_check,insecure)'
956 s exportfs -rav
957 showmount -e localhost
958 fi
959
960
961
962 e "$end_msg_var"
963
964
965 # persistent virtual machines
966
967 case $distro in
968 debian|ubuntu)
969 pi libosinfo-bin;
970 ;;
971 esac
972
973 # distro may not know about win 10 yet.
974 variant=win7
975 if ! virt-install --os-variant list &>/dev/null; then # we are using a newer virt-install
976 for v in 10 8.1 8; do
977 if osinfo-query os | gr "^\s*win${v/./\\.}\s" &>/dev/null; then
978 variant=win$v
979 break
980 fi
981 done
982 fi
983
984 if ! s virsh list --all --name | grep -xF win10 &>/dev/null; then
985
986 # created account with
987 # win10vmian@outlook.com, and easy to remember password
988 # win 10 virtio, makes disk way way way faster
989 # wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso
990 # https://wiki.archlinux.org/index.php/QEMU#Change_Existing_Windows_VM_to_use_virtio
991 # for installing virtio after initial install instead of with initial iso:
992 # qemu-img create -f qcow2 fake.qcow2 1G
993 # --disk=/a/images/virtio-win.iso,device=cdrom \
994 # --disk=/a/images/fake.qcow2,bus=virtio
995 # Also,
996 # went to device manager, saw 2 pci devices with yellow !,
997 # did search for drivers, pick cdrom location, done.
998 #
999 # from http://www.tenforums.com/tutorials/4189-fast-startup-turn-off-windows-10-a.html.
1000 # google said there was a control panel option for it, but
1001 # that turned out to be a lie.
1002 # Put this in a .bat file and run as administrator to turn off
1003 # hyberboot which fucks things up.
1004 # REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V HiberbootEnabled /T REG_dWORD /D 0 /F
1005 # power settings, turn off display: never
1006 # run "control userpasswords2", turn on automatic login.
1007 # note: when changing devices, I just undefine, the create the vm again.
1008
1009 s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
1010 --disk=/a/images/win10.qcow2,bus=virtio --vcpus 2 -r 4096 -w bridge=br0 \
1011 -n win10 --import --os-variant $variant --cpu host-model-only
1012
1013 s virsh destroy win10
1014
1015 # this one hasn\'t had the virtio fix done yet.
1016 s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
1017 --disk=/a/images/win7.qcow2 --vcpus 2 -r 4096 -w bridge=br0 \
1018 -n win7 --import --os-variant win7 --cpu host-model-only
1019 s virsh destroy win7
1020 # had a problem with --cpu host, so trying out
1021 # --cpu host-model-only
1022
1023 fi
1024
1025
1026 pi samba
1027 # note samba re-reads it's config every 1 minute
1028 case $distro in
1029 arch) s cp /etc/samba/smb.conf.default /etc/samba/smb.conf ;;
1030 esac
1031
1032 # add 2 lines after workgroup option
1033 s sed -ri '/^\s*encrypt passwords\s*=/d' /etc/samba/smb.conf
1034 s sed -ri '/^\s*map to guest\s*=/d' /etc/samba/smb.conf
1035 s sed -i 's/\(\s*workgroup\s*=\).*/\1 WORKGROUP\n\tencrypt passwords = yes\n\tmap to guest = bad password/' /etc/samba/smb.conf
1036 # remove default homes section. not sharing that.
1037 s sed -ri '/^\s*\[homes\]/,/\s*\[/d' /etc/samba/smb.conf
1038
1039 if ! grep -xF '[public]' /etc/samba/smb.conf &>/dev/null; then
1040 s tee -a /etc/samba/smb.conf <<'EOF'
1041 [public]
1042 guest ok = yes
1043 read only = no
1044 path = /kfrodo
1045 EOF
1046 fi
1047
1048 case $distro in
1049 debian|ubuntu)
1050 # systemd claims it generates units from /etc/init.d, but it clearly doesn't
1051 # in debian. I have no idea how they are related. fuck debian right now. It's
1052 # not documented. samba has a systemd init file linked to /dev/null.
1053 # There's this https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=769714 which
1054 # claims samba's sub-services will be started automatically by systemd... it
1055 # didn't on install, wonder if it will on boot. It clued me in how to start
1056 # it manually though. Nothing in /usr/share/doc/samba, debian admin guide
1057 # says nothing about any of this. (this is in debian testing as of 4/2016).
1058
1059 s /etc/init.d/samba start
1060 ;;
1061 arch)
1062 sgo samba
1063 ;;
1064 esac
1065
1066 tu /etc/hosts <<< "127.0.1.1 $(hostname).lan $(hostname)"
1067
1068
1069
1070 rootdev=$(mount | sed -rn 's#^(\S+) on / .*#\1#p')
1071 s mkdir /mnt/root
1072 tu /etc/fstab <<< "$rootdev /mnt/root btrfs noatime,subvolid=0 0 0"
1073 mountpoint /mnt/root || s mount /mnt/root
1074 idev=$(mount | sed -rn 's#^(\S+) on /i .*#\1#p')
1075 if [[ $idev != $rootdev ]]; then
1076 s mkdir /mnt/iroot
1077 tu /etc/fstab <<< "$idev /mnt/iroot btrfs noatime,subvolid=0 0 0"
1078 mountpoint /mnt/iroot || s mount /mnt/iroot
1079 fi
1080
1081
1082 ######### begin stuff belonging at the end ##########
1083
1084
1085 # Apps we want to override others for default file handler:
1086 # simplest way in debian is to just install them last.
1087 simple_packages+=(
1088 mpv
1089 )
1090
1091 case $distro in
1092 ubuntu|debian)
1093 spa spacefm-gtk3 ;;
1094 arch)
1095 spa spacefm ;;
1096 esac
1097
1098
1099 pi "${simple_packages[@]}"
1100
1101
1102 if $pending_reboot; then
1103 echo "$0: pending reboot and then finished. doing it now."
1104 s reboot now
1105 else
1106 echo "$0: $(date): ending now)"
1107 fi