From 791ffa6112748d6734f0730878bdcfdd5c9493c6 Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Fri, 2 Jul 2021 14:20:16 +0900 Subject: [PATCH] Added overwrite install --- script/common/confirmation.sh | 19 ++++++++++-- script/common/preinstall.sh | 55 ++++++++++++++++++++++++----------- script/config.sh | 4 +++ 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/script/common/confirmation.sh b/script/common/confirmation.sh index f9d6ddd..674ab8c 100644 --- a/script/common/confirmation.sh +++ b/script/common/confirmation.sh @@ -5,12 +5,25 @@ function confirmation(){ + # Consistency check for the OVERWRITEINSTALL and ERASEALL + if [ ${ERASEALL} -eq 1 -a ${OVERWRITEINSTALL} -eq 1 ] ; then + cat <<- HEREDOC 1>&2 + ***** ERROR : Confliction between ERASEALL and OVERWRITEINATALL ***** + ...ERASEALL = ${ERASEALL} + ...OVERWRITEINSTALL = ${OVERWRITEINSTALL} + ...Check configuration in config.txt + + ...Installation process terminated.. + HEREDOC + + fi + # Sanity check for volume group name if echo ${VGNAME} | grep "-" -i > /dev/null ; then # "-" is found in the volume group name. cat <<- HEREDOC 1>&2 ***** ERROR : VGNAME is "${VGNAME}" ***** ..."-" is not allowed in the volume name. - ...Check passphrase and config.txt + ...Check configuration in config.txt ...Installation process terminated.. HEREDOC @@ -22,7 +35,7 @@ function confirmation(){ cat <<- HEREDOC 1>&2 ***** ERROR : LVROOTNAME is "${LVROOTNAME}" ***** ..."-" is not allowed in the volume name. - ...Check passphrase and config.txt + ...Check configuration in config.txt ...Installation process terminated.. HEREDOC @@ -34,7 +47,7 @@ function confirmation(){ cat <<- HEREDOC 1>&2 ***** ERROR : LVSWAPNAME is "${LVSWAPNAME}" ***** ..."-" is not allowed in the volume name. - ...Check passphrase and config.txt + ...Check configuration in config.txt ...Installation process terminated.. HEREDOC diff --git a/script/common/preinstall.sh b/script/common/preinstall.sh index 476435e..6f9a987 100644 --- a/script/common/preinstall.sh +++ b/script/common/preinstall.sh @@ -79,24 +79,45 @@ function pre_install() { fi # if /dev/mapper/swap volume already exit. # Create a ROOT Logical Volume on VG. - if [ -e /dev/mapper/${VGNAME}-${LVROOTNAME} ] ; then - cat <<- HEREDOC 1>&2 - ***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}" already exists. ***** - ...Check LVROOTNAME environment variable in config.txt. - HEREDOC - echo "...Deactivate all logical volumes in volume group \"${VGNAME}\"." - vgchange -a n ${VGNAME} - echo "...Close LUKS volume \"${CRYPTPARTNAME}\"." - cryptsetup close ${CRYPTPARTNAME} - cat <<- HEREDOC 1>&2 + if [ -e /dev/mapper/${VGNAME}-${LVROOTNAME} ] ; then # exist + if [ ${OVERWRITEINATALL} -eq 1 ] ; then # exist and overwrite install + echo "...Logical volume "${VGNAME}-${LVROOTNAME}" already exists. OK." + else # exist and not overwriteinstall + cat <<- HEREDOC 1>&2 + ***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}" already exists. ***** + ...Check LVROOTNAME environment variable in config.txt. + HEREDOC + echo "...Deactivate all logical volumes in volume group \"${VGNAME}\"." + vgchange -a n ${VGNAME} + echo "...Close LUKS volume \"${CRYPTPARTNAME}\"." + cryptsetup close ${CRYPTPARTNAME} + cat <<- HEREDOC 1>&2 + + ...Installation process terminated.. + HEREDOC + return 1 # with error status + fi + else # not exsit + if [ ${OVERWRITEINATALL} -eq 1 ] ; then + cat <<- HEREDOC 1>&2 + ***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}" doesn't exist while overwrite install. ***** + ...Check consistency of config.txt. + HEREDOC + echo "...Deactivate all logical volumes in volume group \"${VGNAME}\"." + vgchange -a n ${VGNAME} + echo "...Close LUKS volume \"${CRYPTPARTNAME}\"." + cryptsetup close ${CRYPTPARTNAME} + cat <<- HEREDOC 1>&2 + + ...Installation process terminated.. + HEREDOC + return 1 # with error status + else # not exist and not overwrite install + echo "...Create logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"." + lvcreate -l ${LVROOTSIZE} -n ${LVROOTNAME} ${VGNAME} + fi + fi - ...Installation process terminated.. - HEREDOC - return 1 # with error status - else - echo "...Create logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"." - lvcreate -l ${LVROOTSIZE} -n ${LVROOTNAME} ${VGNAME} - fi # if the root volun already exist # successful return return 0 diff --git a/script/config.sh b/script/config.sh index 726785e..c6308df 100644 --- a/script/config.sh +++ b/script/config.sh @@ -26,6 +26,10 @@ export CRYPTPARTNAME="luks_volume" export VGNAME="vg1" export LVSWAPNAME="swap" +# Do not touch this parameter, unless you understand precisely what you are doing. +# 1 : Overwrite the existing logical volume as root vlume. 0 : Create new logical volume as root volume. +export OVERWRITEINSTALL=0 + # Void Linux only. Ignored in Ubuntu. # The font size of the void-installer export XTERMFONTSIZE=11