2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
25 # setup automatic decryption on boot using host-specific key file.
26 # When changing a hostname, that key needs updating.
29 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
31 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
32 if [[ $
- != *i
* ]]; then
33 exec &>>/var
/log
/keyscript-on.log
34 echo "$0: starting. $(date)"
37 sed="sed --follow-symlinks"
39 # for running under corn, we need this, else, if we call
40 # /sbin/update-initramfs , it will fail with:
41 # /sbin/update-initramfs: 157: mkinitramfs: not found
44 if [[ $PPID == 1 ]]; then
45 if [[ -e /b
/bash_unpublished
/source-state
]]; then
46 # this is the canonical one
47 source /b
/bash_unpublished
/source-state
48 elif [[ -e /dev
/shm
/iank-status
]]; then
49 # This one gets copied by system-status and is useful because it
50 # exists when /a is unmounted.
51 source /dev
/shm
/iank-status
53 if [[ $MAIL_HOST && $MAIL_HOST != "$HOSTNAME" ]]; then
54 echo "$0: exiting early: running under systemd as MAIL_HOST"
59 if [[ ! -e /tmp
/keyscript-off
]]; then
60 if [[ $
($sed -rn 's/^ID=(.*)/\1/p' /etc
/os-release
) == arch
]]; then
61 if ! grep -q '^\s*FILES=' /etc
/mkinitcpio.conf
; then
62 $sed -ri 's/^#(\s*FILES=.*)/\1/' /etc
/mkinitcpio.conf
# uncomment
67 if grep -q "${x}," /etc
/crypttab
; then
68 $sed -i "s#${x},#/root/keyscript,#" /etc
/crypttab
73 # switch to easy or hard login pass which is the same as luks
74 f
=/q
/root
/shadow
/traci-simple
75 [[ $HOSTNAME != tpnew
]] || usermod
-p "$(cat $f)" iank
77 echo "$0: finished. $(date)"