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
|
|
|
|
|
|
|
|
DOCKER_DIR=$DIR/../docker
|
2017-08-24 02:05:53 +02:00
|
|
|
if [ $# -gt 2 ]
|
2017-08-23 22:15:42 +02:00
|
|
|
then
|
|
|
|
DOCKER_DIR=$3
|
|
|
|
fi
|
|
|
|
|
2017-10-02 20:49:42 +02:00
|
|
|
OS="linwin"
|
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-10-04 05:20:09 +02:00
|
|
|
TAG="1.12.0"
|
|
|
|
|
2017-08-23 22:15:42 +02:00
|
|
|
# Functions
|
|
|
|
|
|
|
|
function dockerComposeUp() {
|
|
|
|
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.$OS.yml up -d
|
|
|
|
}
|
|
|
|
|
|
|
|
function dockerComposeDown() {
|
|
|
|
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.$OS.yml down
|
|
|
|
}
|
|
|
|
|
2017-08-27 04:36:25 +02:00
|
|
|
function dockerComposePull() {
|
|
|
|
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.$OS.yml pull
|
|
|
|
}
|
|
|
|
|
2017-08-23 22:15:42 +02:00
|
|
|
function dockerPrune() {
|
|
|
|
docker image prune -f
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateLetsEncrypt() {
|
2017-08-23 22:29:55 +02:00
|
|
|
if [ -d "${outputDir}/letsencrypt/live" ]
|
2017-08-23 22:15:42 +02:00
|
|
|
then
|
2017-08-27 04:54:10 +02:00
|
|
|
docker pull certbot/certbot
|
2017-08-23 22:15:42 +02:00
|
|
|
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() {
|
2017-10-04 05:20:09 +02:00
|
|
|
docker pull bitwarden/setup:$TAG
|
|
|
|
docker run -it --rm --name setup --network container:mssql -v $OUTPUT_DIR:/bitwarden bitwarden/setup:$TAG \
|
2017-08-23 22:15:42 +02:00
|
|
|
dotnet Setup.dll -update 1 -db 1
|
|
|
|
echo "Database update complete"
|
|
|
|
}
|
|
|
|
|
2017-08-24 17:16:01 +02:00
|
|
|
function printEnvironment() {
|
2017-10-04 05:20:09 +02:00
|
|
|
docker pull bitwarden/setup:$TAG
|
|
|
|
docker run -it --rm --name setup -v $OUTPUT_DIR:/bitwarden bitwarden/setup:$TAG \
|
2017-08-24 17:16:01 +02:00
|
|
|
dotnet Setup.dll -printenv 1 -env $OS
|
|
|
|
}
|
|
|
|
|
2017-08-23 22:15:42 +02:00
|
|
|
# Commands
|
|
|
|
|
|
|
|
if [ "$1" == "start" -o "$1" == "restart" ]
|
|
|
|
then
|
|
|
|
dockerComposeDown
|
2017-08-27 04:36:25 +02:00
|
|
|
dockerComposePull
|
2017-08-23 22:15:42 +02:00
|
|
|
updateLetsEncrypt
|
|
|
|
dockerComposeUp
|
|
|
|
dockerPrune
|
2017-08-24 17:16:01 +02:00
|
|
|
printEnvironment
|
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
|
|
|
|
fi
|