diff options
Diffstat (limited to 'init')
-rwxr-xr-x | init | 44 |
1 files changed, 22 insertions, 22 deletions
@@ -4,19 +4,19 @@ export DEBUG=0 export INTERACTIVE=0 export ROOTDEV='' -function screen_init { +screen_init() { # Clear screen clear # Output message file if it exists - [[ -f /etc/msg ]] && cat /etc/msg + [ -f /etc/msg ] && cat /etc/msg } # # Mounts the fakeroot from the kernel "root" param # -function mount_fakeroot { +mount_fakeroot() { local rootdev=${1} local fakeroot=${2} @@ -24,10 +24,10 @@ function mount_fakeroot { } -function log { +log() { local msg="${1}" echo -e "${msg}" - if [[ ${DEBUG} -ne 0 ]]; then + if [ "${DEBUG}" -ne 0 ]; then echo "Press enter to continue" read fi @@ -38,17 +38,17 @@ function log { # Resolves the path to the root device from the cmdline root= syntax. # Currently handles UUID syntax and /dev/sdx syntax # -function parse_cmdline { +parse_cmdline() { local cmdline=${1} for i in ${cmdline[@]}; do case "${i}" in root=*) - if [[ ${i:5:4} == 'UUID' ]]; then + if [ "${i:5:4}" == 'UUID' ]; then # mount by uuid local uuid=$(echo ${i} | cut -d '=' -f 3) ROOTDEV="$(blkid -U ${uuid})" - elif [[ ${i:5:5} == 'LABEL' ]]; then + elif [ "${i:5:5}" == 'LABEL' ]; then # mount by label local label=$(echo ${i} | cut -d '=' -f 3) ROOTDEV="$(blkid -L ${label})" @@ -78,10 +78,10 @@ function parse_cmdline { # filesystem, but won't automatically detect luks partitions and prompt for a # password. This allows the script to be smarter about encrypted partitions. # -function get_part_type { - path=${1} - typestr=$(blkid -s TYPE ${path}) - if [[ $(echo ${typestr} | grep 'crypto_LUKS') ]]; then +get_part_type() { + local path="${1}" + local typestr="$(blkid -s TYPE ${path})" + if [ "$(echo ${typestr} | grep 'crypto_LUKS')" ]; then echo 'luks' else echo 'fs' @@ -94,15 +94,15 @@ function get_part_type { # to the new decrypted block device. This path takes the rough form of # /dev/mapper/_dev_sdx # -function setup_encrypted { - path=${1} - name=$(echo ${path} | tr / _) +setup_encrypted() { + local path="${1}" + local name="$(echo ${path} | tr / _)" # Decrypted block dev path is /dev/mapper/${name} cryptsetup luksOpen ${path} ${name} # Notify user and wait for input on failure - if [[ $? -gt 0 ]]; then + if [ "$?" -gt 0 ]; then echo "An error was detected mounting the encrypted root." >&2 echo "Pausing. Press enter to continue." >&2 read @@ -149,7 +149,7 @@ wait_dev() { # Main function to keep the main operations code nicely separated from the # rest. # -function main { +main() { # display fanciful boot image screen_init @@ -161,7 +161,7 @@ function main { local fakeroot='/mnt/root' - if [[ ! -d ${fakeroot} ]]; then + if [ ! -d "${fakeroot}" ]; then log "Fake root location ${fakeroot} does not exist. Creating." mkdir ${fakeroot} fi @@ -176,14 +176,14 @@ function main { wait_dev "${ROOTDEV}" 10 # Drop to maintenance shell if root device does not exist. - if [[ $? -ne 0 ]]; then + 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)" /bin/bash -i fi - if [[ $(get_part_type ${ROOTDEV}) == 'luks' ]]; then + if [ "$(get_part_type ${ROOTDEV})" == 'luks' ]; then # Set new rootdev location (/dev/mapper/something). This will update it to # the decrypted block device path. log "Root device ${ROOTDEV} is encrypted." @@ -192,7 +192,7 @@ function main { fi # Drop to interactive shell if requested - if [[ ${INTERACTIVE} == 1 ]]; then + if [ "${INTERACTIVE}" == 1 ]; then log "Interractive shell requested. Type 'exit' to continue boot sequence." /bin/bash --norc fi @@ -202,7 +202,7 @@ function main { mount_fakeroot ${ROOTDEV} ${fakeroot} # Ensure switch_root will be possible for destination fakeroot - if [[ ! -f ${fakeroot}/sbin/init ]]; then + 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." /bin/bash -i |