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