Initial commit - passino - password-store clone in POSIX shell script
HTML hg clone https://bitbucket.org/iamleot/passino
DIR Log
DIR Files
DIR Refs
---
DIR changeset f0b48f93ba3a9de7d4a5977ad6742aa838af225c
HTML Author: Leonardo Taccari <iamleot@gmail.com>
Date: Mon, 17 Jun 2019 18:49:58
Initial commit
Diffstat:
passino.sh | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 149 insertions(+), 0 deletions(-)
---
diff -r 000000000000 -r f0b48f93ba3a passino.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/passino.sh Mon Jun 17 18:49:58 2019 +0200
@@ -0,0 +1,149 @@
+#!/bin/sh
+
+
+umask 077
+
+editor=${EDITOR:=vi}
+gpg=gpg2
+password_store_dir=${PASSWORD_STORE_DIR:=${HOME}/.password-store}
+
+
+#
+# Print usage message and exit
+#
+usage()
+{
+ echo "usage: passino edit|help|list|show"
+
+ exit 1
+}
+
+
+#
+# Print help message and exit
+#
+help()
+{
+ echo "usage: passino edit|help|ls|show"
+ echo
+ echo "e|ed|edit passname"
+ echo "Edit the password \`passname'."
+ echo
+ echo "h|help"
+ echo "Show an help message"
+ echo
+ echo "l|ls|list"
+ echo "List all passwords"
+ echo
+ echo "s|show passname"
+ echo "Print the password \`passname' to the stdout."
+ echo
+
+ exit 1
+}
+
+
+#
+# Invoke GPG to decrypt stdin
+#
+decrypt()
+{
+
+ ${gpg} -q -d
+}
+
+
+#
+# Invoke GPG to encrypt stdin
+#
+encrypt()
+{
+
+ ${gpg} -q -e --default-recipient-self
+}
+
+
+#
+# Edit the password passname.
+#
+edit()
+{
+ passname=$1
+ passfile="${password_store_dir}/${passname}.gpg"
+
+ if [ -z "${passname}" ]; then
+ return
+ fi
+
+ tmpfile=`mktemp -t passino` || return
+
+ if [ -f "${passfile}" ]; then
+ decrypt < "${passfile}" > "${tmpfile}"
+ fi
+
+ ${EDITOR} "${tmpfile}"
+ encrypt < "${tmpfile}" > "${passfile}"
+ rm -f "${tmpfile}"
+}
+
+#
+# List all passwords
+#
+list()
+{
+
+ find ${password_store_dir} -name '*.gpg' |
+ sed -e "s;^${password_store_dir};;" \
+ -e 's;^/;;' \
+ -e 's;\.gpg$;;' |
+ sort
+}
+
+
+#
+# Decrypt the password passname and print it to stdout.
+#
+show()
+{
+ passname=$1
+ passfile="${password_store_dir}/${passname}.gpg"
+
+ if [ -z "${passname}" ] || [ ! -f "${passfile}" ]; then
+ return
+ fi
+
+ decrypt < "${passfile}"
+}
+
+
+#
+# passino, a password-store clone in POSIX shell script
+#
+main()
+{
+ subcommand=$1
+
+ case $subcommand in
+ e|ed|edit)
+ passname=$2
+ edit "${passname}"
+ ;;
+ h|help)
+ help
+ ;;
+ l|ls|list)
+ list
+ ;;
+ s|show)
+ passname=$2
+ show "${passname}"
+ ;;
+ *)
+ usage
+ ;;
+ esac
+
+ exit 0
+}
+
+main "$@"