Refactored

This commit is contained in:
Suikan 2021-07-01 20:57:24 +09:00
parent 3a5446c6ad
commit d51c88949b
6 changed files with 71 additions and 18 deletions

View file

@ -1,7 +1,10 @@
#!/bin/bash
# ******************************************************************************* # *******************************************************************************
# Confirmation and Passphrase setting # Confirmation and Passphrase setting
# ******************************************************************************* # *******************************************************************************
function confirmation(){
# Sanity check for volume group name # Sanity check for volume group name
if echo ${VGNAME} | grep "-" -i > /dev/null ; then # "-" is found in the volume group name. if echo ${VGNAME} | grep "-" -i > /dev/null ; then # "-" is found in the volume group name.
cat <<HEREDOC 1>&2 cat <<HEREDOC 1>&2
@ -11,7 +14,7 @@ Check passphrase and config.txt
Installation terminated. Installation terminated.
HEREDOC HEREDOC
return return 1
fi # "-" is found in the volume group name. fi # "-" is found in the volume group name.
# Sanity check for root volume name # Sanity check for root volume name
@ -23,7 +26,7 @@ Check passphrase and config.txt
Installation terminated. Installation terminated.
HEREDOC HEREDOC
return return 1
fi # "-" is found in the volume name. fi # "-" is found in the volume name.
# Sanity check for swap volume name # Sanity check for swap volume name
@ -35,7 +38,7 @@ Check passphrase and config.txt
Installation terminated. Installation terminated.
HEREDOC HEREDOC
return return 1
fi # "-" is found in the volume name. fi # "-" is found in the volume name.
# For surre ask the config.sh is edited # For surre ask the config.sh is edited
@ -51,7 +54,7 @@ if [ ${YESNO} != "Y" -a ${YESNO} != "y" ] ; then
Installation terminated. Installation terminated.
HEREDOC HEREDOC
return return 1
fi # if YES fi # if YES
# For sure ask ready to erase. # For sure ask ready to erase.
@ -64,7 +67,7 @@ Check config.sh. The variable ERASEALL is ${ERASEALL}.
Installation terminated. Installation terminated.
HEREDOC HEREDOC
return return 1
fi # if YES fi # if YES
fi # if erase all fi # if erase all
@ -81,7 +84,12 @@ read -sr PASSPHRASE_C
if [ ${PASSPHRASE} != ${PASSPHRASE_C} ] ; then if [ ${PASSPHRASE} != ${PASSPHRASE_C} ] ; then
cat <<HEREDOC 1>&2 cat <<HEREDOC 1>&2
***** ERROR : Passphrase doesn't match ***** ***** ERROR : Passphrase doesn't match *****
Installation terminated. Installation terminated.
HEREDOC HEREDOC
return return 1
fi # passphrase validation fi # passphrase validation
# succesfull return
return 0
}

View file

@ -1,7 +1,10 @@
#!/bin/bash
# ******************************************************************************* # *******************************************************************************
# Common part of para-install # Common part of para-install
# ******************************************************************************* # *******************************************************************************
function parainstall() {
# While the /etc/default/grub in the install target is NOT existing, keep sleeping. # While the /etc/default/grub in the install target is NOT existing, keep sleeping.
# If installer terminated without file copy, this script also terminates. # If installer terminated without file copy, this script also terminates.
while [ ! -e ${TARGETMOUNTPOINT}/etc/default/grub ] while [ ! -e ${TARGETMOUNTPOINT}/etc/default/grub ]
@ -15,7 +18,7 @@ The installer terminated unexpectedly.
Installation process terminated. Installation process terminated.
HEREDOC HEREDOC
return return 1
fi fi
done # while done # while
@ -26,7 +29,7 @@ sleep 1 # 1sec.
# Make target GRUB aware to the crypt partition # Make target GRUB aware to the crypt partition
# This must do it after start of the file copy by installer, but before the end of the file copy. # This must do it after start of the file copy by installer, but before the end of the file copy.
# If the environment is not GUI, keep quiet not to bother the TUI installer. # If the environment is not GUI, keep quiet not to bother the TUI installer.
if [ $PARINSTMSG -eq 1 ]; then if [ ${PARAINSTMSG} -eq 1 ]; then
echo "...Add GRUB_ENABLE_CRYPTODISK entry to ${TARGETMOUNTPOINT}/etc/default/grub " echo "...Add GRUB_ENABLE_CRYPTODISK entry to ${TARGETMOUNTPOINT}/etc/default/grub "
fi fi
echo "GRUB_ENABLE_CRYPTODISK=y" >> ${TARGETMOUNTPOINT}/etc/default/grub echo "GRUB_ENABLE_CRYPTODISK=y" >> ${TARGETMOUNTPOINT}/etc/default/grub
@ -34,7 +37,12 @@ echo "GRUB_ENABLE_CRYPTODISK=y" >> ${TARGETMOUNTPOINT}/etc/default/grub
# And then, wait for the end of installer process # And then, wait for the end of installer process
# If the environment is not GUI, keep quiet not to bother the TUI installer. # If the environment is not GUI, keep quiet not to bother the TUI installer.
if [ $PARAINSTMSG -eq 1 ]; then if [ ${PARAINSTMSG} -eq 1 ]; then
echo "...Waiting for the end of GUI/TUI installer." echo "...Waiting for the end of GUI/TUI installer."
fi fi
wait $installer_pid wait $installer_pid
# succesfull return
return 0
} # para install

View file

@ -1,3 +1,7 @@
#!/bin/bash
function parainstall_msg() {
cat <<HEREDOC cat <<HEREDOC
****************************************************************************** ******************************************************************************
The pre-install process is done. We are ready to install the Linux to the The pre-install process is done. We are ready to install the Linux to the
@ -22,3 +26,5 @@ if [ ${ERASEALL} -eq 1 ] ; then
echo "swap : /dev/mapper/${VGNAME}-${LVSWAPNAME}" echo "swap : /dev/mapper/${VGNAME}-${LVSWAPNAME}"
fi fi
return 0
}

View file

@ -2,6 +2,8 @@
# Pre-install stage # Pre-install stage
# ******************************************************************************* # *******************************************************************************
function pre_install() {
# ----- Erase entire disk, create partitions, format them and encrypt the LUKS partition ----- # ----- Erase entire disk, create partitions, format them and encrypt the LUKS partition -----
if [ ${ERASEALL} -eq 1 ] ; then if [ ${ERASEALL} -eq 1 ] ; then
@ -51,7 +53,7 @@ Check passphrase and config.txt
Installation terminated. Installation terminated.
HEREDOC HEREDOC
return return 1
fi # if crypt volume is unable to open fi # if crypt volume is unable to open
# ----- Configure the LVM in LUKS volume ----- # ----- Configure the LVM in LUKS volume -----
@ -81,8 +83,12 @@ Check LVROOTNAME environment variable in config.txt.
Installation terminated. Installation terminated.
HEREDOC HEREDOC
return return 1
else else
echo "...Create logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"." echo "...Create logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"."
lvcreate -l ${LVROOTSIZE} -n ${LVROOTNAME} ${VGNAME} lvcreate -l ${LVROOTSIZE} -n ${LVROOTNAME} ${VGNAME}
fi # if the root volun already exist fi # if the root volun already exist
# successful return
return 0
}

View file

@ -3,6 +3,12 @@
# Load configuration parameter # Load configuration parameter
source config.sh source config.sh
# Load functions
source common/confirmation.sh
source common/preinstall.sh
source common/parainstall.sh
source common/parainstall_msg.sh
# Varidate whether script is executed as sourced or not # Varidate whether script is executed as sourced or not
(return 0 2>/dev/null) && sourced=1 || sourced=0 (return 0 2>/dev/null) && sourced=1 || sourced=0
if [ $sourced -eq 0 ] ; then if [ $sourced -eq 0 ] ; then
@ -46,21 +52,28 @@ fi # "Ubuntu" is not found in the OS name.
# ******************************************************************************* # *******************************************************************************
# Common part of the parameter confirmation # Common part of the parameter confirmation
source common/_confirmation.sh if ! confirmation ; then
return 1
fi
# ******************************************************************************* # *******************************************************************************
# Pre-install stage # Pre-install stage
# ******************************************************************************* # *******************************************************************************
# Common part of the pre-install stage # Common part of the pre-install stage
source common/_preinstall.sh if ! pre_install ; then
return 1
fi
# ******************************************************************************* # *******************************************************************************
# Para-install stage # Para-install stage
# ******************************************************************************* # *******************************************************************************
# Show common message to let the operator focus on the critical part # Show common message to let the operator focus on the critical part
source common/_parainstall_msg.sh if ! parainstall ; then
return 1
fi
# Ubuntu dependent message # Ubuntu dependent message
cat <<HEREDOC cat <<HEREDOC
@ -85,7 +98,7 @@ installer_pid=$!
# Common part of the para-install. # Common part of the para-install.
# Record the install PID, modify the /etc/default/grub of the target, # Record the install PID, modify the /etc/default/grub of the target,
# and then, wait for the end of sintaller. # and then, wait for the end of sintaller.
source common/_parainstall.sh parainstall_msg
# ******************************************************************************* # *******************************************************************************
# Post-install stage # Post-install stage

View file

@ -3,6 +3,12 @@
# Load configuration parameter # Load configuration parameter
source config.sh source config.sh
# Load functions
source common/confirmation.sh
source common/preinstall.sh
source common/parainstall.sh
source common/parainstall_msg.sh
# Varidate whether script is executed as sourced or not # Varidate whether script is executed as sourced or not
(return 0 2>/dev/null) && sourced=1 || sourced=0 (return 0 2>/dev/null) && sourced=1 || sourced=0
if [ $sourced -eq 0 ] ; then if [ $sourced -eq 0 ] ; then
@ -46,7 +52,9 @@ fi # "Void" is not found in the OS name.
# ******************************************************************************* # *******************************************************************************
# Common part of the parameter confirmation # Common part of the parameter confirmation
source common/_confirmation.sh if ! confirmation ; then
return 1
fi
# ******************************************************************************* # *******************************************************************************
# Pre-install stage # Pre-install stage
@ -61,7 +69,9 @@ else
fi fi
# Common part of the pre-install stage # Common part of the pre-install stage
source common/_preinstall.sh if ! pre_install ; then
return 1
fi
# ADD "rd.auto=1 cryptdevice=/dev/sda2:${LUKS_NAME} root=/dev/mapper/${VGNAME}-${ROOTNAME}" to GRUB. # ADD "rd.auto=1 cryptdevice=/dev/sda2:${LUKS_NAME} root=/dev/mapper/${VGNAME}-${ROOTNAME}" to GRUB.
# This is magical part. I have not understood why this is required. # This is magical part. I have not understood why this is required.
@ -75,7 +85,9 @@ sed -i "s#loglevel=4#loglevel=4 rd.auto=1 cryptdevice=/dev/sda2:${LUKS_NAME} roo
# ******************************************************************************* # *******************************************************************************
# Show common message to let the operator focus on the critical part # Show common message to let the operator focus on the critical part
source common/_parainstall_msg.sh if ! parainstall ; then
return 1
fi
# Ubuntu dependent message # Ubuntu dependent message
cat <<HEREDOC cat <<HEREDOC