initramfs/resources/initramfs-init: fix shellcheck issues

This commit is contained in:
Austin English 2020-12-27 05:39:03 -06:00
parent c60b085e56
commit b76b029b7d
2 changed files with 18 additions and 12 deletions

View File

@ -1,4 +1,10 @@
#!/bin/busybox sh
# shellcheck shell=sh
# shellcheck disable=SC2039
#
# Really, this should be ash, not sh, but shellcheck doesn't support ash, see
# https://github.com/koalaman/shellcheck/issues/853
# SC2039 is there because of that (local/== unsupported in sh, work in ash)
# This is the init script built into the PrawnOS initramfs
@ -21,8 +27,8 @@ echo In PrawnOS Init
#add this to start shell at desired point
rescue_shell() {
[ "{$1}" != "debug" ] && echo "Something went wrong. Dropping to a shell." > /dev/tty1
[ "{$1}" == "debug" ] && echo "Debug flag detected, entering debug shell" > /dev/tty1
[ "${1}" != "debug" ] && echo "Something went wrong. Dropping to a shell." > /dev/tty1
[ "${1}" == "debug" ] && echo "Debug flag detected, entering debug shell" > /dev/tty1
echo "Something went wrong. Dropping to a shell." > /dev/tty1
exec setsid /bin/sh -c 'exec /bin/sh </dev/tty1 >/dev/tty1 2>&1'
}
@ -53,10 +59,12 @@ rootpartuuid() {
# if optional count is provided:
# returns 1 if substring occurs in string < optional count
# returns 0 otherwise
occur() while case "$1" in (*"$2"*) set -- \
occur() {
while case "$1" in (*"$2"*) set -- \
"${1#*"$2"}" "$2" "${3:-0}" "$((${4:-0}+1))";;
(*) return "$((${4:-0}<${3:-1}))";;esac
do : "${_occur:+$((_occur=$4))}";done
}
# mount the bare necesities
mount -n -t proc proc /proc
@ -93,22 +101,20 @@ fi
echo BLKID: ${BLKID} > /dev/tty1
#If its an mmcblk device, the kernel partiton will p1. If it is a usb device, the partiton will just be 1
#Just want everything before the 1
# If it's an mmcblk device, the kernel partiton will be p1. If it is a usb device, the partiton will just be 1.
# Just want everything before the 1
ROOT_DEV="${BLKID%1:*}"
echo ROOT_DEV: ${ROOT_DEV} > /dev/tty1
# label any partition on the system with RESCUESHELL to enter the initramfs rescue shell before mount and root_switch.
# you can do this with "cgpt add -i 1 -l RESCUESHELL /dev/sda" for example to label the first partiton of a usb drive.
if [ -n "$(blkid | grep RESCUESHELL)" ]
then
if blkid | grep -q RESCUESHELL; then
rescue_shell debug
fi
if [ -n "$(blkid ${ROOT_DEV}2 | grep crypto_LUKS)" ]
then
#decrypt and mount the root filesystem, disable kernel log messages to avoid clashing with the prompt
if blkid ${ROOT_DEV}2 | grep -q crypto_LUKS; then
# decrypt and mount the root filesystem, disable kernel log messages to avoid clashing with the prompt
dmesg -n 2
echo "Opening encrypted root partition, this will take 30s..."
cryptsetup --tries 5 luksOpen ${ROOT_DEV}2 luksroot || rescue_shell

View File

@ -74,9 +74,9 @@ main() {
# The find fallback is for non git users, e.g., distros packaging shellcheck or end users
# running shell-checks from a tarball download.
if [ -d .git ] ; then
files_to_check="$(git ls-files | xargs file | grep -e 'shell script' | cut -d : -f1)"
files_to_check="$(git ls-files | xargs file | grep -e 'shell script' -e '/bin/busybox sh script' | cut -d : -f1)"
else
files_to_check="$(find . -type f -exec file {} \; | grep -e 'shell script' | cut -d : -f1)"
files_to_check="$(find . -type f -exec file {} \; | grep -e 'shell script' -e '/bin/busybox sh script' | cut -d : -f1)"
fi
# Generic shellscript checks: