From a03a4adc96f14f6115897a9ca414fce9af32b45b Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Wed, 20 May 2020 12:47:30 +0200 Subject: [PATCH] Finished luks setup --- scripts/base.sh | 11 ++++++++++ scripts/encryption/storage/mount.sh | 3 ++- scripts/encryption/storage/setup.sh | 33 +++++++++++++++++------------ scripts/image/setup.sh | 9 +------- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/scripts/base.sh b/scripts/base.sh index d9e1944..6409b79 100644 --- a/scripts/base.sh +++ b/scripts/base.sh @@ -82,6 +82,17 @@ set_device_path(){ error } +overwritte_device_with_zeros(){ + question "Should $device_path be overwritten with zeros before copying?(y/N)" && read -r copy_zeros_to_device + if [ "$copy_zeros_to_device" = "y" ] + then + info "Overwritting..." && + dd if=/dev/zero of="$device_path" bs="$OPTIMAL_BLOCKSIZE" status=progress || error "Overwritting $device_path failed." + else + info "Skipping Overwritting..." + fi +} + HEADER(){ echo echo "${COLOR_YELLOW}The" diff --git a/scripts/encryption/storage/mount.sh b/scripts/encryption/storage/mount.sh index f2c86e6..eadbffa 100644 --- a/scripts/encryption/storage/mount.sh +++ b/scripts/encryption/storage/mount.sh @@ -4,8 +4,9 @@ echo "Mounts encrypted storages" set_device_mount_and_mapper_paths +partition_path="$device_path""1" info "Unlock partition..." && -sudo cryptsetup luksOpen $device_path $mapper_name || +sudo cryptsetup luksOpen $partition_path $mapper_name || error info "Mount partition..." && diff --git a/scripts/encryption/storage/setup.sh b/scripts/encryption/storage/setup.sh index a29320f..c504a2d 100644 --- a/scripts/encryption/storage/setup.sh +++ b/scripts/encryption/storage/setup.sh @@ -3,38 +3,43 @@ echo "Setups disk encryption" set_device_mount_and_mapper_paths -info "Overwritting device \"$device_path\" with zeros..." && -sudo dd if=/dev/zero of=$device_path bs=$OPTIMAL_BLOCKSIZE status=progress conv=fdatasync || -error +overwritte_device_with_zeros info "Creating new GPT partition table..." ( echo "g" # create a new empty GPT partition table echo "w" # Write partition table -)| sudo fdisk "$device_path" || error +)| sudo fdisk --wipe always "$device_path" || +error info "Creating partition table..." -( echo "n" # Create GPT partition table +( echo "n" # Create new partition + echo "" # Accept default + echo "" # Accept default + echo "" # Accept default echo "p" # Create GPT partition table echo "w" # Write partition table -)| sudo fdisk "$device_path" || error - -info "Show memory devices..." && -sudo fdisk -l || error +)| sudo fdisk --wipe always "$device_path" || +error +partition_path="$device_path""1" info "Encrypt $device_path..." && -sudo cryptsetup -v -y luksFormat $device_path +sudo cryptsetup -v -y luksFormat $partition_path || +error info "Unlock partition..." && -sudo cryptsetup luksOpen $device_path $mapper_name +sudo cryptsetup luksOpen $partition_path $mapper_name || +error info "Create btrfs file system..." && sudo mkfs.btrfs $mapper_path || error info "Creating mount folder unter \"$mount_path\"..." && -mkdir -p $mount_path || error +sudo mkdir -p $mount_path || error info "Mount partition..." && -sudo mount $mapper_path $mount_path || error +sudo mount $mapper_path $mount_path || +error info "Own partition by user..." && -sudo chown -R $USER:$USER $mount_path || error +sudo chown -R $USER:$USER $mount_path || +error diff --git a/scripts/image/setup.sh b/scripts/image/setup.sh index da6701c..babc033 100644 --- a/scripts/image/setup.sh +++ b/scripts/image/setup.sh @@ -214,14 +214,7 @@ question "Should the image be transfered to $device_path?(y/n)" && read -r trans if [ "$transfer_image" = "y" ] then - question "Should $device_path be overwritten with zeros before copying?(y/n)" && read -r copy_zeros_to_device - if [ "$copy_zeros_to_device" = "y" ] - then - info "Overwritting..." && - dd if=/dev/zero of="$device_path" bs="$OPTIMAL_BLOCKSIZE" status=progress || error "Overwritting $device_path failed." - else - info "Skipping Overwritting..." - fi + overwritte_device_with_zeros info "Starting image transfer..." if [ "$os" = "arch" ]