11#!/bin/busybox sh
2+ # shellcheck shell=sh
3+ # shellcheck disable=SC2039
4+ #
5+ # Really, this should be ash, not sh, but shellcheck doesn't support ash, see
6+ # https://github.com/koalaman/shellcheck/issues/853
7+ # SC2039 is there because of that (local/== unsupported in sh, work in ash)
28
39# This is the init script built into the PrawnOS initramfs
410
@@ -21,8 +27,8 @@ echo In PrawnOS Init
2127
2228#add this to start shell at desired point
2329rescue_shell() {
24- [ "{$ 1}" != "debug" ] && echo "Something went wrong. Dropping to a shell." > /dev/tty1
25- [ "{$ 1}" == "debug" ] && echo "Debug flag detected, entering debug shell" > /dev/tty1
30+ [ "${ 1}" != "debug" ] && echo "Something went wrong. Dropping to a shell." > /dev/tty1
31+ [ "${ 1}" == "debug" ] && echo "Debug flag detected, entering debug shell" > /dev/tty1
2632 echo "Something went wrong. Dropping to a shell." > /dev/tty1
2733 exec setsid /bin/sh -c 'exec /bin/sh </dev/tty1 >/dev/tty1 2>&1'
2834}
@@ -53,10 +59,12 @@ rootpartuuid() {
5359# if optional count is provided:
5460# returns 1 if substring occurs in string < optional count
5561# returns 0 otherwise
56- occur() while case "$1" in (*"$2"*) set -- \
62+ occur() {
63+ while case "$1" in (*"$2"*) set -- \
5764 "${1#*"$2"}" "$2" "${3:-0}" "$((${4:-0}+1))";;
5865 (*) return "$((${4:-0}<${3:-1}))";;esac
5966 do : "${_occur:+$((_occur=$4))}";done
67+ }
6068
6169# mount the bare necesities
6270mount -n -t proc proc /proc
93101
94102echo BLKID: ${BLKID} > /dev/tty1
95103
96- #If its an mmcblk device, the kernel partiton will p1. If it is a usb device, the partiton will just be 1
97- #Just want everything before the 1
104+ # If it's an mmcblk device, the kernel partiton will be p1. If it is a usb device, the partiton will just be 1.
105+ # Just want everything before the 1
98106ROOT_DEV="${BLKID%1:*}"
99107echo ROOT_DEV: ${ROOT_DEV} > /dev/tty1
100108
101109# label any partition on the system with RESCUESHELL to enter the initramfs rescue shell before mount and root_switch.
102110# you can do this with "cgpt add -i 1 -l RESCUESHELL /dev/sda" for example to label the first partiton of a usb drive.
103- if [ -n "$(blkid | grep RESCUESHELL)" ]
104- then
111+ if blkid | grep -q RESCUESHELL; then
105112 rescue_shell debug
106113fi
107114
108115
109- if [ -n "$(blkid ${ROOT_DEV}2 | grep crypto_LUKS)" ]
110- then
111- #decrypt and mount the root filesystem, disable kernel log messages to avoid clashing with the prompt
116+ if blkid ${ROOT_DEV}2 | grep -q crypto_LUKS; then
117+ # decrypt and mount the root filesystem, disable kernel log messages to avoid clashing with the prompt
112118 dmesg -n 2
113119 echo "Opening encrypted root partition, this will take 30s..."
114120 cryptsetup --tries 5 luksOpen ${ROOT_DEV}2 luksroot || rescue_shell
0 commit comments