From 17ecb79c0868f6405f259f01f5dd7578e068a683 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Wed, 4 Jun 2025 20:03:28 +0100 Subject: add a 'cert' command to manage certificates --- cert.sh.in | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 cert.sh.in (limited to 'cert.sh.in') diff --git a/cert.sh.in b/cert.sh.in new file mode 100644 index 0000000..0ac8224 --- /dev/null +++ b/cert.sh.in @@ -0,0 +1,83 @@ +#! /bin/sh +# This source code is released into the public domain. + +_c_list() { + if ! [ -d "$_UACME_DIR" ]; then + return 0 + fi + + local _certs="$(cd $_UACME_DIR && ls)" + local cert + for cert in $_certs; do + if [ "$cert" = "private" ]; then + continue + fi + + printf '%s\n' "$cert" + done + + return 0 +} + +_c_remove() { + if [ -z "$1" ]; then + _fatal "missing certificate name" + fi + + local cert + for cert in "$@"; do + local _path="${_UACME_DIR}/${cert}" + + if ! [ -d "$_path" ]; then + _warn "certificate not found: %s" "$cert" + continue + fi + + # Just in case... + if [ "${_path##*/}" = "" ]; then + _fatal "internal error" + fi + + rm -rf "$_path" + done +} + +# Parse command-line arguments. +args=$(getopt "" $*) +if [ $? -ne 0 ]; then + exit 1 +fi +set -- $args + +_uacme_flags="" + +while :; do + case "$1" in + -y) + _uacme_flags="$_uacme_flags $1" + shift;; + --) + shift; break;; + esac +done + +_command="$1"; shift +if [ -z "$_command" ]; then + _fatal "missing command" +fi + +case "$_command" in +list) + _c_list "$@" + exit $? + ;; + +remove) + _c_remove "$@" + exit $? + ;; + +*) + _fatal "unknown command: %s" "$_command" + ;; +esac -- cgit v1.2.3