From 60052659b98832c78c902e4f27ecee2663d8e913 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 6 May 2026 08:30:49 +0200 Subject: Added scripts --- scripts/secret | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 scripts/secret (limited to 'scripts/secret') diff --git a/scripts/secret b/scripts/secret new file mode 100755 index 0000000..14ec2e0 --- /dev/null +++ b/scripts/secret @@ -0,0 +1,52 @@ +#!/bin/sh + +# Encrypt and decrypt files using a fixed cipher and passphrase. +# The first line of the (unencrypted) file is considered the "password", +# the rest can be anything. + +# Usage: secret command file +# Available commands: +# clip: copy the secret to clipboard; deleted after 10 seconds +# edit: edit or add a file +# show: show the full encrypted file + +# Requires: openssl, xsel (for clip only) + +# ksh completion +# set -A complete_sel_1 clip edit show +# set -A complete_sel_2 box/secret + +opts="aes-256-cbc -iter 1000" # options for openssl +timeout=10 # timeout for clip, in ms +editor=${EDITOR:-vi} + +if [ -z "$1" ] || [ -z "$2" ]; then + echo "usage: secret command file" +else +case "$1" in + clip) + openssl $opts -d < "$2" | head -n 1 | xargs printf "%s" | xsel -ib + sleep $timeout && xsel -db & + ;; + edit) + tempfile=$(mktemp) + if [ -f "$2" ]; then + openssl $opts -d < "$2" > "$tempfile" + fi + $editor "$tempfile" + read -p "Are you sure? [N/yes] " an + if [ "$an" = yes ] || [ "$an" = Yes ] || [ "$an" = YES ]; then + openssl $opts < "$tempfile" > "$2" + else + echo "Changes discarded" + fi + rm "$tempfile" + ;; + show) + openssl $opts -d < "$2" + ;; + *) + echo "$1: not a valid command" + ;; +esac +fi -- cgit v1.3