linux-image-manager/scripts/encryption/storage/single_drive/setup.sh

51 lines
1.4 KiB
Bash
Raw Normal View History

2020-12-20 21:16:56 +01:00
#!/bin/bash
2020-12-20 21:58:11 +01:00
# shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location.
# shellcheck disable=SC2015 # Deactivating bool hint
# shellcheck disable=SC2154 # Referenced but not assigned
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
echo "Setups disk encryption"
2020-05-20 15:03:50 +02:00
set_device_mount_partition_and_mapper_paths
2020-05-20 12:47:30 +02:00
overwritte_device_with_zeros
info "Creating new GPT partition table..."
( echo "g" # create a new empty GPT partition table
echo "w" # Write partition table
2020-05-20 12:47:30 +02:00
)| sudo fdisk --wipe always "$device_path" ||
error
info "Creating partition table..."
2020-05-20 12:47:30 +02:00
( 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
2020-05-20 12:47:30 +02:00
)| sudo fdisk --wipe always "$device_path" ||
error
info "Encrypt $device_path..." &&
2020-12-20 21:58:11 +01:00
sudo cryptsetup -v -y luksFormat "$partition_path" ||
2020-05-20 12:47:30 +02:00
error
info "Unlock partition..." &&
2020-12-20 21:58:11 +01:00
sudo cryptsetup luksOpen "$partition_path" "$mapper_name" ||
2020-05-20 12:47:30 +02:00
error
info "Create btrfs file system..." &&
2020-12-20 21:58:11 +01:00
sudo mkfs.btrfs "$mapper_path" || error
info "Creating mount folder unter \"$mount_path\"..." &&
2020-12-20 21:58:11 +01:00
sudo mkdir -p "$mount_path" || error
info "Mount partition..." &&
2020-12-20 21:58:11 +01:00
sudo mount "$mapper_path" "$mount_path" ||
2020-05-20 12:47:30 +02:00
error
info "Own partition by user..." &&
2020-12-20 21:58:11 +01:00
sudo chown -R "$USER":"$USER" "$mount_path" ||
2020-05-20 12:47:30 +02:00
error
2020-05-20 15:03:50 +02:00
success "Encryption successfull :)"