minor improvements
[distro-setup] / keyscript-on
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4
5 set -eE -o pipefail
6 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
7
8 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
9 if [[ $- != *i* ]]; then
10 exec &>>/var/log/keyscript-on.log
11 echo "$0: starting. $(date)"
12 fi
13 rootn=1
14
15 sed="sed --follow-symlinks"
16
17 # for running under corn, we need this, else, if we call
18 # /sbin/update-initramfs , it will fail with:
19 # /sbin/update-initramfs: 157: mkinitramfs: not found
20 PATH="/sbin:$PATH"
21
22 if [[ $INVOCATION_ID ]]; then
23 if [[ -e /b/bash_unpublished/source-state ]]; then
24 source /b/bash_unpublished/source-state
25 fi
26 if [[ $MAIL_HOST && $MAIL_HOST != $HOSTNAME ]]; then
27 echo "$0: exiting early: running under systemd as MAIL_HOST"
28 exit 0
29 fi
30 fi
31
32 if [[ ! -e /tmp/keyscript-off ]]; then
33 if [[ $($sed -rn 's/^ID=(.*)/\1/p' /etc/os-release) == arch ]]; then
34 if ! grep -q '^\s*FILES=' /etc/mkinitcpio.conf; then
35 $sed -ri 's/^#(\s*FILES=.*)/\1/' /etc/mkinitcpio.conf # uncomment
36 mkinitcpio -p linux
37 fi
38 else
39 x=decrypt_keyctl
40 if grep -q "${x}," /etc/crypttab; then
41 $sed -i "s#${x},#/root/keyscript,#" /etc/crypttab
42 update-initramfs -u
43 fi
44 fi
45 fi
46 # switch to easy or hard login pass which is the same as luks
47 f=/q/root/shadow/traci-simple
48 [[ $HOSTNAME != tpnew ]] || usermod -p "$(cat $f)" iank
49
50 echo "$0: finished. $(date)"