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