f26861bdfcff825425fa9e2addc3d84850286623
[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 [[ ! -e /tmp/keyscript-off ]]; then
23 if [[ $($sed -rn 's/^ID=(.*)/\1/p' /etc/os-release) == arch ]]; then
24 if ! grep -q '^\s*FILES=' /etc/mkinitcpio.conf; then
25 $sed -ri 's/^#(\s*FILES=.*)/\1/' /etc/mkinitcpio.conf # uncomment
26 mkinitcpio -p linux
27 fi
28 else
29 x=decrypt_keyctl
30 if grep -q "${x}," /etc/crypttab; then
31 $sed -i "s#${x},#/root/keyscript,#" /etc/crypttab
32 update-initramfs -u
33 fi
34 fi
35 fi
36 # switch to easy or hard login pass which is the same as luks
37 f=/q/root/shadow/traci-simple
38 [[ $HOSTNAME != tpnew ]] || usermod -p "$(cat $f)" iank
39
40 echo "$0: finished. $(date)"