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