#!/bin/bash
-if (( $# != 2));then
- echo "usage: overonion e|d keyfile"
+function die() {
+ echo "$*" >&2
exit 1
+}
+
+if (( $# != 2));then
+ die "usage: overonion e|d keyfile"
fi
mode=$1
if [[ "$mode" != e && "$mode" != d ]];then
- echo "Use 'e' for encrypt or 'd' for decrypt"
- exit 1
+ die "Use 'e' for encrypt or 'd' for decrypt"
fi
keyfile=$2
if [[ ! -e "$keyfile" ]];then
- echo "Keyfile not found"
- exit 1
+ die "Keyfile not found"
fi
if [[ ! -r "$keyfile" ]];then
- echo "Cannot read keyfile"
- exit 1
+ die "Cannot read keyfile"
fi
num_layers=$(wc -l < "$keyfile")
if (( num_layers < 20 ));then
- echo "Keyfile doesn't have enough layers to be an onion"
- exit 1
+ die "Keyfile doesn't have enough layers to be an onion"
fi
if [[ "$mode" == e ]];then
fi
if (( $# != 1));then
- echo "usage: overonion-make-key keyfile"
+ echo "usage: overonion-make-key keyfile" >&2
exit 1
fi
keyfile=$1
if [[ -e "$keyfile" ]];then
- echo "That keyfile already exists. I refuse to overwrite it."
+ echo "That keyfile already exists. I refuse to overwrite it." >&2
exit 1
fi
i=0
while read -r cipher;do
- echo -n $'\r'"Generating key $((++i))/${#ciphers[*]}"
+ echo -n $'\r'"Generating key $((++i))/${#ciphers[*]}" >&2
cat >> "$keyfile" <<< "$cipher $(head -c 99 "$random_source" | base64 --wrap=0 )"
done < <( IFS=$'\n'; shuf <<< "${ciphers[*]}"; )
-echo
+echo >&2