From 704340d796609a8773bc37711deebdf78295a633 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 27 Oct 2023 17:28:25 +0200 Subject: [PATCH] Added secret export feature for restic-backup.sh --- restic-backup.sh | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/restic-backup.sh b/restic-backup.sh index 7c32ac6..181ae11 100755 --- a/restic-backup.sh +++ b/restic-backup.sh @@ -16,12 +16,13 @@ ## NAME="restic-backup.sh" -VERSION="0.2.1" +VERSION="0.2.2" AUTHOR="david@socialnerds.org" LICENSE="MIT" DESCRIPTION="A simple script to help setup and run periodic Restic backup jobs." WEBSITE="https://git.socialnerds.org/david/scripts" -CHANGELOG=("[2023-10-27][v0.2.1] Better Healthchecks integration" +CHANGELOG=("[2023-10-27][v0.2.2] Added secret export option" + "[2023-10-27][v0.2.1] Better Healthchecks integration" "[2023-10-26][v0.2.0] Complete rewrite" "[2022-01-01][v0.1.0] Initial version") @@ -54,15 +55,25 @@ SNAPSHOTS=32 # Print help information function print_help() { - printf "%s\n\n%s\n%b\n\n%s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n" \ + printf "%s\n\n%s\n%b\n\n%s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n" \ "$DESCRIPTION" "Usage:" "$LIB_BOLD$EXECUTABLE $LIB_CLEAR" "Options:" \ "-c, --checks" "Enable Healthchecks" \ + "-s, --secret" "Print secret(s) and exit" \ "-h, --help" "Print help screen and exit" \ "-i, --info" "Print script information and exit" \ "-v, --verbose" "More verbose output" \ "-q, --quiet" "No output except errors (overrides -v)" } +# Print secret(s) to easily c/p it to your password manager +function print_secret() { + printf "%13s %b\n" "Password:" "$LIB_RED$LIB_RED_BG$(cat $PASSWORD)$LIB_CLEAR" + printf "%13s %b\n" "Repository:" "$LIB_RED$LIB_RED_BG$(cat $REPOSITORY)$LIB_CLEAR" + if [[ -s $HEALTHCHECKS ]]; then + printf "%13s %b\n" "Healthchecks:" "$LIB_RED$LIB_RED_BG$(cat $HEALTHCHECKS)$LIB_CLEAR" + fi +} + ## ## Preflight @@ -105,6 +116,9 @@ while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do -c|--checks) C=1 ;; + -s|--secret) + S=1 + ;; -h|--help) H=1 ;; @@ -136,6 +150,9 @@ if [[ $I -eq 1 ]]; then elif [[ $H -eq 1 ]]; then print_help exit 0 +elif [[ $S -eq 1 ]]; then + print_secret + exit 0 fi if [[ -z "$1" ]]; then