From 5977803e3b9479f2dd80aca85547a586db282e37 Mon Sep 17 00:00:00 2001 From: dcertskc <66886574+dcertskc@users.noreply.github.com> Date: Wed, 17 Jun 2020 08:05:35 -0500 Subject: [PATCH] Added force renew certificate (#781) --- scripts/bitwarden.ps1 | 6 ++++++ scripts/bitwarden.sh | 5 +++++ scripts/run.ps1 | 23 +++++++++++++++++++++++ scripts/run.sh | 21 +++++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/scripts/bitwarden.ps1 b/scripts/bitwarden.ps1 index 9949c57636..5ab92733e9 100644 --- a/scripts/bitwarden.ps1 +++ b/scripts/bitwarden.ps1 @@ -6,6 +6,7 @@ param ( [switch] $update, [switch] $rebuild, [switch] $updateconf, + [switch] $renewcert, [switch] $updatedb, [switch] $updaterun, [switch] $updateself, @@ -64,6 +65,7 @@ Available commands: -updaterun -updateself -updateconf +-renewcert -rebuild -help @@ -137,6 +139,10 @@ elseif ($stop) { Check-Output-Dir-Exists Invoke-Expression "& `"$scriptsDir\run.ps1`" -stop -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion" } +elseif ($renewcert) { + Check-Output-Dir-Exists + Invoke-Expression "& `"$scriptsDir\run.ps1`" -renewcert -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion" +} elseif ($updaterun) { Check-Output-Dir-Exists Download-Run-File diff --git a/scripts/bitwarden.sh b/scripts/bitwarden.sh index b2ddfca2a9..1a8ac9939f 100755 --- a/scripts/bitwarden.sh +++ b/scripts/bitwarden.sh @@ -91,6 +91,7 @@ updatedb updaterun updateself updateconf +renewcert rebuild help @@ -132,6 +133,10 @@ elif [ "$1" == "stop" ] then checkOutputDirExists $SCRIPTS_DIR/run.sh stop $OUTPUT $COREVERSION $WEBVERSION +elif [ "$1" == "renewcert" ] +then + checkOutputDirExists + $SCRIPTS_DIR/run.sh renewcert $OUTPUT $COREVERSION $WEBVERSION elif [ "$1" == "updaterun" ] then checkOutputDirExists diff --git a/scripts/run.ps1 b/scripts/run.ps1 index 5113b9cf28..57e814d68b 100644 --- a/scripts/run.ps1 +++ b/scripts/run.ps1 @@ -8,6 +8,7 @@ param ( [switch] $stop, [switch] $pull, [switch] $updateconf, + [switch] $renewcert, [switch] $updatedb, [switch] $update ) @@ -139,6 +140,16 @@ function Update-Lets-Encrypt { } } +function Force-Update-Lets-Encrypt { + if (Test-Path -Path "${outputDir}\letsencrypt\live") { + Invoke-Expression ("docker pull{0} certbot/certbot" -f "") #TODO: qFlag + $certbotExp = "docker run -it --rm --name certbot -p ${certbotHttpsPort}:443 -p ${certbotHttpPort}:80 " +` + "-v ${outputDir}/letsencrypt:/etc/letsencrypt/ certbot/certbot " +` + "renew{0} --logs-dir /etc/letsencrypt/logs --force-renew" -f $qFlag + Invoke-Expression $certbotExp + } +} + function Update-Database { Pull-Setup Docker-Compose-Files @@ -171,6 +182,15 @@ function Restart { Print-Environment } +function certRestart { + Docker-Compose-Down + Docker-Compose-Pull + Force-Update-Lets-Encrypt + Docker-Compose-Up + Print-Environment +} + + function Pull-Setup { Invoke-Expression ("docker pull{0} bitwarden/setup:${coreVersion}" -f "") #TODO: qFlag } @@ -195,6 +215,9 @@ elseif ($pull) { elseif ($stop) { Docker-Compose-Down } +elseif ($renewcert) { + certRestart +} elseif ($updateconf) { Docker-Compose-Down Update -withpull diff --git a/scripts/run.sh b/scripts/run.sh index 5f80344d28..e4127ac2a9 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -148,6 +148,16 @@ function updateLetsEncrypt() { fi } +function forceupdateLetsEncrypt() { + 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 --force-renew + fi +} + function updateDatabase() { pullSetup dockerComposeFiles @@ -183,6 +193,14 @@ function restart() { printEnvironment } +function certrestart() { + dockerComposeDown + dockerComposePull + forceupdateLetsEncrypt + dockerComposeUp + printEnvironment +} + function pullSetup() { docker pull bitwarden/setup:$COREVERSION } @@ -201,6 +219,9 @@ then elif [ "$1" == "stop" ] then dockerComposeDown +elif [ "$1" == "renewcert" ] +then + certrestart elif [ "$1" == "updateconf" ] then dockerComposeDown