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