2017-08-23 22:15:42 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Setup
|
|
|
|
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
OUTPUT_DIR="../."
|
2017-08-23 22:51:36 +02:00
|
|
|
if [ $# -gt 1 ]
|
2017-08-23 22:15:42 +02:00
|
|
|
then
|
|
|
|
OUTPUT_DIR=$2
|
|
|
|
fi
|
|
|
|
|
2017-11-09 04:24:23 +01:00
|
|
|
COREVERSION="latest"
|
2017-08-24 02:05:53 +02:00
|
|
|
if [ $# -gt 2 ]
|
2017-08-23 22:15:42 +02:00
|
|
|
then
|
2017-11-09 04:24:23 +01:00
|
|
|
COREVERSION=$3
|
2017-08-23 22:15:42 +02:00
|
|
|
fi
|
|
|
|
|
2017-11-09 04:24:23 +01:00
|
|
|
WEBVERSION="latest"
|
|
|
|
if [ $# -gt 3 ]
|
|
|
|
then
|
|
|
|
WEBVERSION=$4
|
|
|
|
fi
|
|
|
|
|
|
|
|
OS="lin"
|
2017-08-23 22:15:42 +02:00
|
|
|
if [ "$(uname)" == "Darwin" ]
|
|
|
|
then
|
2017-10-02 20:49:42 +02:00
|
|
|
OS="mac"
|
2017-08-23 22:15:42 +02:00
|
|
|
fi
|
|
|
|
|
2017-11-09 04:24:23 +01:00
|
|
|
DOCKER_DIR="$OUTPUT_DIR/docker"
|
2017-10-04 05:20:09 +02:00
|
|
|
|
2017-08-23 22:15:42 +02:00
|
|
|
# Functions
|
|
|
|
|
|
|
|
function dockerComposeUp() {
|
2018-02-20 17:15:16 +01:00
|
|
|
if [ -f "${DOCKER_DIR}/docker-compose.override.yml" ]
|
2018-02-20 17:09:47 +01:00
|
|
|
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
|
2017-08-23 22:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function dockerComposeDown() {
|
2018-02-20 17:15:16 +01:00
|
|
|
if [ -f "${DOCKER_DIR}/docker-compose.override.yml" ]
|
2018-02-20 17:09:47 +01:00
|
|
|
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
|
2017-08-23 22:15:42 +02:00
|
|
|
}
|
|
|
|
|
2017-08-27 04:36:25 +02:00
|
|
|
function dockerComposePull() {
|
2018-02-20 17:15:16 +01:00
|
|
|
if [ -f "${DOCKER_DIR}/docker-compose.override.yml" ]
|
2018-02-20 17:09:47 +01:00
|
|
|
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
|
2017-08-27 04:36:25 +02:00
|
|
|
}
|
|
|
|
|
2017-08-23 22:15:42 +02:00
|
|
|
function dockerPrune() {
|
|
|
|
docker image prune -f
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateLetsEncrypt() {
|
2017-11-09 04:24:23 +01:00
|
|
|
if [ -d "${OUTPUT_DIR}/letsencrypt/live" ]
|
2017-08-23 22:15:42 +02:00
|
|
|
then
|
2017-08-27 04:54:10 +02:00
|
|
|
docker pull certbot/certbot
|
2018-03-27 20:55:33 +02:00
|
|
|
docker run -i --rm --name certbot -p 443:443 -p 80:80 \
|
|
|
|
-v $OUTPUT_DIR/letsencrypt:/etc/letsencrypt/ certbot/certbot \
|
2017-08-23 22:15:42 +02:00
|
|
|
renew --logs-dir /etc/letsencrypt/logs
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateDatabase() {
|
2017-10-25 23:21:35 +02:00
|
|
|
pullSetup
|
2018-03-27 20:55:33 +02:00
|
|
|
if [ $OS == "lin" ]
|
|
|
|
then
|
|
|
|
docker run -i --rm --name setup --network container:bitwarden-mssql \
|
2018-03-27 22:51:09 +02:00
|
|
|
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
2018-03-27 20:55:33 +02:00
|
|
|
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
|
2017-08-23 22:15:42 +02:00
|
|
|
echo "Database update complete"
|
|
|
|
}
|
|
|
|
|
2017-10-25 23:21:35 +02:00
|
|
|
function update() {
|
|
|
|
pullSetup
|
2018-03-27 20:55:33 +02:00
|
|
|
if [ $OS == "lin" ]
|
|
|
|
then
|
2018-03-27 21:04:13 +02:00
|
|
|
docker run -i --rm --name setup \
|
2018-03-27 22:51:09 +02:00
|
|
|
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
2018-03-27 20:55:33 +02:00
|
|
|
dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
|
|
|
else
|
2018-03-27 21:04:13 +02:00
|
|
|
docker run -i --rm --name setup \
|
|
|
|
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
2018-03-27 20:55:33 +02:00
|
|
|
dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
|
|
|
fi
|
2017-10-25 23:21:35 +02:00
|
|
|
}
|
|
|
|
|
2017-08-24 17:16:01 +02:00
|
|
|
function printEnvironment() {
|
2017-10-25 23:21:35 +02:00
|
|
|
pullSetup
|
2018-03-27 20:55:33 +02:00
|
|
|
if [ $OS == "lin" ]
|
|
|
|
then
|
2018-03-27 21:04:13 +02:00
|
|
|
docker run -i --rm --name setup \
|
2018-03-27 22:51:09 +02:00
|
|
|
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
2018-03-27 20:55:33 +02:00
|
|
|
dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
|
|
|
else
|
2018-03-27 21:04:13 +02:00
|
|
|
docker run -i --rm --name setup \
|
|
|
|
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
2018-03-27 20:55:33 +02:00
|
|
|
dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
|
|
|
fi
|
2017-08-24 17:16:01 +02:00
|
|
|
}
|
|
|
|
|
2017-10-25 23:21:35 +02:00
|
|
|
function restart() {
|
2017-08-23 22:15:42 +02:00
|
|
|
dockerComposeDown
|
2017-08-27 04:36:25 +02:00
|
|
|
dockerComposePull
|
2017-08-23 22:15:42 +02:00
|
|
|
updateLetsEncrypt
|
2018-03-27 21:23:02 +02:00
|
|
|
|
|
|
|
if [ $OS == "lin" ]
|
|
|
|
then
|
|
|
|
echo "LOCAL_UID=`id -u $USER`" > ../env/uid.env
|
|
|
|
fi
|
|
|
|
|
2017-08-23 22:15:42 +02:00
|
|
|
dockerComposeUp
|
|
|
|
dockerPrune
|
2017-08-24 17:16:01 +02:00
|
|
|
printEnvironment
|
2017-10-25 23:21:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function pullSetup() {
|
2017-11-09 04:24:23 +01:00
|
|
|
docker pull bitwarden/setup:$COREVERSION
|
2017-10-25 23:21:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Commands
|
|
|
|
|
|
|
|
if [ "$1" == "start" -o "$1" == "restart" ]
|
|
|
|
then
|
|
|
|
restart
|
2017-08-27 04:36:25 +02:00
|
|
|
elif [ "$1" == "pull" ]
|
|
|
|
then
|
|
|
|
dockerComposePull
|
2017-08-23 22:15:42 +02:00
|
|
|
elif [ "$1" == "stop" ]
|
|
|
|
then
|
|
|
|
dockerComposeDown
|
2017-08-23 22:42:39 +02:00
|
|
|
elif [ "$1" == "updatedb" ]
|
2017-08-23 22:15:42 +02:00
|
|
|
then
|
|
|
|
updateDatabase
|
2017-10-25 23:21:35 +02:00
|
|
|
elif [ "$1" == "update" ]
|
|
|
|
then
|
|
|
|
dockerComposeDown
|
|
|
|
update
|
|
|
|
restart
|
2018-03-11 05:53:21 +01:00
|
|
|
echo "Pausing 60 seconds for database to come online. Please wait..."
|
|
|
|
sleep 60
|
2017-10-25 23:21:35 +02:00
|
|
|
updateDatabase
|
2017-08-23 22:15:42 +02:00
|
|
|
fi
|