Makefile: add pickrand
[cmccabe-bin] / dec.sh
1 #!/usr/bin/env bash
2
3 die() {
4     echo $@
5     exit 1
6 }
7
8 if [[ "x${PASS}" = "x" ]]; then
9     read -s -p "enter password: " PASS
10 fi
11
12 RET=0
13 for FILE in "$@"; do
14     if [[ "${FILE}" = *.nc ]]; then
15         BASE_FILE="$(dirname ${FILE})/$(basename ${FILE} .nc)"
16         if [ -e "${BASE_FILE}" ]; then
17             echo "Not decrypting $FILE because there is already a ${BASE_FILE}"
18         else
19             if openssl enc -d -aes-256-ecb \
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