From f5d39aa867c36592382f275082c4aeb665aa6336 Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Tue, 29 Jun 2021 07:39:17 +0900 Subject: [PATCH] all existence check is by -e --- ubuntu/1-pre-install.sh | 8 ++++---- ubuntu/3-post-install.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ubuntu/1-pre-install.sh b/ubuntu/1-pre-install.sh index af72de5..169d3dc 100644 --- a/ubuntu/1-pre-install.sh +++ b/ubuntu/1-pre-install.sh @@ -91,7 +91,7 @@ fi # if erase all # ----- Open the LUKS partition ----- # Open the crypt partition. -printf %s "${PASSPHRASE}" | cryptsetup open -d - "${DEV}${CRYPTPARTITION}" ${CRYPTPARTNAME} +printf %s "${PASSPHRASE}" | cryptsetup open -e - "${DEV}${CRYPTPARTITION}" ${CRYPTPARTNAME} # Check whether successful open. If mapped, it is successful. if [ ! -e /dev/mapper/${CRYPTPARTNAME} ] ; then @@ -106,20 +106,20 @@ fi # if crypt volume is unable to open # ----- Configure the LVM in LUKS volume ----- # Create a Physical Volume and Volume Group, if first time -if [ ! -d /dev/${VGNAME} ]; then +if [ ! -e /dev/${VGNAME} ]; then pvcreate /dev/mapper/${CRYPTPARTNAME} vgcreate ${VGNAME} /dev/mapper/${CRYPTPARTNAME} fi # if /dev/volume-groupt not exist # Create a SWAP Logical Volume on VG, if it doesn't exist -if [ -d /dev/mapper/${VGNAME}-${LVSWAPNAME} ] ; then +if [ -e /dev/mapper/${VGNAME}-${LVSWAPNAME} ] ; then echo "Swap volume already exist. Skipped to create" 1>&2 else lvcreate -L ${LVSWAPSIZE} -n ${LVSWAPNAME} ${VGNAME} fi # if /dev/mapper/swap volume already exit. # Create a ROOT Logical Volume on VG. -if [ -d /dev/mapper/${VGNAME}-${LVROOTNAME} ] ; then +if [ -e /dev/mapper/${VGNAME}-${LVROOTNAME} ] ; then cat <&2 ***** ERROR : Logical volume ${VGNAME}-${LVROOTNAME} already exists. ***** Check LVROOTNAME environment variable in config.txt. diff --git a/ubuntu/3-post-install.sh b/ubuntu/3-post-install.sh index 89b12e1..c417ead 100644 --- a/ubuntu/3-post-install.sh +++ b/ubuntu/3-post-install.sh @@ -37,7 +37,7 @@ chmod u=rx,go-rwx /etc/luks chmod u=r,go-rwx /etc/luks/boot_os.keyfile # Add a key to the key file. Use the passphrase in the environment variable. -printf %s "${PASSPHRASE}" | cryptsetup luksAddKey -d - "${DEV}${CRYPTPARTITION}" /etc/luks/boot_os.keyfile +printf %s "${PASSPHRASE}" | cryptsetup luksAddKey -e - "${DEV}${CRYPTPARTITION}" /etc/luks/boot_os.keyfile # Add the LUKS volume information to /etc/crypttab to decrypt by kernel. echo "${CRYPTPARTNAME} UUID=$(blkid -s UUID -o value ${DEV}${CRYPTPARTITION}) /etc/luks/boot_os.keyfile luks,discard" >> /etc/crypttab