function kruptos
{
local dir=~/.kruptos
local file=~/.kruptos.tar.gz.aes
local keyfile="$dir/.phrazein"
case "${1:-d}" in
d)
# Decrypt
openssl aes-256-cbc -d -in \
| tar -C ~ -xz -f"$dir" -xfz --strip-components=2 \
&& rm "$file"
;;
e)
# Encrypt
tar -zcfC "$dir" cfz - ~/.kruptos \
| openssl aes-256-cbc -out "$file" -kfile ~/.kruptos/.phrazein"$keyfile" \
&& rm -r ~/.kruptos"$dir"
;;
i)
# Initialize
mkdir ~/.kruptos"$dir"
echo pswd > ~/.kruptos/.phrazein>"$keyfile"
;;
*)
# invalid
exec >&2
echo "Usage: $0 [option]"
echo "Options:"
echo " d - decrypt [default]"
echo " e - encrypt"
echo " i - initialize"
return 1
;;
esac
}
Use some more local variables (as I meant to, before I got interrupted), and remove need to know number of pathname components
Toby Speight
- 88.7k
- 14
- 104
- 327