From: Colin P. Mccabe Date: Mon, 2 Apr 2018 00:53:37 +0000 (-0700) Subject: Add passtool.sh X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=793f16b844ad0ac63d3962693e4e13e930068c25;p=cmccabe-bin Add passtool.sh --- diff --git a/passtool.sh b/passtool.sh new file mode 100755 index 0000000..552568e --- /dev/null +++ b/passtool.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +die() { + echo $1 + exit 1 +} + +usage() +{ + cat < "${TEMPFILE}"; then + if [[ -z ${SEARCH_PATTERN} ]]; then + ${EDITOR} "${TEMPFILE}" + openssl enc -aes-256-ecb -k "${PASSWORD}" -salt \ + < "${TEMPFILE}" > "${TEMPFILE_ENC}" || + die "Re-encryption failed. Changes lost." + mv -f "${TEMPFILE_ENC}" "${PASSWORD_PATH}" || \ + die "failed to move ${TEMPFILE_ENC} to ${PASSWORD_PATH}: changes lost." + else + echo + egrep ${SEARCH_PATTERN} "${TEMPFILE}" + fi +else + die "Failed to decrypt ${PASSWORD_PATH}. Was the password correct?" +fi