diff options
| author | Igor Soarez <igor@soarez.org> | 2026-09-17 19:45:23 +0100 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-09-17 19:45:23 +0100 |
| commit | 13cc065ec014b86369dfe4ad60d1a43fa06fd251 (patch) | |
| tree | 684690c61b7b59758c2aac132c65b81c86de0608 /secrets/main.sh | |
dotfiles
Shell, editor and terminal configuration, the tools that go with them, and
szecret, an age-based secret manager whose store lives elsewhere.
History restarts here. What came before was not written to be read by
anyone else, and carried machine names, addresses and an encrypted secret
store; it is kept privately instead. What is left is meant to be safe on
any machine, including one whose owner is not me: see CLAUDE.md for the
rule it is written to.
Diffstat (limited to 'secrets/main.sh')
| -rwxr-xr-x | secrets/main.sh | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/secrets/main.sh b/secrets/main.sh new file mode 100755 index 0000000..89bbea3 --- /dev/null +++ b/secrets/main.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +set -euo pipefail + +this_dir="$(cd "$(dirname "$(realpath "$0")")" && pwd)" + +# list all commands, name only +cmds() { + find "${this_dir}" -maxdepth 1 -type f -name '*.sh' -print0 \ + | xargs -0 -n 1 basename \ + | sed 's/\.sh$//' \ + | grep -Ev '^(main|common)$' \ + | sort +} + +# list all commands, name and description +cmd_descriptions() { + for cmd in $(cmds); do + local cmd_sh="${this_dir}/${cmd}.sh" + if [[ -x "${cmd_sh}" ]]; then + local description + description="$(bash "${cmd_sh}" -h 2>/dev/null | head -1 | sed 's/^[^:]*: *//')" + if [[ -n "${description}" ]]; then + printf "%-15s %s\n" "${cmd}" "${description}" + else + printf "%-15s\n" "${cmd}" + fi + fi + done +} + +if [[ "$#" -gt 0 && ("$1" == "-h" || "$1" == "--help") ]]; then + cat <<EOF +szecret: Secret management using age encryption + +Usage: + szecret -h|--help + szecret <command> -h|--help + szecret <command> [args...] + +Available commands: + +$(cmd_descriptions | sed 's/^/ /') +EOF + exit 0 +fi + +# check number of arguments > 1, error and exit if not +# extract first argument, call script with same name using remaining arguments +if [ $# -lt 1 ]; then + >&2 cat <<EOF +ERROR: no command specified. Available: + +$(cmd_descriptions | sed 's/^/ /') +EOF + exit 1 +fi + +cmd="$1" +cmd_sh="${this_dir}/${cmd}.sh" +shift + +if [[ ! -e "${cmd_sh}" ]]; then + >&2 echo "ERROR: no command named ${cmd}. Available: $(cmds | paste -sd ',' -)" + exit 1 +fi + +exec bash "${cmd_sh}" "$@" + |
