#!/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" # Functions function dockerComposeUp() { docker-compose -f $DOCKER_DIR/docker-compose.yml up -d } function dockerComposeDown() { docker-compose -f $DOCKER_DIR/docker-compose.yml down } function dockerComposePull() { docker-compose -f $DOCKER_DIR/docker-compose.yml pull } function dockerPrune() { docker image prune -f } function updateLetsEncrypt() { if [ -d "${OUTPUT_DIR}/letsencrypt/live" ] then docker pull certbot/certbot docker run -it --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 docker run -it --rm --name setup --network container:mssql -v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \ dotnet Setup.dll -update 1 -db 1 -os $OS -corev $COREVERSION -webv $WEBVERSION echo "Database update complete" } function update() { pullSetup docker run -it --rm --name setup -v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \ dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION } function printEnvironment() { pullSetup docker run -it --rm --name setup -v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \ dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION } function restart() { dockerComposeDown dockerComposePull updateLetsEncrypt 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 updateDatabase fi