Makefile: add pickrand
[cmccabe-bin] / enc.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         echo "Not encrypting ${FILE} because its name already ends in .nc"
15     else
16         NEW_FILE="${FILE}.nc"
17         if [ -e "${NEW_FILE}" ]; then
18             echo "Not encrypting ${FILE} because there is already a ${NEW_FILE}"
19         else
20             if openssl enc -aes-256-ecb \
21                     -S "${SALT}" \
22                     -k "${PASS}" < "${FILE}" > "${NEW_FILE}"; then
23                 echo "Created ${NEW_FILE}"
24             else
25                 echo "Failed to create ${NEW_FILE}"
26                 RET=1
27             fi
28         fi
29     fi
30 done
31 exit $RET