How Can I Create a Bash Script For Menu Based LUKS Encryption?

242 Views Asked by At

I am writing a Bash script to make LUKS encryption user friendly and to make the process faster while still allowing control of the arguments.

My current code:

#!/usr/bin/env bash


## Ask user for device.
echo "Device:"
read device

## Ask user for cipher.
echo "Available ciphers:"
echo "AES     [0]"
echo "Serpent [1]"
echo "Twofish [2]"
echo "Cipher:"
read cipherin
if [[ $cipherin == "0" ]]; then
        [[ $cipher == "aes-xts-plain64" ]]
elif [[ $cipherin == "1" ]]; then
        [[ $cipher == "serpent-xts-plain64" ]]
elif [[ $cipherin == "2" ]]; then
        [[ $cipher == "twofish-xts-plain64" ]]
else echo "Invalid choice."
fi

## Ask user for key length.
echo "Available key lengths (bits):"
echo "128 [0]"
echo "256 [1]"
echo "Key length:"
read keyin
if [[ $keyin == "0" ]]; then
        [[ $key == "256" ]]
elif [[ $keyin == "1" ]]; then
        [[ $key == "512" ]]
else echo "Invalid choice."
fi

## Ask user for hash.
echo "Available hashes:"
echo "SHA-1     [0]"
echo "SHA-256   [1]"
echo "SHA-512   [2]"
echo "Whirlpool [3]:"
echo "Hash:"
read hashin
if [[ $hashin == "0" ]]; then
        [[ $hash == "sha1" ]]
elif [[ $hashin == "1" ]]; then
        [[ $hash == "sha256" ]]
elif [[ $hashin == "2" ]]; then
        [[ $hash == "sha512" ]]
elif [[ $hashin == "3" ]]; then
        [[ $hash == "whirlpool" ]]
else echo "Invalid choice."
fi

## Ask user for PBKDF.
echo "Available PBKDFs:"
echo "argon2i  [0]"
echo "argon2id [1]"
echo "pbkdf2   [2]"
read pbkdfin
if [[ $pbkdfin == "0" ]]; then
        [[ $pbkdf == "argon2i" ]]
elif [[ $pbkdfin == "1" ]]; then
        [[ $pbkdf == "argon2id" ]]
elif [[ $pbkdfin == "2" ]]; then
        [[ $pbkdf == "pbkdf2" ]]
else echo "Invalid choice."
fi

## Ask user for iteration time.
echo "Iteration time (ms):"
read iteration

## Encrypt drive using LUKS.
echo "Encrypting..."
sudo cryptsetup --type luks2 -c ${cipher} -h ${hash}\
 -i ${iteration} -s ${key} --pbkdf ${pbkdf} --use-urandom\
 -y luksFormat ${device}

The command fails with "cryptsetup: invalid numeric value". I enter 2000 into the iterations, which is default, so I know the number of interations is not the issue.

I have used https://shellcheck.net with no positive outcome; I am confused by the results.

0

There are 0 best solutions below