From ce90d7da2359f71c4cf139c4a4af8b0a1ae4a4e4 Mon Sep 17 00:00:00 2001 From: tteckster Date: Sat, 31 Dec 2022 07:39:25 -0500 Subject: [PATCH] Update and rename vaultwarden-v4.sh to vaultwarden-v5.sh --- ct/{vaultwarden-v4.sh => vaultwarden-v5.sh} | 130 +++++++++++++++++--- 1 file changed, 111 insertions(+), 19 deletions(-) rename ct/{vaultwarden-v4.sh => vaultwarden-v5.sh} (77%) diff --git a/ct/vaultwarden-v4.sh b/ct/vaultwarden-v5.sh similarity index 77% rename from ct/vaultwarden-v4.sh rename to ct/vaultwarden-v5.sh index 9e5ffc70..03dbef93 100644 --- a/ct/vaultwarden-v4.sh +++ b/ct/vaultwarden-v5.sh @@ -1,4 +1,14 @@ #!/usr/bin/env bash +function header_info { + cat <<"EOF" + _ __ ____ _ __ __ +| | / /___ ___v5__/ / /| | / /___ __________/ /__ ____ +| | / / __ `/ / / / / __/ | /| / / __ `/ ___/ __ / _ \/ __ \ +| |/ / /_/ / /_/ / / /_ | |/ |/ / /_/ / / / /_/ / __/ / / / +|___/\__,_/\__,_/_/\__/ |__/|__/\__,_/_/ \__,_/\___/_/ /_/ + +EOF +} echo -e "Loading..." APP="Vaultwarden" var_disk="6" @@ -8,7 +18,6 @@ var_os="debian" var_version="11" NSAPP=$(echo ${APP,,} | tr -d ' ') var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) INTEGER='^[0-9]+$' YW=$(echo "\033[33m") BL=$(echo "\033[36m") @@ -20,6 +29,7 @@ CL=$(echo "\033[m") BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" +CROSS="${RD}✗${CL}" set -o errexit set -o errtrace set -o nounset @@ -35,30 +45,22 @@ function error_exit() { echo -e "$flag $msg" 1>&2 exit $EXIT } -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${CL} - _ _____ __ ____ _______ _____ ____ ____ _______ __ -| | / / | / / / / / /_ __/ | / / | / __ \/ __ \/ ____/ | / / -| | / / /| |/ / / / / / / | | /| / / /| | / /_/ / / / / __/ / |/ / -| |/ / ___ / /_/ / /___/ / | |/ |/ / ___ |/ _, _/ /_/ / /___/ /| / -|___/_/ |_\____/_____/_/ v4 |__/|__/_/ |_/_/ |_/_____/_____/_/ |_/ -${CL}" -} + function msg_info() { local msg="$1" echo -ne " ${HOLD} ${YW}${msg}..." } + function msg_ok() { local msg="$1" echo -e "${BFR} ${CM} ${GN}${msg}${CL}" } + +function msg_error() { + local msg="$1" + echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" +} + function PVE_CHECK() { PVE=$(pveversion | grep "pve-manager/7" | wc -l) if [[ $PVE != 1 ]]; then @@ -68,6 +70,28 @@ function PVE_CHECK() { exit fi } +if command -v pveversion >/dev/null 2>&1; then + if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then + NEXTID=$(pvesh get /cluster/nextid) + else + clear + echo -e "⚠ User exited script \n" + exit + fi +fi +if ! command -v pveversion >/dev/null 2>&1; then + if [[ ! -d /opt/vaultwarden ]]; then + msg_error "No ${APP} Installation Found!"; + exit + fi + if (whiptail --title "${APP} LXC UPDATE" --yesno "This will update ${APP}. Proceed?" 10 58); then + echo "User selected Update" + else + clear + echo -e "⚠ User exited script \n" + exit + fi +fi function default_settings() { echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" CT_TYPE="1" @@ -101,6 +125,7 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" + VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -253,9 +278,11 @@ function advanced_settings() { if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" VERB="yes" + VERB2="" else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" + VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -266,7 +293,7 @@ function advanced_settings() { advanced_settings fi } -function start_script() { +function install_script() { if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then header_info echo -e "${BL}Using Default Settings${CL}" @@ -277,8 +304,72 @@ function start_script() { advanced_settings fi } + +function update_script() { +UPD=$(whiptail --title "UPDATE" --radiolist --cancel-button Exit-Script "Choose Type" 8 58 2 \ + "1" "VaultWarden" ON \ + "2" "Web-Vault" OFF \ + 3>&1 1>&2 2>&3) + clear -start_script +header_info +echo -e "\n ⚠️ Ensure you set 2vCPU & 3072MiB RAM MIMIMUM!!! \n" +if [ "$UPD" == "1" ]; then +msg_info "Stopping Vaultwarden" +systemctl stop vaultwarden.service +msg_ok "Stopped Vaultwarden" + +msg_info "Updating VaultWarden (Patience)" +git clone https://github.com/dani-garcia/vaultwarden &>/dev/null +cd vaultwarden +cargo build --features "sqlite,mysql,postgresql" --release &>/dev/null +DIR=/usr/bin/vaultwarden + if [ -d "$DIR" ]; then + cp target/release/vaultwarden /usr/bin/ + else + cp target/release/vaultwarden /opt/vaultwarden/bin/ + fi +msg_ok "Updated VaultWarden" + +msg_info "Cleaning up" +cd ~ && rm -rf vaultwarden +msg_ok "Cleaned" + +msg_info "Starting Vaultwarden" +systemctl start vaultwarden.service +msg_ok "Started Vaultwarden" + +msg_ok "Update Successful" +echo -e "\n ⚠️ Ensure you set resources back to normal settings \n" +exit; +fi +if [ "$UPD" == "2" ]; then +msg_info "Stopping Vaultwarden" +systemctl stop vaultwarden.service +msg_ok "Stopped Vaultwarden" + +msg_info "Updating Web-Vault" +curl -fsSLO https://github.com/dani-garcia/bw_web_builds/releases/download/$VWRELEASE/bw_web_$VWRELEASE.tar.gz &>/dev/null + if [ -d "/var/lib/vaultwarden" ]; then + tar -xzf bw_web_$VWRELEASE.tar.gz -C /var/lib/vaultwarden/ &>/dev/null + else + tar -zxf bw_web_$VWRELEASE.tar.gz -C /opt/vaultwarden/ &>/dev/null + fi +msg_ok "Updated Web-Vault" + +msg_info "Cleaning up" +rm bw_web_$VWRELEASE.tar.gz +msg_ok "Cleaned" + +msg_info "Starting Vaultwarden" +systemctl start vaultwarden.service +msg_ok "Started Vaultwarden" +msg_ok "Update Successful" +exit; +fi +} +clear +if ! command -v pveversion >/dev/null 2>&1; then update_script; else install_script; fi if [ "$VERB" == "yes" ]; then set -x; fi if [ "$CT_TYPE" == "1" ]; then FEATURES="nesting=1,keyctl=1" @@ -288,6 +379,7 @@ fi TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export VERBOSE=$VERB +export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os