cem-utils

Random utilities
git clone git://git.ckyln.com/~cem/cem-utils.git
Log | Files | Refs | README

commit 858a8e8189cb8d6415a029b53ea7f53eec603988
parent 58723a3fe8d3c0730dc6bb624ff76bf74912adc8
Author: Cem Keylan <cem@ckyln.com>
Date:   Wed, 19 Feb 2020 18:30:00 +0300

add pm

Diffstat:
MREADME.md | 70+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Apm/Makefile | 10++++++++++
Apm/pm | 36++++++++++++++++++++++++++++++++++++
3 files changed, 115 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md @@ -18,11 +18,21 @@ there this is not a big repository, but I will be publishing other utilities, once I sort everything out. -Here is the list of programs: +Not all of my utilities are here at the moment. Some +are on my main computer that I cannot reach at the +moment. Some live on my dotfiles (I will be updating +my dotfiles for Carbs Linux someday I promise). I will +also be merging my useless utilities that are currently +on individual repositories here. + +Below are explanations per utility and here is the +small list of programs: + * nap * nap-hooks * dwm-notify-send +* pm nap @@ -91,5 +101,63 @@ To install run, as root if necessary This will install `notify-send` and `kill-notification` to `/usr/local/bin` + +pm +-- + +Dumb password manager with absolutely no fancy features. By +that I mean, + +* No password generation +* No git integration +* No questions asked +* No grepping/finding passwords +* No clipboard support +* No tree view +* Does not ask for password input (reads from stdin) + +Currently 34 SLOC. Supports adding/deleting/listing/showing +passwords. I don't intend on implementing any more features. +You can wrap this script with something other to make use of +it. + +To install run, as root if necessary + + make -C pm install + +You really do think that asking for password for twice blah +blah is a really important feature? Okay, then add a function +to your shellrc/profile like this. + + pmask() { + [ "$1" ] || return 1 + printf 'Enter your password: ' + read pass + printf 'Enter your password again: ' + read pass2 + if [ "$pass" = "$pass2" ] ; then + printf '%s' "$pass" | pm a "$1" + else + printf "Passwords don't match\n" + return 1 + fi + } + +You want to copy to clipboard? That's easy! You just need +to do a `pm s passname | xclip -sel c`. You can still make +it a function by doing this + + copypass() { + [ "$1" ] || return 1 + pm s "$1" | xclip -sel c + } + +The whole rationale is that you can already do that with simple +commands. Why complicate (and possibly break) things by introducing +them into a single script? If you want some function that is +a must for you, implement it yourself with some script or +a shell function. This way, it works just as you intended it. + + [1]: http://git.vuxu.org/runit-void/tree/zzz [2]: https://github.com/bahamas10/zzz-user-hooks diff --git a/pm/Makefile b/pm/Makefile @@ -0,0 +1,10 @@ +PREFIX = /usr/local +BINDIR = ${PREFIX}/bin + +install: + install -Dm755 -t ${DESTDIR}${BINDIR} pm + +uninstall: + rm -f ${DESTDIR}${BINDIR}/pm + +.PHONY: install uninstall diff --git a/pm/pm b/pm/pm @@ -0,0 +1,36 @@ +#!/bin/sh +error() { printf '\033[1;31m!> \033[merror: %s\n' "$@" >&2 ;} +die() { error "$1" ; exit 1 ;} + +PM_DIR="${PM_DIR:-$HOME/.local/share/pm}" +usage() { printf '\033[1;36m-> \033[m%s\n' "usage: ${0##*/} [a|d|l|s] [options]" "" \ + "[a]dd <name> - Reads the password from stdin to the given entry" \ + "[d]el <name> - Deletes given enry" \ + "[l]ist - Lists all the passwords" \ + "[s]how <name> - Shows the given password" "" \ + "VARIABLES:" "PM_DIR: $PM_DIR" "PM_GPG_USER: $PM_GPG_USER" ; exit "${1:-0}" ;} + +gpg="$(command -v gpg2 || command -v gpg)" || die "gnupg cannot be found" +case "$1" in + a|add) + [ "$2" ] || usage 1 + [ "$PM_GPG_USER" ] || die "Please set a \$PM_GPG_USER variable" + [ -e "$PM_DIR/$2.asc" ] && die "an entry for $2 already exists" + mkdir -p "$PM_DIR" + tr -d '\n' < /dev/stdin > "$PM_DIR/$2" + "$gpg" -e -a -r "$PM_GPG_USER" -- "$PM_DIR/$2" || + error "Could not encrypt password" + rm -f "$PM_DIR/$2" + ;; + d|del) [ "$2" ] || usage 1 ; rm -f "$PM_DIR/$2.asc" ;; + l|list) + find "$PM_DIR" -type f -name '*.asc' 2>/dev/null || ls -1 "$PM_DIR" + ;; + s|show) + [ "$2" ] || usage 1 + [ -r "$PM_DIR/$2.asc" ] || + die "Entry for $2 doesn't exist or is not readable" + "$gpg" --decrypt "$PM_DIR/$2.asc" 2>/dev/null | tr -d '\n' || + die "Could not decrypt $PM_DIR/$2.asc" + ;; + *) usage 0 ;; esac