Make update-bitwarden.sh able to run non-interactive (#90)

* make update-bitwarden.sh able to run non-interactive

* changed script to be runnable by bash 3.x & README entry edited
This commit is contained in:
p0thi
2021-01-27 14:51:13 +01:00
committed by GitHub
parent 7ddf01fdf6
commit 59ee2e3c3a
2 changed files with 23 additions and 4 deletions

View File

@@ -1,4 +1,12 @@
#!/bin/bash
ask () {
local __resultVar=$1
local __result="$2"
if [ -z "$2" ]; then
read -p "$3" __result
fi
eval $__resultVar="'$__result'"
}
SCRIPT_BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BW_VERSION="$(curl --silent https://raw.githubusercontent.com/bitwarden/server/master/scripts/bitwarden.sh | grep 'COREVERSION="' | sed 's/^[^"]*"//; s/".*//')"
@@ -8,8 +16,8 @@ echo "Starting Bitwarden update, newest server version: $BW_VERSION"
# Default path is the parent directory of the BitBetter location
BITWARDEN_BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )"
# Get Bitwarden base from user (or keep default value)
read -p "Enter Bitwarden base directory [$BITWARDEN_BASE]: " tmpbase
# Get Bitwarden base from user (or keep default value) or use first argument
ask tmpbase "$1" "Enter Bitwarden base directory [$BITWARDEN_BASE]: "
BITWARDEN_BASE=${tmpbase:-$BITWARDEN_BASE}
# Check if directory exists and is valid
@@ -18,7 +26,7 @@ BITWARDEN_BASE=${tmpbase:-$BITWARDEN_BASE}
# Check if user wants to recreate the docker-compose override file
RECREATE_OV="y"
read -p "Rebuild docker-compose override? [Y/n]: " tmprecreate
ask tmprecreate "$2" "Rebuild docker-compose override? [Y/n]: "
RECREATE_OV=${tmprecreate:-$RECREATE_OV}
if [[ $RECREATE_OV =~ ^[Yy]$ ]]
@@ -48,7 +56,7 @@ if [ $retval -ne 0 ]; then
REBUILD_BB="y"
REBUILD_BB_DESCR="[Y/n]"
fi
read -p "Rebuild BitBetter images? $REBUILD_BB_DESCR: " tmprebuild
ask tmprebuild "$3" "Rebuild BitBetter images? $REBUILD_BB_DESCR: "
REBUILD_BB=${tmprebuild:-$REBUILD_BB}
if [[ $REBUILD_BB =~ ^[Yy]$ ]]