79 lines
3.1 KiB
Makefile
Executable file
79 lines
3.1 KiB
Makefile
Executable file
alias m := mount
|
|
alias u := unmount
|
|
|
|
MOUNTPOINT := "./mnt" # where the encrypted filesystem can be accessed
|
|
VOLUME_NAME := "portable_luks_volume" # how the image should be named
|
|
IMAGE_PATH := "./luks_container.img" # path where the image should be
|
|
IMAGE_SIZE := "1G" # size how big the image should be
|
|
required_deps := 'cryptsetup fallocate mkfs.ext4 zstd mount umount chown rmdir mkdir xxhsum' # required dependencies
|
|
CHECKSUM := "xxh.checksum"
|
|
|
|
default: mount
|
|
|
|
# mounting the encrypted volume
|
|
mount: check-deps verify-checksum decompress
|
|
@echo "creating mountpoint"
|
|
@mkdir -p {{MOUNTPOINT}} # creating mountpoint
|
|
sudo cryptsetup luksOpen {{IMAGE_PATH}} {{VOLUME_NAME}} # opening the luks container
|
|
sudo mount /dev/mapper/{{VOLUME_NAME}} {{MOUNTPOINT}} # mounting the filesystem
|
|
sudo chown $USER {{MOUNTPOINT}} # setting permission for the current user to access the mount
|
|
|
|
# unmounting the encrypted volume
|
|
unmount: check-deps
|
|
sudo umount {{MOUNTPOINT}} # unmounting the filesystem
|
|
sudo cryptsetup luksClose {{VOLUME_NAME}} # closing the luks container
|
|
rmdir {{MOUNTPOINT}} # removing the mountpoint
|
|
just compress # compressing the image
|
|
|
|
# creating an encrypted volume and mounting it
|
|
create: check-deps
|
|
sudo fallocate -l {{IMAGE_SIZE}} {{IMAGE_PATH}} # allocating the file
|
|
sudo cryptsetup luksFormat {{IMAGE_PATH}} {{VOLUME_NAME}} # formating the file for luks
|
|
sudo cryptsetup luksOpen {{IMAGE_PATH}} {{VOLUME_NAME}} # opening the luks container
|
|
sudo mkfs.ext4 /dev/mapper/{{VOLUME_NAME}} # formatting the container with a filesystem
|
|
mkdir -p {{MOUNTPOINT}} # creating a mountpoint
|
|
sudo mount /dev/mapper/{{VOLUME_NAME}} {{MOUNTPOINT}} # mounting filesystem
|
|
|
|
|
|
# compressing the image
|
|
compress:
|
|
@echo "Compressing the image and removing the original"
|
|
zstd --rm --adapt {{IMAGE_PATH}}
|
|
|
|
# decompressing the image
|
|
decompress:
|
|
@echo "Decompressing the image and removing compressed version"
|
|
zstd --rm -d {{IMAGE_PATH}}.zst
|
|
|
|
create-checksum:
|
|
@xxhsum {{IMAGE_PATH}}.zst > {{CHECKSUM}}
|
|
|
|
verify-checksum:
|
|
@xxhsum -c {{CHECKSUM}}
|
|
|
|
|
|
# Check if all required dependencies are installed
|
|
check-deps:
|
|
#!/usr/bin/env sh
|
|
missing_deps=""
|
|
# Loop through each dependency in the list
|
|
for dep in {{required_deps}}; do
|
|
# Check if the command exists in the PATH
|
|
if ! command -v "$dep" > /dev/null 2>&1; then
|
|
# If not found, add it to the list of missing dependencies (with a space separator)
|
|
missing_deps="$missing_deps $dep"
|
|
fi
|
|
done
|
|
|
|
# Check if the missing_deps variable has content (trim whitespace first)
|
|
if [ -n "$(echo $missing_deps | xargs)" ]; then
|
|
echo "Error: The following required dependencies are missing:" >&2
|
|
# Use xargs to print each missing dependency on a new line, prefixed with ' - '
|
|
echo "$missing_deps" | xargs -n1 printf " - %s\n" >&2
|
|
echo "Please install them and try again." >&2
|
|
# Exit with a non-zero status code to indicate failure
|
|
exit 1
|
|
else
|
|
# Optional: message indicating success
|
|
echo "All dependencies satisfied."
|
|
fi
|