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