Makefile: add pickrand
[cmccabe-bin] / dec.sh
1 #!/usr/bin/env bash
2
3 die() {
4     echo $@
5     exit 1
6 }
7
8 [ "x${SALT}" = "x" ] && die "you must set SALT to the salt."
9 [ "x${PASS}" = "x" ] && die "you must set PASS to the password"
10
11 RET=0
12 for FILE in "$@"; do
13     if [[ "${FILE}" = *.nc ]]; then
14         BASE_FILE="$(dirname ${FILE})/$(basename ${FILE} .nc)"
15         if [ -e "${BASE_FILE}" ]; then
16             echo "Not decrypting $FILE because there is already a ${BASE_FILE}"
17         else
18             if openssl enc -d -aes-256-ecb \
19                     -S "$SALT" \
20                     -k "$PASS" < "${FILE}" > "${BASE_FILE}"; then
21                 echo "Created ${BASE_FILE}"
22             else
23                 echo "Failed to create ${BASE_FILE}"
24                 RET=1
25             fi
26         fi
27     else
28         echo "Not decrypting $FILE because its name does not end in .nc"
29     fi
30 done
31 exit $RET