mirror of
https://github.com/bitwarden/server.git
synced 2024-11-29 13:25:17 +01:00
164 lines
4.0 KiB
Bash
164 lines
4.0 KiB
Bash
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Setup
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
OUTPUT_DIR="../."
|
|
if [ $# -gt 1 ]
|
|
then
|
|
OUTPUT_DIR=$2
|
|
fi
|
|
|
|
COREVERSION="latest"
|
|
if [ $# -gt 2 ]
|
|
then
|
|
COREVERSION=$3
|
|
fi
|
|
|
|
WEBVERSION="latest"
|
|
if [ $# -gt 3 ]
|
|
then
|
|
WEBVERSION=$4
|
|
fi
|
|
|
|
OS="lin"
|
|
if [ "$(uname)" == "Darwin" ]
|
|
then
|
|
OS="mac"
|
|
fi
|
|
|
|
DOCKER_DIR="$OUTPUT_DIR/docker"
|
|
ENV_DIR="$OUTPUT_DIR/env"
|
|
|
|
# Functions
|
|
|
|
function dockerComposeUp() {
|
|
if [ -f "${DOCKER_DIR}/docker-compose.override.yml" ]
|
|
then
|
|
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.override.yml up -d
|
|
else
|
|
docker-compose -f $DOCKER_DIR/docker-compose.yml up -d
|
|
fi
|
|
}
|
|
|
|
function dockerComposeDown() {
|
|
if [ -f "${DOCKER_DIR}/docker-compose.override.yml" ]
|
|
then
|
|
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.override.yml down
|
|
else
|
|
docker-compose -f $DOCKER_DIR/docker-compose.yml down
|
|
fi
|
|
}
|
|
|
|
function dockerComposePull() {
|
|
if [ -f "${DOCKER_DIR}/docker-compose.override.yml" ]
|
|
then
|
|
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.override.yml pull
|
|
else
|
|
docker-compose -f $DOCKER_DIR/docker-compose.yml pull
|
|
fi
|
|
}
|
|
|
|
function dockerPrune() {
|
|
docker image prune -f
|
|
}
|
|
|
|
function updateLetsEncrypt() {
|
|
if [ -d "${OUTPUT_DIR}/letsencrypt/live" ]
|
|
then
|
|
docker pull certbot/certbot
|
|
docker run -i --rm --name certbot -p 443:443 -p 80:80 \
|
|
-v $OUTPUT_DIR/letsencrypt:/etc/letsencrypt/ certbot/certbot \
|
|
renew --logs-dir /etc/letsencrypt/logs
|
|
fi
|
|
}
|
|
|
|
function updateDatabase() {
|
|
pullSetup
|
|
if [ $OS == "lin" ]
|
|
then
|
|
docker run -i --rm --name setup --network container:bitwarden-mssql \
|
|
-v $OUTPUT_DIR:/bitwarden -e LOCAL_UID=`id -u $USER` bitwarden/setup:$COREVERSION \
|
|
dotnet Setup.dll -update 1 -db 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
|
else
|
|
docker run -i --rm --name setup --network container:bitwarden-mssql \
|
|
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
|
dotnet Setup.dll -update 1 -db 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
|
fi
|
|
echo "Database update complete"
|
|
}
|
|
|
|
function update() {
|
|
pullSetup
|
|
if [ $OS == "lin" ]
|
|
then
|
|
docker run -i --rm --name setup -v $OUTPUT_DIR:/bitwarden \
|
|
-e LOCAL_UID=`id -u $USER` bitwarden/setup:$COREVERSION \
|
|
dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
|
else
|
|
docker run -i --rm --name setup \
|
|
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
|
dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
|
fi
|
|
}
|
|
|
|
function printEnvironment() {
|
|
pullSetup
|
|
if [ $OS == "lin" ]
|
|
then
|
|
docker run -i --rm --name setup -v $OUTPUT_DIR:/bitwarden \
|
|
-e LOCAL_UID=`id -u $USER` bitwarden/setup:$COREVERSION \
|
|
dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
|
else
|
|
docker run -i --rm --name setup \
|
|
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
|
dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
|
fi
|
|
}
|
|
|
|
function restart() {
|
|
dockerComposeDown
|
|
dockerComposePull
|
|
updateLetsEncrypt
|
|
|
|
if [ $OS == "lin" ]
|
|
then
|
|
mkdir -p $ENV_DIR
|
|
echo "LOCAL_UID=`id -u $USER`" > $ENV_DIR/uid.env
|
|
fi
|
|
|
|
dockerComposeUp
|
|
dockerPrune
|
|
printEnvironment
|
|
}
|
|
|
|
function pullSetup() {
|
|
docker pull bitwarden/setup:$COREVERSION
|
|
}
|
|
|
|
# Commands
|
|
|
|
if [ "$1" == "start" -o "$1" == "restart" ]
|
|
then
|
|
restart
|
|
elif [ "$1" == "pull" ]
|
|
then
|
|
dockerComposePull
|
|
elif [ "$1" == "stop" ]
|
|
then
|
|
dockerComposeDown
|
|
elif [ "$1" == "updatedb" ]
|
|
then
|
|
updateDatabase
|
|
elif [ "$1" == "update" ]
|
|
then
|
|
dockerComposeDown
|
|
update
|
|
restart
|
|
echo "Pausing 60 seconds for database to come online. Please wait..."
|
|
sleep 60
|
|
updateDatabase
|
|
fi
|