2020-09-10 21:36:44 +02:00
#!/bin/bash
2021-01-27 14:51:13 +01:00
ask ( ) {
local __resultVar = $1
local __result = " $2 "
if [ -z " $2 " ] ; then
read -p " $3 " __result
fi
eval $__resultVar = " ' $__result ' "
}
2020-09-10 21:36:44 +02:00
SCRIPT_BASE = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " >/dev/null 2>& 1 && pwd ) "
2022-04-09 06:49:08 +02:00
BW_VERSION = $( curl -sL https://go.btwrdn.co/bw-sh-versions | grep '^ *"' coreVersion'":' | awk -F\: '{ print $2 }' | sed -e 's/,$//' -e 's/^"//' -e 's/"$//' )
2020-09-10 21:36:44 +02:00
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 ) "
2021-01-27 14:51:13 +01:00
# Get Bitwarden base from user (or keep default value) or use first argument
ask tmpbase " $1 " " Enter Bitwarden base directory [ $BITWARDEN_BASE ]: "
2020-09-10 21:36:44 +02:00
BITWARDEN_BASE = ${ tmpbase :- $BITWARDEN_BASE }
# Check if directory exists and is valid
[ -d " $BITWARDEN_BASE " ] || { echo " Bitwarden base directory $BITWARDEN_BASE not found! " ; exit 1; }
[ -f " $BITWARDEN_BASE /bitwarden.sh " ] || { echo " Bitwarden base directory $BITWARDEN_BASE is not valid! " ; exit 1; }
# Check if user wants to recreate the docker-compose override file
RECREATE_OV = "y"
2021-01-27 14:51:13 +01:00
ask tmprecreate " $2 " "Rebuild docker-compose override? [Y/n]: "
2020-09-10 21:36:44 +02:00
RECREATE_OV = ${ tmprecreate :- $RECREATE_OV }
if [ [ $RECREATE_OV = ~ ^[ Yy] $ ] ]
then
{
echo "version: '3'"
echo ""
echo "services:"
echo " api:"
echo " image: bitbetter/api: $BW_VERSION "
echo ""
echo " identity:"
echo " image: bitbetter/identity: $BW_VERSION "
echo ""
} > $BITWARDEN_BASE /bwdata/docker/docker-compose.override.yml
echo "BitBetter docker-compose override created!"
else
echo " Make sure to check if the docker override contains the correct image version ( $BW_VERSION ) in $BITWARDEN_BASE /bwdata/docker/docker-compose.override.yml! "
fi
# Check if user wants to rebuild the bitbetter images
docker images bitbetter/api --format= "{{ .Tag }}" | grep -F -- " ${ BW_VERSION } " > /dev/null
retval = $?
REBUILD_BB = "n"
REBUILD_BB_DESCR = "[y/N]"
if [ $retval -ne 0 ] ; then
REBUILD_BB = "y"
REBUILD_BB_DESCR = "[Y/n]"
fi
2021-01-27 14:51:13 +01:00
ask tmprebuild " $3 " " Rebuild BitBetter images? $REBUILD_BB_DESCR : "
2020-09-10 21:36:44 +02:00
REBUILD_BB = ${ tmprebuild :- $REBUILD_BB }
if [ [ $REBUILD_BB = ~ ^[ Yy] $ ] ]
then
2021-08-31 11:40:37 +02:00
$SCRIPT_BASE /build.sh
2020-09-10 21:36:44 +02:00
echo " BitBetter images updated to version: $BW_VERSION "
fi
# Now start the bitwarden update
cd $BITWARDEN_BASE
./bitwarden.sh updateself
# Update the bitwarden.sh: automatically patch run.sh to fix docker-compose pull errors for private images
2022-03-21 21:20:32 +01:00
awk '1;/function downloadRunFile/{c=6}c&&!--c{print "sed -i ' \' 's/dccmd pull/dccmd pull --ignore-pull-failures || true/g' \' ' $SCRIPTS_DIR/run.sh"}' $BITWARDEN_BASE /bitwarden.sh > tmp_bw.sh && mv tmp_bw.sh $BITWARDEN_BASE /bitwarden.sh
2020-09-10 21:36:44 +02:00
chmod +x $BITWARDEN_BASE /bitwarden.sh
echo "Patching bitwarden.sh completed..."
./bitwarden.sh update
2021-03-17 10:38:54 +01:00
# Prune Docker images without at least one container associated to them.
echo "Pruning Docker images without at least one container associated to them..."
docker image prune -a
2020-09-10 21:36:44 +02:00
cd $SCRIPT_BASE
echo "Bitwarden update completed!"