summaryrefslogtreecommitdiff
path: root/scripts/secret
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-05-06 08:30:49 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2026-05-06 08:30:49 +0200
commit60052659b98832c78c902e4f27ecee2663d8e913 (patch)
tree9efc1388569c43456557aa1975b4bec99bf06c94 /scripts/secret
parent10e16c2fb2266bb2b46ec7ea64d721de0c29a0d9 (diff)
downloadconfig-60052659b98832c78c902e4f27ecee2663d8e913.tar.gz
config-60052659b98832c78c902e4f27ecee2663d8e913.zip
Added scripts
Diffstat (limited to 'scripts/secret')
-rwxr-xr-xscripts/secret52
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/secret b/scripts/secret
new file mode 100755
index 0000000..14ec2e0
--- /dev/null
+++ b/scripts/secret
@@ -0,0 +1,52 @@
1#!/bin/sh
2
3# Encrypt and decrypt files using a fixed cipher and passphrase.
4# The first line of the (unencrypted) file is considered the "password",
5# the rest can be anything.
6
7# Usage: secret command file
8# Available commands:
9# clip: copy the secret to clipboard; deleted after 10 seconds
10# edit: edit or add a file
11# show: show the full encrypted file
12
13# Requires: openssl, xsel (for clip only)
14
15# ksh completion
16# set -A complete_sel_1 clip edit show
17# set -A complete_sel_2 box/secret
18
19opts="aes-256-cbc -iter 1000" # options for openssl
20timeout=10 # timeout for clip, in ms
21editor=${EDITOR:-vi}
22
23if [ -z "$1" ] || [ -z "$2" ]; then
24 echo "usage: secret command file"
25else
26case "$1" in
27 clip)
28 openssl $opts -d < "$2" | head -n 1 | xargs printf "%s" | xsel -ib
29 sleep $timeout && xsel -db &
30 ;;
31 edit)
32 tempfile=$(mktemp)
33 if [ -f "$2" ]; then
34 openssl $opts -d < "$2" > "$tempfile"
35 fi
36 $editor "$tempfile"
37 read -p "Are you sure? [N/yes] " an
38 if [ "$an" = yes ] || [ "$an" = Yes ] || [ "$an" = YES ]; then
39 openssl $opts < "$tempfile" > "$2"
40 else
41 echo "Changes discarded"
42 fi
43 rm "$tempfile"
44 ;;
45 show)
46 openssl $opts -d < "$2"
47 ;;
48 *)
49 echo "$1: not a valid command"
50 ;;
51esac
52fi

Generated with cgit - Back to sebastiano.tronto.net