From 0d2fe132d3abd71f9a9320c68978b61d44a63b0d Mon Sep 17 00:00:00 2001 From: Daniel Dolezal Date: Fri, 1 Jul 2022 17:55:24 +0200 Subject: [PATCH] move variables and add password ask for borg backup --- .bashrc | 37 ++++++++++++++++++++++++++++++++++--- Dockerfile | 1 + entrypoint.sh | 4 +--- variables.sh | 3 +++ 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 variables.sh diff --git a/.bashrc b/.bashrc index 8cdc6c0..e04a4c4 100644 --- a/.bashrc +++ b/.bashrc @@ -14,16 +14,19 @@ export PS1="\[\e[31m\][\[\e[m\]\[\e[38;5;172m\]\u\[\e[m\]@\[\e[38;5;153m\]\h\[\e ############################################################################################################################## # Borg Repo finder ############################################################################################################################## +source "/variables.sh" + function sepurator { - echo "===============================================================================" + echo "==============================================================================================" } function find_borg_repo { repo_list=( $(find "$1" -name "index.*" -type f | rev | cut -d '/' -f "2-" | rev) ) if [ -z "$repo_list" ]; then + sepurator echo "* Can not find borg repository" - exit 1 + sepurator else sepurator echo "* Select borg repository" @@ -61,9 +64,37 @@ function select_borg_repo { fi done fi + sepurator +} + +function ask_for_repo_password { + if grep -q 'key' "$BORG_REPO/config"; then + echo "* BORG REPO has a password" + sepurator + echo "(you can leave it empty if you not like to export BORG_PASSPHRASE)" + read -s -p "Please enter password: " BORG_REPO_PASSWORD + echo "" + if [ "$BORG_REPO_PASSWORD" != "" ]; then + export BORG_PASSPHRASE="$BORG_REPO_PASSWORD" + fi + else + echo "* BORG REPO has no password" + fi + sepurator +} + +function print_container_info { + sepurator + echo "BorgServer powered by $BORG_VERSION - Image Hostname: $HOSTNAME | Image Version: $DOCKER_IMAGE_VERSION" + sepurator } find_borg_repo backups/ export BORG_REPO="${repo_list[selected_repo]}" -clear +if [ ! -z "$BORG_REPO" ]; then + ask_for_repo_password + clear +fi + +print_container_info neofetch diff --git a/Dockerfile b/Dockerfile index 4a369b1..1bc8269 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,7 @@ VOLUME ["/sshkeys/host"] COPY motd.txt /etc/motd COPY entrypoint.sh / +COPY variables.sh / COPY .bash_profile /root/ COPY .bashrc /root/ diff --git a/entrypoint.sh b/entrypoint.sh index c46cf36..34c4be8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,5 @@ #!/bin/bash -DOCKER_IMAGE_VERSION="1.0.8" -BORG_VERSION=$(borg -V) -SSH_FOLDERS=( /sshkeys/clients /sshkeys/host ) +source "/variables.sh" ############################################################################################################################## # Funktionen ############################################################################################################################## diff --git a/variables.sh b/variables.sh new file mode 100644 index 0000000..f504de7 --- /dev/null +++ b/variables.sh @@ -0,0 +1,3 @@ +DOCKER_IMAGE_VERSION="1.0.9" +BORG_VERSION=$(borg -V) +SSH_FOLDERS=( /sshkeys/clients /sshkeys/host )