Improved variable management

This commit is contained in:
Michele Cereda
2022-04-18 01:11:56 +02:00
parent 8dc9f14e8a
commit a202013a33
6 changed files with 33 additions and 28 deletions

View File

@@ -2,14 +2,15 @@
: ${DEVICE:?not set}
: ${LABEL:?not set}
MOUNT_OPTIONS="${MOUNT_OPTIONS:-compress-force=zstd}"
[[ ${EUID} -eq 0 ]] || (echo "Please rerun this script with root privileges" && exit 1)
[[ -f "${DEVICE}" ]] || echo "${DEVICE} not found"
: "${MOUNT_OPTIONS:=compress-force=zstd}"
cryptsetup luksFormat "${DEVICE}"
cryptsetup luksOpen "${DEVICE}" "${LABEL}"
mkfs.btrfs --label "${LABEL}" "/dev/mapper/${LABEL}"
mount --types btrfs --options "${MOUNT_OPTIONS}" "/dev/mapper/${LABEL}" "/mnt/${LABEL}"
[[ $EUID -eq 0 ]] || (echo "Please rerun this script with root privileges" && exit 1)
[[ -f "$DEVICE" ]] || echo "${DEVICE} not found"
cryptsetup luksFormat "$DEVICE"
cryptsetup luksOpen "$DEVICE" "$LABEL"
mkfs.btrfs --label "$LABEL" "/dev/mapper/${LABEL}"
mount --types btrfs --options "$MOUNT_OPTIONS" "/dev/mapper/${LABEL}" "/mnt/${LABEL}"
umount "/mnt/${LABEL}"
cryptsetup luksClose "${DEVICE}"
cryptsetup luksClose "$DEVICE"