shellcheck and fix checkrestart false positive
[distro-setup] / keyscript-on
index 71e19f0500f16d519a6997892b47bc25bf88e8d2..e62c7ed63c14d4b6f1a9b50965a0511773d4aebf 100755 (executable)
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
 
-[[ $EUID == 0 ]] || exec sudo "${BASH_SOURCE}" "$@"
+[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
 if [[ $- != *i* ]]; then
     exec &>>/var/log/keyscript-on.log
     echo "$0: starting. $(date)"
 fi
 rootn=1
 
+sed="sed --follow-symlinks"
+
 if [[ ! -e /tmp/keyscript-off ]]; then
-    if [[ $(sed -rn 's/^ID=(.*)/\1/p' /etc/os-release) == arch ]]; then
+    if [[ $($sed -rn 's/^ID=(.*)/\1/p' /etc/os-release) == arch ]]; then
         if ! grep -q '^\s*FILES=' /etc/mkinitcpio.conf; then
-            sed -ri --follow-symlinks 's/^#(\s*FILES=.*)/\1/' /etc/mkinitcpio.conf # uncomment
+            $sed -ri 's/^#(\s*FILES=.*)/\1/' /etc/mkinitcpio.conf # uncomment
             mkinitcpio -p linux
         fi
     else
-        if grep -q '/root/keyscript,' /etc/crypttab; then
-            sed -i --follow-symlinks 's#/root/keyscript-manual,#/root/keyscript,#' /etc/crypttab
-            update-initramfs -u
+        x=/root/keyscript
+        if grep -q "${x}-manual," /etc/crypttab; then
+            $sed -i "s#${x}-manual,#${x},#" /etc/crypttab
+           update-initramfs -u
         fi
     fi
 fi
 # switch to easy or hard login pass which is the same as luks
 f=/q/root/shadow/traci-simple
-[[ $HOSTNAME != tp ]] || usermod -p "$(cat $f)" ian
+[[ $HOSTNAME != tpnew ]] || usermod -p "$(cat $f)" iank
 
 echo "$0: finished. $(date)"