From 6810e4414a1e0ba1804e7e41e6eed720af10843d Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Sun, 4 Jul 2021 21:41:49 +0900 Subject: [PATCH 1/4] Added error handling Add the return status validation Issue #7 --- script/lib.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/script/lib.sh b/script/lib.sh index 0d03ad7..895f331 100644 --- a/script/lib.sh +++ b/script/lib.sh @@ -138,16 +138,20 @@ function pre_install() { # Zap existing partition table and create new GPT echo "...Initializing \"${DEV}\" with GPT." sgdisk --zap-all "${DEV}" + if is_error ; then return 1 ; fi; # If error, terminate # Create EFI partition and format it echo "...Creating an EFI partition on \"${DEV}\"." # shellcheck disable=SC2140 sgdisk --new="${EFIPARTITION}":0:+"${EFISIZE}" --change-name="${EFIPARTITION}":"EFI System" --typecode="${EFIPARTITION}":ef00 "${DEV}" + if is_error ; then return 1 ; fi; # If error, terminate echo "...Formatting the EFI parttion." mkfs.vfat -F 32 -n EFI-SP "${DEV}${EFIPARTITION}" + if is_error ; then return 1 ; fi; # If error, terminate # Create Linux partition echo "...Creating a Linux partition on ${DEV}." # shellcheck disable=SC2140 sgdisk --new="${CRYPTPARTITION}":0:0 --change-name="${CRYPTPARTITION}":"Linux LUKS" --typecode="${CRYPTPARTITION}":8309 "${DEV}" + if is_error ; then return 1 ; fi; # If error, terminate # Then print them sgdisk --print "${DEV}" else # BIOS @@ -159,6 +163,7 @@ function pre_install() { sfdisk "${DEV}" <<- HEREDOC 2M,,L HEREDOC + if is_error ; then return 1 ; fi; # If error, terminate fi # if EFI firmware # Encrypt the partition to install Linux @@ -194,8 +199,10 @@ function pre_install() { else echo "...Initializing a physical volume on \"${CRYPTPARTNAME}\"" pvcreate /dev/mapper/"${CRYPTPARTNAME}" + if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; echo "...And then creating Volume group \"${VGNAME}\"." vgcreate "${VGNAME}" /dev/mapper/"${CRYPTPARTNAME}" + if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; fi # if /dev/volume-groupt exist # Create a SWAP Logical Volume on VG, if it doesn't exist @@ -204,6 +211,7 @@ function pre_install() { else echo "...Creating logical volume \"${LVSWAPNAME}\" on \"${VGNAME}\"." lvcreate -L "${LVSWAPSIZE}" -n "${LVSWAPNAME}" "${VGNAME}" + if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; fi # if /dev/mapper/swap volume already exit. # Create a ROOT Logical Volume on VG. @@ -331,4 +339,21 @@ function distribution_check(){ # no error return 0 +} + + +# ******************************************************************************* +# Error report and return revsers status. +# ******************************************************************************* +function is_error() { + if [ $? -eq 0 ] ; then # Is previous job OK? + return 1 # If OK, return error ( because it was not error ) + else + cat <<- HEREDOC + **** ERROR ! **** + + Installation process terminated. + HEREDOC + return 0 # If error, return OK ( because it was error ) + fi; } \ No newline at end of file From 95d8c6f62cfc1281194364647975af2f068ba15f Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Sun, 4 Jul 2021 21:54:29 +0900 Subject: [PATCH 2/4] Add and adjust erro rhanding. Add error handling afer dd. Error message of pre-install is now conditional. --- script/lib.sh | 1 + script/void-kaiten-yaki.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/script/lib.sh b/script/lib.sh index 895f331..c9c207e 100644 --- a/script/lib.sh +++ b/script/lib.sh @@ -158,6 +158,7 @@ function pre_install() { # Zap existing partition table echo "...Erasing partition table of \"${DEV}\"." dd if=/dev/zero of="${DEV}" bs=512 count=1 + if is_error ; then return 1 ; fi; # If error, terminate # Create MBR and allocate max storage for Linux partition echo "...Creating a Linux partition on ${DEV} with MBR." sfdisk "${DEV}" <<- HEREDOC diff --git a/script/void-kaiten-yaki.sh b/script/void-kaiten-yaki.sh index 6dd8da4..87cfcd4 100644 --- a/script/void-kaiten-yaki.sh +++ b/script/void-kaiten-yaki.sh @@ -56,8 +56,8 @@ function main() { # Common part of the pre-install stage if ! pre_install ; then # If error, restore the modification. - echo "...restoring modified /etc/default/grub." - sed -i -e "s#loglevel=4 ${GRUB_ADDITIONAL_PARAMETERS}#loglevel=4#" /etc/default/grub + echo "...restoring /etc/default/grub, if needed" + sed -i -e "s#${GRUB_ADDITIONAL_PARAMETERS}##" /etc/default/grub return 1 # with error status fi From e3e35995611120680650e998c8bba16e88ba77d3 Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Sun, 4 Jul 2021 22:00:55 +0900 Subject: [PATCH 3/4] Add error handling on lvcreate root --- script/lib.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/lib.sh b/script/lib.sh index c9c207e..82b0ffc 100644 --- a/script/lib.sh +++ b/script/lib.sh @@ -240,6 +240,7 @@ function pre_install() { else # not exist and not overwrite install echo "...Creating logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"." lvcreate -l "${LVROOTSIZE}" -n "${LVROOTNAME}" "${VGNAME}" + if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; fi fi From 98ad669b1338ea6c827489c2f7e39f9577270604 Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Sun, 4 Jul 2021 22:09:22 +0900 Subject: [PATCH 4/4] Update changelog Add the return status validation Issue #7 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 557e539..ec8b588 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Record of the modification in project development. ### Changed - [Issue 5 : OVERWRITEINSTALL confirmation is missing](https://github.com/suikan4github/kaiten-yaki/issues/5) - [Issue 6 : Remove loglevel dependency from the void-kaiten-yaki.sh ](https://github.com/suikan4github/kaiten-yaki/6) +- [Issue 7 : Add the return status validation ](https://github.com/suikan4github/kaiten-yaki/7) ### Deprecated ### Removed