various fixes
[distro-setup] / distro-begin
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16
17
18
19 # for bootstrapping a new machine
20
21 # in case we need it,
22 # to make ssh interactive shell run better, we run this first.
23 sudo bash -c 'source /a/c/repos/bash/.bashrc && source /a/exe/ssh-emacs-setup'
24
25
26 # usage: $0 [-r] HOSTNAME
27
28 # tips:
29 # run any sudo command first so your pass is cached
30 # set the scrollback to unlimited in case something goes wrong
31
32 if [[ $EUID == 0 ]]; then
33 if getent passwd ian; then
34 echo "$0: error: running as root. unprivileged user exists. use it."
35 exit 1
36 else
37 echo "$0: warning: running as root. I will setup users then exit"
38 fi
39 fi
40
41 interactive=true # set this to false to force set -x
42 [[ $- == *i* ]] || interactive=false
43
44 if ! $interactive; then
45 set -x
46 set -e -o pipefail
47 fi
48 set -E
49 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
50
51 exec &> >(sudo tee -a /var/log/distro-begin)
52 echo "$0: $(date): starting now)"
53
54 # headless=false # unused atm
55 recompile=false
56 # for copying to a new data fs
57 bootstrapfs=false # old flag, needs new look before using.
58 while [[ $1 == -* ]]; do
59 case $1 in
60 -r) recompile=true; shift ;;
61 esac
62 done
63
64 if [[ $1 ]]; then
65 export HOSTNAME=$1
66 fi
67
68 for f in iank-dev htpc treetowl x2 frodo tp li lj demohost; do
69 eval "$f() { [[ $HOSTNAME == $f ]]; }"
70 done
71 has_p() { treetowl || iank-dev || x2 || frodo || tp || demohost; }
72 has_x() { ! { lj || li; }; }
73 linode() { lj || li; }
74 encrypted() { has_p; }
75
76 shopt -s extglob
77 export GLOBIGNORE=*/.:*/..
78 umask 0002
79
80
81 ####### end command line parsing
82
83 PATH="/a/exe:$PATH"
84 sed="sed --follow-symlinks"
85
86 ##### begin setup encryption scripts ######
87 if encrypted; then
88 # I tried making a service which was dependent on reboot.target,
89 # but it happened too late in the shutdown process.
90 sudo dd of=/etc/systemd/system/keyscripton.service <<'EOF'
91 [Unit]
92 Description=Turn on automatic decryption of drives on boot
93 # tried using graphical.target, but it made my display manager restart before rebooting.
94 # generally, I don't think targets order shutdown like they do startup.
95 # So, I did systemd-analyze plot > something.svg, and picked a reliably started
96 # service that happens late in the game.
97 After=postfix.service
98 DefaultDependencies=no
99 # not sure if needed, makes sure we shut down before reboot.target
100 Conflicts=reboot.target
101
102 [Service]
103 Type=oneshot
104 RemainAfterExit=yes
105 ExecStart=/bin/true
106 ExecStop=/a/exe/keyscript-on
107
108 [Install]
109 WantedBy=keyscriptoff.service
110 EOF
111 sudo systemctl daemon-reload # needed if the file was already there
112 sudo systemctl stop keyscripton.service
113 # sudo systemctl start keyscripton.service
114 sudo systemctl enable keyscripton.service
115
116 sudo dd of=/etc/systemd/system/keyscriptoff.service <<'EOF'
117 [Unit]
118 Description=Turn off automatic decryption of drives on boot
119
120 [Service]
121 Type=oneshot
122 ExecStart=/a/exe/keyscript-off
123
124 [Install]
125 WantedBy=multi-user.target
126 EOF
127 sudo systemctl daemon-reload # needed if the file was already there
128 sudo systemctl enable keyscriptoff.service
129 sudo systemctl start keyscriptoff.service
130 fi
131 ##### end setup encryption scripts ######
132
133
134 install-myqueue
135
136 # this script has been designed to be idempotent
137 # todo, it would be nice to cut down on some of the output
138
139
140 for x in /a/bin/errhandle/*-function; do
141 source $x
142 done
143
144
145 set +e
146 $interactive || errcatch
147 set +x
148 source /a/bin/distro-functions/src/identify-distros
149 $interactive || set -x
150
151 if isfedora; then
152 # comment out line disallowing calling sudo in scripts
153 sudo $sed -i 's/^Defaults *requiretty/#\0 # ian commented/' /etc/sudoers
154 # turn on magic sysrq commands for this boot cycle
155 echo 1 > sudo dd of=/proc/sys/kernel/sysrq
156 # selinux is not user friendly. Like, you enable samba, but you haven't run the magic selinux commands so it doesn't work
157 # and you have no idea why.
158 sudo $sed -i 's/^\(SELINUX=\).*/\1disabled/' /etc/selinux/config
159 selinuxenabled && sudo setenforce 0
160 fi
161
162
163 # already ran for pxe installs, but used for vps & updates
164 distro=$(distro-name)
165 case $distro in
166 ubuntu|debian)
167 sudo bash -c ". /a/bin/fai/fai-wrapper && /a/bin/fai/fai/config/scripts/GRUB_PC/11-ian"
168 ;;
169 *)
170 sudo bash -c ". /a/bin/fai/fai-wrapper &&
171 /a/bin/fai/fai/config/distro-install-common/end"
172 ;;
173 esac
174
175 if linode; then
176 sudo $sed -i '/^127\.0\.1\.1/d' /etc/hosts
177 echo "127.0.1.1 $HOSTNAME.lan $HOSTNAME" | sudo tee -a /etc/hosts
178 fi
179
180
181 if [[ $EUID == 0 ]]; then
182 echo "$0: running as root. exiting now that users are setup"
183 exit 0
184 fi
185
186
187 #### begin link bashrc repo for all users ######
188 for x in /a/c/repos/bash/!(.git|..|.); do
189 lnf "$x" /home/ian
190 sudo -u traci -i <<EOF
191 PATH="/a/exe:$PATH"
192 lnf "$x" /home/traci
193 EOF
194 sudo -i <<EOF
195 PATH="/a/exe:$PATH"
196 lnf $x /root
197 EOF
198 done
199 #### end link bashrc repo for all users ######
200
201
202 set +x
203 errallow
204 source ~/.bashrc
205 $interactive || errcatch
206 $interactive || set -x
207
208
209 # passwordless sudo
210 tu /etc/sudoers <<'EOF'
211 ian ALL=(ALL) NOPASSWD: ALL
212 Defaults env_keep += SUDOD
213 EOF
214
215
216 # enable magic sysrq keys. debian docs say it is already enabled by default
217 isfedora && tu /etc/sysctl.conf 'kernel.sysrq = 1'
218
219
220 s lnf -T /q/p /p
221 # this needs to be before installing pacserve so we have gpg conf.
222 conflink
223
224 if isdebian; then
225 codename=$(debian-codename)
226 if isdebian-stable && has_x; then
227 s dd of=/etc/apt/sources.list.d/mozilla-iceweasel.list <<EOF
228 deb http://mozilla.debian.net/ $codename-backports firefox-release
229 deb-src http://mozilla.debian.net/ $codename-backports firefox-release
230 EOF
231 p update
232 # take care of mozilla signing errors in previous command
233 pi pkg-mozilla-archive-keyring
234 p update
235 else
236 :
237 # this would change stable to testing, but I set that up already.
238 # It\'s just a no-op if its already testing.
239 # sudo sed -ri 's!^( *[^ #]+ +[^ ]+ +)[[:alpha:]]+(.*)!\1testing\2!' /etc/apt/sources.list
240 p update
241 fi
242 fi
243
244 if isarch; then
245 #https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages
246 sudo pacman -S --noconfirm --needed base-devel jq
247 # pacaur seems to be the best, although it + cower has a few minor bugs,
248 # its design goals seem good, so, going for it.
249
250 aurpi() {
251 for p in "$@"; do
252 tempdir=$(mktemp -d)
253 pushd $tempdir
254 aurex "$p"
255 makepkg -sri --skippgpcheck --noconfirm
256 popd
257 rm -rf $tempdir
258 done
259 }
260 aurpi cower pacaur
261
262 pi pacserve
263
264 x=$(mktemp); /usr/bin/pacman.conf-insert_pacserve >$x
265 sudo dd of=/etc/pacman.conf if=$x; rm $x
266 sudo systemctl enable pacserve.service
267 sudo systemctl start pacserve.service
268
269 # strange error if just installing trash-cli: "pyalpm requires python",
270 # so I see that it requires python2, and installing that manually fixes it.
271 # I didn't see this on earlier installation, main thing which changed was
272 # pacserve, so not sure if it's related.
273 pi python2
274 fi
275
276 pup
277 pi trash-cli
278
279
280 ###### link files ###########
281 # convenient to just do all file linking in one place
282
283 # if it wasn't set already, we could set hostname here
284 #echo treetowl | s dd of=/etc/hostname
285 #s hostname -F /etc/hostname
286 #HOSTNAME=$(hostname)
287
288
289 s lnf -T /a/bin /b
290
291 if has_p; then
292 lnf -T /p/offlineimap ~/Maildir
293 lnf -T /p/News ~/News
294 # don't use /* because I don't want to require it to be mounted
295 fi
296
297 s lnf /q/root/.editor-backups /q/root/.undo-tree-history \
298 /a/opt /a/c/.emacs.d $HOME/mw_vars /k/backup /root
299
300 rootsshsync
301
302 s lnf /a/c/.inputrc /a/c/.vim /a/c/.vimrc /a/c/.gvimrc /root
303
304 # machine is going away
305 # if [[ $HOSTNAME == htpc ]]; then
306 # lnf -T /i/Videos ~/Downloads
307 # fi
308
309 if has_p; then
310 # for dovecot
311 lnf -T /i/k/mboxes ~/mail
312 fi
313
314
315 # basic needed packages
316 case $(distro-name) in
317 debian)
318 if has_x; then
319 if isdebian-stable; then
320 pi firefox/$codename-backports
321 else
322 # for a while, firefox/unstable had all it\'s deps satisfied
323 # by testing packages, but now i hit a conflict,
324 # it wanted a newer libfontconfig1, but emacs build-deps
325 # wanted an older one. Oh well, they seem to release
326 # a new esr version every 9 months or so.
327 pi firefox-esr
328 fi
329 fi
330 # for hosts which require nonfree drivers
331 # i previously had extra packages listed here linux-image-amd64
332 # firmware-linux-free linux-headers-amd64, but I
333 # don\'t see any reason why. seems to work in testing without.
334 # remove this note if it continues to work.
335 p=firmware-linux-nonfree
336 if apt-cache show $p &>/dev/null; then
337 pi $p
338 fi
339 ;;&
340 ubuntu|debian)
341 if has_x; then
342 if isdebian-stable; then
343 pi xmacro
344 else
345 pi xmacro/unstable # has no unstable deps
346 fi
347 pi gtk-redshift xinput
348 fi
349 ;;&
350 fedora)
351 p -y groupinstall development-tools c-development books admin-tools
352 pi wget man-pages
353 if has_x; then
354 pi redshift-gtk
355 # debian has this package patched to work, upstream is dead
356 # tried using alien, pi alien, alien -r *.deb, rpm -Uhv *.rpm, got this error, so fuck it
357 # file /usr/bin from install of xmacro-0.3pre_20000911-7.x86_64 conflicts with file from package filesystem-3.2-19.fc20.x86_64
358 # http://packages.debian.org/source/sid/xmacro
359 pi patch libXtst-devel
360 cd $(mktemp -d)
361 wget http://ftp.de.debian.org/debian/pool/main/x/xmacro/xmacro_0.3pre-20000911.orig.tar.gz
362 wget http://ftp.de.debian.org/debian/pool/main/x/xmacro/xmacro_0.3pre-20000911-6.diff.gz
363 ex *.gz
364 patch -p0 < xmacro_0.3pre-20000911-6.diff
365 cd xmacro-0.3pre-20000911.orig
366 make
367 sleep 1 # not sure why the following command couldn\'t find, so trying this
368 # no make install target
369 s cp -f xmacroplay xmacrorec xmacrorec2 /usr/local/bin
370 fi
371 ;;&
372 arch)
373 # like apt-cache
374 pi pkgfile
375 s pkgfile --update
376 if has_x; then
377 # libxtst is missing dep https://aur.archlinux.org/packages/xmacro/#news
378 pi xorg-server redshift xorg-xinput libxtst xmacro
379
380 # background:
381 # https://aur.archlinux.org/packages/xkbset/#comment-545419
382 cert=$(mktemp)
383 cat >$cert <<'EOF'
384 -----BEGIN CERTIFICATE-----
385 MIIJADCCB+igAwIBAgIRAIVAhZ0TMbQ5jTm0koI8X6YwDQYJKoZIhvcNAQELBQAw
386 djELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1JMRIwEAYDVQQHEwlBbm4gQXJib3Ix
387 EjAQBgNVBAoTCUludGVybmV0MjERMA8GA1UECxMISW5Db21tb24xHzAdBgNVBAMT
388 FkluQ29tbW9uIFJTQSBTZXJ2ZXIgQ0EwHhcNMTUxMjA4MDAwMDAwWhcNMTgxMjA3
389 MjM1OTU5WjCBsTELMAkGA1UEBhMCVVMxDjAMBgNVBBETBTY1MjExMREwDwYDVQQI
390 EwhNaXNzb3VyaTERMA8GA1UEBxMIQ29sdW1iaWExHzAdBgNVBAkTFjExMDAgQ2Fy
391 cmllIEZyYW5ja2UgRHIxHzAdBgNVBAoTFlVuaXZlcnNpdHkgb2YgTWlzc291cmkx
392 CzAJBgNVBAsTAk1VMR0wGwYDVQQDExRmYWN1bHR5Lm1pc3NvdXJpLmVkdTCCASIw
393 DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN8Kap8hASpxQeqjHibGsCR1PBkh
394 nW9p5FkuhGpMW/3ko8QfxH0W1Hq2y2DTFUmq17kH3GfT3h9a7HcmUrC3q15PciOB
395 WR3j8u0bDfVppyAZXiHJzYGN7xHiPrZtFEGgwZd28+sW80WXTbG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MpmG2Nu
428 Z/UypjYkN4JvwRbKBpTrce2IT/Sy29x6chBbyD+0WE6QORBtaUHuzE1KoXqpnF4M
429 QrkKw0oBAC6x9dISoomq0DkIndtoBYYLaxSoII6F4OGWgF7pQ/7MiCBYzsKQpn9t
430 aofMcTfvnCjq+MCIaeYnUKBVww0lOJlUxZGKxFJvRpf78HfbBauojjRO2zXLZD/u
431 KMspbTfDaj5etIgWGShY2eml3N/SjAENmZYkcgDBYFyi8CckcEBAVzpH1+D+7Anz
432 txHSYDNHAYLv83MwbegApa1FwPqlG/4SdEU8G6e6Xf5GLC/6GPGVTUpr7o348OOO
433 lzGQzw==
434 -----END CERTIFICATE-----
435 -----BEGIN CERTIFICATE-----
436 MIIF+TCCA+GgAwIBAgIQRyDQ+oVGGn4XoWQCkYRjdDANBgkqhkiG9w0BAQwFADCB
437 iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
438 cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
439 BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQx
440 MDA2MDAwMDAwWhcNMjQxMDA1MjM1OTU5WjB2MQswCQYDVQQGEwJVUzELMAkGA1UE
441 CBMCTUkxEjAQBgNVBAcTCUFubiBBcmJvcjESMBAGA1UEChMJSW50ZXJuZXQyMREw
442 DwYDVQQLEwhJbkNvbW1vbjEfMB0GA1UEAxMWSW5Db21tb24gUlNBIFNlcnZlciBD
443 QTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJwb8bsvf2MYFVFRVA+e
444 xU5NEFj6MJsXKZDmMwysE1N8VJG06thum4ltuzM+j9INpun5uukNDBqeso7JcC7v
445 HgV9lestjaKpTbOc5/MZNrun8XzmCB5hJ0R6lvSoNNviQsil2zfVtefkQnI/tBPP
446 iwckRR6MkYNGuQmm/Bij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WYRUc+ZruwXtuhxkYze
496 Sf7dNXGiFSeUHM9h4ya7b6NnJSFd5t0dCy5oGzuCr+yDZ4XUmFF0sbmZgIn/f3gZ
497 XHlKYC6SQK5MNyosycdiyA5d9zZbyuAlJQG03RoHnHcAP9Dc1ew91Pq7P8yF1m9/
498 qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9cJ2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRB
499 VXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGwsAvgnEzDHNb842m1R0aB
500 L6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gxQ+6IHdfG
501 jjxDah2nGN59PRbxYvnKkKj9
502 -----END CERTIFICATE-----
503 EOF
504 cat /etc/ssl/certs/ca-certificates.crt >> $cert
505 CURL_CA_BUNDLE=$cert pi xkbset
506 fi
507
508 ;;&
509 ubuntu|debian|fedora)
510 if has_x; then
511 if isdebian-stable; then
512 pi xkbset
513 else
514 # xkbset was in testing for quite a while, dunno
515 # why it's not anymore. Sometime I should check and
516 # see if it's back in testing, but the unstable package
517 # doesn't upgrade anything form testing, and it's tiny
518 # so I'm not bothering to automate it.
519 pi xkbset/unstable
520 fi
521 fi
522 ;;&
523 esac
524
525 if has_x; then
526 pi xbindkeys
527 fi
528 pi cryptsetup lvm2
529 # enables trim for volume delete, other rare commands.
530 sudo $sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc/lvm/lvm.conf
531
532 if encrypted; then
533 if isdeb; then
534 sudo cp /usr/share/doc/util-linux/examples/fstrim.{service,timer} /etc/systemd/system
535 fi
536 # does weekly trim
537 sudo systemctl enable fstrim.timer
538 fi
539
540 dirs=(/mnt/{1,2,3,4,5,6,7,8,9})
541 s mkdir -p "${dirs[@]}"
542 s chown ian:ian "${dirs[@]}"
543
544 if [[ $HOSTNAME == treetowl ]]; then
545 # partitioned it with fai partitioner outside of fai,
546 # because it\'s worth it to have 1% space reserved for boot and
547 # swap partitions in case I ever want to boot off those drives.
548 # as root:
549 # . /a/bin/fai/fai-wrapper
550 # eval-fai-classfile /a/bin/fai/fai/config/class/51-multi-boot
551 # fai-setclass ROTATIONAL
552 # export LUKS_DIR=/q/root/luks/
553 # # because the partition nums existed already
554 # fai-setclass REPARTITION
555 # /a/bin/fai/fai/config/hooks/partition.DEFAULT
556
557 # just the first in the btrfs raid
558 dev=ata-TOSHIBA_MD04ACA500_84REK6NTFS9A-part1
559 tu /etc/fstab <<EOF
560 /dev/mapper/crypt_dev_$dev /i btrfs noatime,subvol=i 0 0
561 EOF
562 else
563 tu /etc/fstab <<'EOF'
564 /q/i /i none bind 0 0
565 EOF
566
567 tu /etc/crypttab <<EOF
568 crypt_dev_$dev /dev/disk/by-id/$dev /q/root/luks/host-treetowl discard,luks
569 EOF
570 fi
571
572 tu /etc/fstab <<'EOF'
573 /i/w /w none bind 0 0
574 /i/k /k none bind 0 0
575 EOF
576
577
578
579 if ! mountpoint /kr; then
580 s mkdir -p /kr
581 s chown ian:traci /kr
582 fi
583 if [[ $HOSTNAME == treetowl ]]; then
584 tu /etc/fstab <<'EOF'
585 /k /kr none bind 0 0
586 EOF
587 else
588 tu /etc/fstab <<'EOF'
589 treetowl:/k /kr nfs defaults 0 0
590 EOF
591 fi
592
593 s mkdir -p /q/i/{w,k}
594 for dir in /{i,w,k}; do
595 if mountpoint $dir; then continue; fi
596 s mkdir -p $dir
597 s chown ian:ian $dir
598 s mount $dir
599 done
600
601
602 # ssh and probably some other things care about parent directory
603 # ownership, and ssh doesn\'t allow any group writable parent
604 # directories, so we are forced to use a directory structure similar
605 # to home directories
606 s chown root:ian /q
607 s chmod 755 /q
608
609
610 # it comes with stretch and arch, but not jessie.
611 # propogate /etc/udev/hwdb.d
612 if which systemd-hwdb; then
613 s systemd-hwdb update
614 ser restart systemd-udev-trigger
615 fi
616
617 # work desktop doesnt need gpg stuff, but it doesnt hurt
618 s dd of=/etc/profile.d/environment.sh <<'EOF'
619 # IAN: EDIT THIS FROM /a/bin/distro-setup/distro-begin
620 export ACME_TINY_WRAPPER_CERT_DIR=/p/c/machine_specific/$HOSTNAME/webservercerts
621
622 if [ -f $HOME/path_add-function ]; then
623 . $HOME/path_add-function
624 path_add /usr/sbin /usr/local/sbin /sbin
625 path_add /a/exe /a/opt/bin $HOME/.cabal/bin
626
627 if [ -r /etc/alternatives/java_sdk ]; then
628 export JAVA_HOME=/etc/alternatives/java_sdk
629 path_add /etc/alternatives/java_sdk
630 fi
631 fi
632
633 export EDITOR="emacsclient"
634 # this makes emacsclient file/-c start a server instance if none is running,
635 # instead of some alternate editor logic
636 export ALTERNATE_EDITOR=""
637
638 # ubuntu starts gpg agent automatically with /etc/X11/Xsession.d/90gpg-agent.
639 # fedora doesn't, which left me to figure this out, and google was no help.
640 # fedora documentation is often quite bad :(
641 # This is mostly copied from that file.
642 # Main difference is that we eval the result of starting gpg-agent,
643 # while that file executes it through xsession specific var.
644 # Also make sourcing the pidfile make more sense.
645 # End result should be the same afaik.
646 # for gpg-agent to work when calling gpg from the command line,
647 # we need an environment variable that is setup via the eval.
648 # which is why we do this upon login, so it can propogate
649 # It is also written to the file $HOME/.gnupg/gpg-agent-info-$(hostname)
650 # I'm not aware if that is ever used, but just fyi.
651 # I also added the bit about xmessaging the stderr,
652 # because I'd like to know if the command fails
653 if [ -f /etc/fedora-release ]; then
654 : ${GNUPGHOME=$HOME/.gnupg}
655
656 GPGAGENT=/usr/bin/gpg-agent
657 PID_FILE="$GNUPGHOME/gpg-agent-info-$(hostname)"
658
659 if ! $GPGAGENT 2>/dev/null; then
660 temp="$(mktemp)"
661 eval "$($GPGAGENT --homedir /p/do-not-delete --daemon --sh --write-env-file=$PID_FILE 2>$temp)"
662 temperr="$(<"$temp")"
663 [ -n "$temperr" ] && xmessage "gpg-agent stderr: $temperr"
664 elif [ -r "$PID_FILE" ]; then
665 . "$PID_FILE"
666 export GPG_AGENT_INFO
667 fi
668 fi
669
670 # ubuntu has 002, debian has 022.
671 # from what I've read, benefit of 002 makes shared groups read/write.
672 # Security concern is where some unixes put everyone in a same group,
673 # so if you copy files there with exact perms, that is probably not
674 # what you want. I don't use a system like that, and I don't really care
675 # either way, but I'd prefer
676 # being able to sync file perms with ubuntu systems at work,
677 # and it's easier to change the debian one.
678
679 umask 002
680 EOF
681
682
683
684 postfix-setup
685
686 if isubuntu; then
687 # disable crash report annoying crap
688 s dd of=/etc/default/apport <<<'enabled=0'
689 fi
690
691 # fai sets this an old way that doesn't work for stretch.
692 # no harm in setting it universally here.
693 # using debconf-set-selection, the area gets reset to ETC
694 # on my linode test machine after doing a dpkg-reconfigure, or a reinstall,
695 # so we are using expect :(
696 s apt-get -y install --no-install-recommends expect
697 s expect <<EOF
698 set force_conservative 0
699 spawn dpkg-reconfigure tzdata -freadline
700 expect -nocase timeout {exit 1} "Geographic area:"
701 send "12\r"
702 expect -nocase timeout {exit 1} "Time zone:"
703 send "11\r"
704 expect eof
705 exit
706 EOF
707
708
709 if has_x; then
710 if isarch; then
711 # install so it's build dependencies don't get removed.
712
713 # emacs git build is currently broken
714 if false; then
715 x=$(mktemp -d)
716 pushd $x
717 aurex emacs-git
718 makepkg -si --noconfirm
719 popd
720 rm -rf $x
721 else
722 pi emacs
723 fi
724 pi hunspell hunspell-en
725 else
726 if $recompile; then
727 /a/bin/buildscripts/emacs
728 else
729 /a/bin/buildscripts/emacs --no-r || /a/bin/buildscripts/emacs
730 fi
731 fi
732
733 # todo, figure this out for arch if we ever try out gnome.
734 if ! isarch; then
735 # install for multiple display managers in case we use one
736 if isdeb; then
737 dir=/etc/gdm3
738 elif isfedora; then
739 # fedora didn\'t have the 3.
740 dir=/etc/gdm
741 fi
742 s mkdir -p $dir/PostLogin
743 s command cp /a/bin/distro-setup/desktop-20-autostart.sh $dir/PostLogin/Default
744 s mkdir /etc/lightdm/lightdm.conf.d
745 s dd of=/etc/lightdm/lightdm.conf.d/12-ian.conf <<'EOF'
746 [SeatDefaults]
747 session-setup-script=/a/bin/distro-setup/desktop-20-autostart.sh
748 EOF
749 fi
750
751
752 pi ghc sakura
753 # todo, also note for work comp, scp opt/org-mode bin/build-scripts
754
755 # use the package manger version to install the cabal version
756 pi cabal-install
757 cabal update
758 PATH="$PATH:$HOME/.cabal/bin"
759
760 # todo, on older ubuntu I used cabal xmonad + xfce,
761 # see /a/bin/old-unused/xmonad-cabal.sh
762
763 # trying out the distros versions newer distros
764 pi xmonad
765 if isarch; then
766 # for displaying error messages.
767 # optional dependency in arch, standard elsewhere.
768 pi xorg-xmessage xmonad-contrib xorg-xsetroot xorg-xinit
769
770 # https://wiki.archlinux.org/index.php/Xinitrc
771 for homedir in /home/*; do
772 cp /etc/X11/xinit/xinitrc $homedir/.xinitrc
773 $sed -ri '/^ *twm\b/,$d' $homedir/.xinitrc
774 tee -a $homedir/.xinitrc <<'EOF'
775 /a/bin/desktop-20-autostart.sh
776 xsetroot -cursor_name left_ptr
777 exec xmonad
778 EOF
779 done
780 else
781 pi suckless-tools
782 fi
783 pi dmenu
784
785 if isdeb && (tp || x2); then
786 pi task-laptop
787 fi
788 fi
789
790 # the first pup command can kill off our /etc/ mod, so rerun this
791 /a/exe/ssh-emacs-setup
792 echo "$0: $(date): ending now"