From a0a5bffec984e94bbdd475b624433d910c914a33 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 21 Aug 2017 11:21:40 -0400 Subject: [PATCH] renew lets encrypt cert on run --- scripts/bitwarden.ps1 | 4 ++-- scripts/bitwarden.sh | 4 ++-- scripts/install.ps1 | 22 +++++++++++++--------- scripts/install.sh | 17 +++++++++++------ scripts/run.ps1 | 9 ++++++++- scripts/run.sh | 18 ++++++++++++++++-- 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/scripts/bitwarden.ps1 b/scripts/bitwarden.ps1 index 67ce0d5490..eb0d0531c8 100644 --- a/scripts/bitwarden.ps1 +++ b/scripts/bitwarden.ps1 @@ -60,7 +60,7 @@ elseif($run -Or $restart) { Download-Run-Files } - Invoke-Expression "$scriptsDir\run.ps1 -dockerDir $dockerDir" + Invoke-Expression "$scriptsDir\run.ps1 -outputDir $output -dockerDir $dockerDir" } elseif($update) { if(Test-Path -Path $dockerDir) { @@ -69,7 +69,7 @@ elseif($update) { New-Item -ItemType directory -Path $dockerDir | Out-Null Download-Run-Files - Invoke-Expression "$scriptsDir\run.ps1 -dockerDir $dockerDir" + Invoke-Expression "$scriptsDir\run.ps1 -outputDir $output -dockerDir $dockerDir" } elseif($updatedb) { Invoke-RestMethod -OutFile $scriptsDir\update-db.ps1 -Uri "${githubBaseUrl}/scripts/update-db.ps1" diff --git a/scripts/bitwarden.sh b/scripts/bitwarden.sh index 495d5696f1..c2308adfe2 100755 --- a/scripts/bitwarden.sh +++ b/scripts/bitwarden.sh @@ -67,7 +67,7 @@ then mkdir $DOCKER_DIR downloadRunFiles fi - $SCRIPTS_DIR/run.sh $DOCKER_DIR + $SCRIPTS_DIR/run.sh $OUTPUT $DOCKER_DIR elif [ "$1" == "update" ] then if [ -d "$DOCKER_DIR" ] @@ -77,7 +77,7 @@ then mkdir $DOCKER_DIR downloadRunFiles - $SCRIPTS_DIR/run.sh $DOCKER_DIR + $SCRIPTS_DIR/run.sh $OUTPUT $DOCKER_DIR elif [ "$1" == "updatedb" ] then curl -s -o $SCRIPTS_DIR/update-db.sh $GITHUB_BASE_URL/scripts/update-db.sh diff --git a/scripts/install.ps1 b/scripts/install.ps1 index bdacbba4e6..a7ce2bf349 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -9,18 +9,22 @@ if(!(Test-Path -Path $outputDir )){ docker --version echo "" +[string]$letsEncrypt = "n" [string]$domain = $( Read-Host "(!) Enter the domain name for your bitwarden instance (ex. bitwarden.company.com)" ) -[string]$letsEncrypt = $( Read-Host "(!) Do you want to use Let's Encrypt to generate a free SSL certificate? (y/n)" ) -if($letsEncrypt -eq "y") { - [string]$email = $( Read-Host "(!) Enter your email address (Let's Encrypt will send you certificate expiration reminders)" ) - - $letsEncryptPath = "${outputDir}/letsencrypt/live/${domain}" - if(!(Test-Path -Path $letsEncryptPath )){ - New-Item -ItemType directory -Path $letsEncryptPath +if($domain -ne "localhost") { + $letsEncrypt = $( Read-Host "(!) Do you want to use Let's Encrypt to generate a free SSL certificate? (y/n)" ) + + if($letsEncrypt -eq "y") { + [string]$email = $( Read-Host "(!) Enter your email address (Let's Encrypt will send you certificate expiration reminders)" ) + + $letsEncryptPath = "${outputDir}/letsencrypt/live/${domain}" + if(!(Test-Path -Path $letsEncryptPath )){ + New-Item -ItemType directory -Path $letsEncryptPath + } + docker run -it --rm --name certbot -p 80:80 -v $outputDir/letsencrypt:/etc/letsencrypt/ certbot/certbot ` + certonly --standalone --noninteractive --agree-tos --preferred-challenges http --email $email -d $domain } - docker run -it --rm --name certbot -p 80:80 -v $outputDir/letsencrypt:/etc/letsencrypt/ certbot/certbot ` - certonly --standalone --noninteractive --agree-tos --preferred-challenges http --email $email -d $domain } docker run -it --rm --name setup -v ${outputDir}:/bitwarden bitwarden/setup ` diff --git a/scripts/install.sh b/scripts/install.sh index 50fc4b9cf8..48b504ac21 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -11,15 +11,20 @@ then fi mkdir -p $OUTPUT_DIR +LETS_ENCRYPT="n" read -p "(!) Enter the domain name for your bitwarden instance (ex. bitwarden.company.com): " DOMAIN -read -p "(!) Do you want to use Let's Encrypt to generate a free SSL certificate? (y/n): " LETS_ENCRYPT -if [ "$LETS_ENCRYPT" == "y" ] +if [ "$DOMAIN" != "localhost" ] then - read -p "(!) Enter your email address (Let's Encrypt will send you certificate expiration reminders): " EMAIL - mkdir -p $OUTPUT_DIR/letsencrypt/live/$DOMAIN - docker run -it --rm --name certbot -p 80:80 -v $OUTPUT_DIR/letsencrypt:/etc/letsencrypt/ certbot/certbot \ - certonly --standalone --noninteractive --agree-tos --preferred-challenges http --email $EMAIL -d $DOMAIN + read -p "(!) Do you want to use Let's Encrypt to generate a free SSL certificate? (y/n): " LETS_ENCRYPT + + if [ "$LETS_ENCRYPT" == "y" ] + then + read -p "(!) Enter your email address (Let's Encrypt will send you certificate expiration reminders): " EMAIL + mkdir -p $OUTPUT_DIR/letsencrypt/live/$DOMAIN + docker run -it --rm --name certbot -p 80:80 -v $OUTPUT_DIR/letsencrypt:/etc/letsencrypt/ certbot/certbot \ + certonly --standalone --noninteractive --agree-tos --preferred-challenges http --email $EMAIL -d $DOMAIN + fi fi docker run -it --rm --name setup -v $OUTPUT_DIR:/bitwarden bitwarden/setup \ diff --git a/scripts/run.ps1 b/scripts/run.ps1 index 71674ef4e1..d9319d9ec3 100644 --- a/scripts/run.ps1 +++ b/scripts/run.ps1 @@ -1,5 +1,6 @@ param ( - [string] $dockerDir = "" + [string]$outputDir = "../.", + [string]$dockerDir = "" ) $dir = Split-Path -Parent $MyInvocation.MyCommand.Path @@ -10,5 +11,11 @@ if($dockerDir -eq "") { docker --version docker-compose --version +$letsEncryptLivePath = "${outputDir}/letsencrypt/live" +if(Test-Path -Path $letsEncryptLivePath) { + docker run -it --rm --name certbot -p 443:443 -p 80:80 -v $outputDir/letsencrypt:/etc/letsencrypt/ certbot/certbot ` + renew +} + docker-compose -f ${dockerDir}\docker-compose.yml -f ${dockerDir}\docker-compose.macwin.yml down docker-compose -f ${dockerDir}\docker-compose.yml -f ${dockerDir}\docker-compose.macwin.yml up -d diff --git a/scripts/run.sh b/scripts/run.sh index 2b3249133d..7f114942a9 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -2,10 +2,17 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DOCKER_DIR=$DIR/../docker + +OUTPUT_DIR="../." if [ $# -eq 1 ] then - DOCKER_DIR=$1 + OUTPUT_DIR=$1 +fi + +DOCKER_DIR=$DIR/../docker +if [ $# -eq 2 ] +then + DOCKER_DIR=$2 fi OS="linux" @@ -17,5 +24,12 @@ fi docker --version docker-compose --version +LETS_ENCRYPT_LIVE = "${outputDir}/letsencrypt/live" +if [ -d "$LETS_ENCRYPT_LIVE" ] +then + docker run -it --rm --name certbot -p 443:443 -p 80:80 -v $OUTPUT_DIR/letsencrypt:/etc/letsencrypt/ certbot/certbot \ + renew +fi + docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.$OS.yml down docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.$OS.yml up -d