From e71a6eb321d0260fc88a5232f8c4f6e628905b57 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 3 Dec 2020 00:18:11 +0000 Subject: [PATCH] sekrit: add rm command While at it, fix a typo. --- bin/sekrit.1 | 13 ++++++++++++- bin/sekrit.sh | 28 +++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/bin/sekrit.1 b/bin/sekrit.1 index 3dfe000..20dd215 100644 --- a/bin/sekrit.1 +++ b/bin/sekrit.1 @@ -38,6 +38,11 @@ .Nm .Cm ls .Op Ar keys ... +.Nm +.Cm rm +.Op Fl f +.Ar key +.Op Ar key ... .Sh DESCRIPTION .Nm is a small shell script for managing encrypted files. @@ -104,7 +109,13 @@ given as argument, list all the registered keys under that hierarchy. If no .Ar key -is given, list all the registeres keys. +is given, list all the registered keys. +.It Nm Cm rm Oo Fl f Oc Ar key Op Ar key ... +Removes the file associated with each +.Ar key . +Asks for confirmation before removing each file, unless +.Fl f +is given. .El .Sh ENVIRONMENT .Bl -tag -width SEKRIT_GPG_ID diff --git a/bin/sekrit.sh b/bin/sekrit.sh index 150cad1..32b8f27 100644 --- a/bin/sekrit.sh +++ b/bin/sekrit.sh @@ -35,6 +35,7 @@ Usage: ${0##*/} get key ${0##*/} has key ${0##*/} ls [keys ...] + ${0##*/} rm [-f] key [key ...] If no value was provided on command line, add reads from stdin. . @@ -116,8 +117,8 @@ sekrit_cp() sekrit_gen() { - len=43 OPTIND=1 + len=43 while getopts l: flag; do case "$flag" in l) len=$(to_number "$OPTARG") || @@ -179,6 +180,30 @@ sekrit_ls() fi } +sekrit_rm() +{ + OPTIND=1 + fflag= + while getopts f flag; do + case "$flag" in + f) fflag=-f ;; + *) usage ;; + esac + done + shift $((OPTIND - 1)) + + [ $# -ge 1 ] || usage + + for key; do + path=$(make_key_path "$key") + if [ ! -f "$path" ]; then + printf "%s: no data for key %s\n" "${0##*/}" "$key" >&2 + else + rm -i $fflag "$path" + fi + done +} + set -e [ $# -ge 1 ] || usage @@ -198,5 +223,6 @@ gen) sekrit_gen "$@" ;; get) sekrit_get "$@" ;; has) sekrit_has "$@" ;; ls) sekrit_ls "$@" ;; +rm) sekrit_rm "$@" ;; *) usage ;; esac