summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xinit50
1 files changed, 29 insertions, 21 deletions
diff --git a/init b/init
index 89eec1b..98a771e 100755
--- a/init
+++ b/init
@@ -1,13 +1,14 @@
#!/bin/bash
export DEBUG=0
+export QUIET=0
export INTERACTIVE=0
export ROOTDEV=''
export CRYPTROOT=''
screen_init() {
# Clear screen
- clear
+ [ "${QUIET}" -eq 1 ] && clear
# Output message file if it exists
[ -f /etc/msg ] && cat /etc/msg
@@ -26,8 +27,11 @@ mount_fakeroot() {
log() {
- local msg="${1}"
- echo -e "${msg}"
+ local lvl="${1}"
+ local msg="${2}"
+ [ "${QUIET}" -eq 1 ] && [ "${lvl,,}" = "info" ] && return
+
+ printf -- "%s\n" "${msg}"
if [ "${DEBUG}" -ne 0 ]; then
echo "Press enter to continue"
read
@@ -80,6 +84,10 @@ parse_cmdline() {
# Enable interactive mode
INTERACTIVE=1
;;
+ quiet)
+ # Enable quiet boot (less output)
+ QUIET=1
+ ;;
esac
done
}
@@ -102,7 +110,7 @@ setup_encrypted() {
# Ensure decryption was successful, it not, drop to debug shell and reboot once done.
printf 'ERROR: Could not decrypt device\n' >&2
printf 'Dropping to debug shell (will automatically reboot on exit).\n' >&2
- /bin/bash --norc
+ /bin/bash --norc -i
printf 'Rebooting\n' >&2
printf 'b' > /proc/sysrq-trigger
fi
@@ -164,64 +172,64 @@ main() {
local fakeroot='/mnt/root'
if [ ! -d "${fakeroot}" ]; then
- log "Fake root location ${fakeroot} does not exist. Creating."
+ log INFO "Fake root location ${fakeroot} does not exist. Creating."
mkdir ${fakeroot}
fi
- log "Parsing cmdline arguments"
+ log INFO "Parsing cmdline arguments"
parse_cmdline "$(cat /proc/cmdline)"
- log "Root device: ${ROOTDEV}"
+ log INFO "Root device: ${ROOTDEV}"
- log "Waiting up to 10 seconds for root device to appear."
+ log INFO "Waiting up to 10 seconds for root device to appear."
wait_dev "${ROOTDEV}" 10
# Drop to maintenance shell if root device does not exist.
if [ "$?" -ne 0 ]; then
- log "ERROR: Root device ${ROOTDEV} does not exist or can not be accessed."
- log " Dropping to maintenance shell for troubleshooting."
- log " (You may just need to wait longer for the root device)"
+ log ERROR "ERROR: Root device ${ROOTDEV} does not exist or can not be accessed."
+ log ERROR " Dropping to maintenance shell for troubleshooting."
+ log ERROR " (You may just need to wait longer for the root device)"
/bin/bash -i
fi
if cryptsetup isLuks "${ROOTDEV}"; then
# Set new rootdev location (/dev/mapper/something). This will update it to
# the decrypted block device path.
- log "Root device ${ROOTDEV} is encrypted."
+ log INFO "Root device ${ROOTDEV} is encrypted."
ROOTDEV=$(setup_encrypted ${ROOTDEV})
- log "New rootdev: ${ROOTDEV}"
+ log INFO "New rootdev: ${ROOTDEV}"
fi
if [ ! -z "${CRYPTROOT}" ]; then
- log "Cryptroot defined. Changing rootdev to '${CRYPTROOT}'"
+ log INFO "Cryptroot defined. Changing rootdev to '${CRYPTROOT}'"
ROOTDEV="${CRYPTROOT}"
fi
# Drop to interactive shell if requested
if [ "${INTERACTIVE}" == 1 ]; then
- log "Interractive shell requested. Type 'exit' to continue boot sequence."
+ log INFO "Interractive shell requested. Type 'exit' to continue boot sequence."
/bin/bash --norc
fi
# Mount the fakeroot.
- log "Mounting fakeroot"
+ log INFO "Mounting fakeroot"
mount_fakeroot ${ROOTDEV} ${fakeroot}
# Ensure switch_root will be possible for destination fakeroot
if [ ! -f "${fakeroot}/sbin/init" ]; then
- log "ERROR: Destination fakeroot ${fakeroot} does not have an init script."
- log " Cannot proceed. Dropping to shell for troubleshooting."
+ log ERROR "ERROR: Destination fakeroot ${fakeroot} does not have an init script."
+ log ERROR " Cannot proceed. Dropping to shell for troubleshooting."
/bin/bash -i
fi
# Boot the real McCoy
- log "Switching root"
+ log INFO "Switching root"
exec switch_root ${fakeroot} /sbin/init
# This will be reached if previous command failed
- log "There was an error performing switch_root to ${fakeroot}."
- log "Starting recovery shell."
+ log ERROR "There was an error performing switch_root to ${fakeroot}."
+ log ERROR "Starting recovery shell."
/bin/bash -i
}

Generated by cgit