2017-08-23 22:15:42 +02:00
|
|
|
param (
|
|
|
|
[string]$outputDir = "../.",
|
2017-11-09 04:24:23 +01:00
|
|
|
[string]$coreVersion = "latest",
|
|
|
|
[string]$webVersion = "latest",
|
2018-05-31 19:42:00 +02:00
|
|
|
[switch] $install,
|
2017-08-23 22:15:42 +02:00
|
|
|
[switch] $start,
|
|
|
|
[switch] $restart,
|
|
|
|
[switch] $stop,
|
2017-08-27 04:36:25 +02:00
|
|
|
[switch] $pull,
|
2017-10-25 23:21:35 +02:00
|
|
|
[switch] $updatedb,
|
|
|
|
[switch] $update
|
2017-08-23 22:15:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Setup
|
|
|
|
|
2018-05-31 19:43:04 +02:00
|
|
|
$dockerDir = "${outputDir}\docker"
|
2017-08-23 22:15:42 +02:00
|
|
|
|
|
|
|
# Functions
|
|
|
|
|
2018-05-31 19:42:00 +02:00
|
|
|
function Install() {
|
|
|
|
[string]$letsEncrypt = "n"
|
|
|
|
Write-Host "(!) " -f cyan -nonewline
|
2018-06-01 03:47:06 +02:00
|
|
|
[string]$domain = $( Read-Host "Enter the domain name for your Bitwarden instance (ex. bitwarden.company.com)" )
|
2018-05-31 19:42:00 +02:00
|
|
|
echo ""
|
|
|
|
|
2018-05-31 19:43:04 +02:00
|
|
|
if ($domain -eq "") {
|
2018-05-31 19:42:00 +02:00
|
|
|
$domain = "localhost"
|
|
|
|
}
|
|
|
|
|
2018-05-31 19:43:04 +02:00
|
|
|
if ($domain -ne "localhost") {
|
2018-05-31 19:42:00 +02:00
|
|
|
Write-Host "(!) " -f cyan -nonewline
|
|
|
|
$letsEncrypt = $( Read-Host "Do you want to use Let's Encrypt to generate a free SSL certificate? (y/n)" )
|
|
|
|
echo ""
|
|
|
|
|
2018-05-31 19:43:04 +02:00
|
|
|
if ($letsEncrypt -eq "y") {
|
2018-05-31 19:42:00 +02:00
|
|
|
Write-Host "(!) " -f cyan -nonewline
|
2018-08-09 03:26:52 +02:00
|
|
|
[string]$email = $( Read-Host ("Enter your email address (Let's Encrypt will send you certificate " +
|
|
|
|
"expiration reminders)") )
|
2018-05-31 19:42:00 +02:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
$letsEncryptPath = "${outputDir}/letsencrypt"
|
2018-05-31 19:43:04 +02:00
|
|
|
if (!(Test-Path -Path $letsEncryptPath )) {
|
2018-05-31 19:42:00 +02:00
|
|
|
New-Item -ItemType directory -Path $letsEncryptPath | Out-Null
|
|
|
|
}
|
|
|
|
docker pull certbot/certbot
|
|
|
|
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 --logs-dir /etc/letsencrypt/logs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Pull-Setup
|
|
|
|
docker run -it --rm --name setup -v ${outputDir}:/bitwarden bitwarden/setup:$coreVersion `
|
|
|
|
dotnet Setup.dll -install 1 -domain ${domain} -letsencrypt ${letsEncrypt} `
|
|
|
|
-os win -corev $coreVersion -webv $webVersion
|
|
|
|
}
|
|
|
|
|
2017-08-23 22:15:42 +02:00
|
|
|
function Docker-Compose-Up {
|
2018-08-31 15:16:14 +02:00
|
|
|
Docker-Compose-Files
|
|
|
|
docker-compose up -d
|
2017-08-23 22:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Docker-Compose-Down {
|
2018-08-31 15:16:14 +02:00
|
|
|
Docker-Compose-Files
|
|
|
|
docker-compose down
|
2017-08-23 22:15:42 +02:00
|
|
|
}
|
|
|
|
|
2017-08-27 04:36:25 +02:00
|
|
|
function Docker-Compose-Pull {
|
2018-08-31 15:16:14 +02:00
|
|
|
Docker-Compose-Files
|
|
|
|
docker-compose pull
|
|
|
|
}
|
|
|
|
|
|
|
|
function Docker-Compose-Files {
|
2018-05-31 19:43:04 +02:00
|
|
|
if (Test-Path -Path "${dockerDir}\docker-compose.override.yml" -PathType leaf) {
|
2018-08-31 15:16:14 +02:00
|
|
|
$env:COMPOSE_FILE = "${dockerDir}\docker-compose.yml;${dockerDir}\docker-compose.override.yml"
|
2018-02-20 17:09:47 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-08-31 15:16:14 +02:00
|
|
|
$env:COMPOSE_FILE = "${dockerDir}\docker-compose.yml"
|
2018-02-20 17:09:47 +01:00
|
|
|
}
|
2018-11-09 03:32:23 +01:00
|
|
|
$env:COMPOSE_HTTP_TIMEOUT = "300"
|
2017-08-27 04:36:25 +02:00
|
|
|
}
|
|
|
|
|
2017-08-23 22:15:42 +02:00
|
|
|
function Docker-Prune {
|
2018-11-07 15:51:16 +01:00
|
|
|
docker image prune --all --force --filter="label=com.bitwarden.product=bitwarden" `
|
|
|
|
--filter="label!=com.bitwarden.project=setup"
|
2017-08-23 22:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Update-Lets-Encrypt {
|
2018-05-31 19:43:04 +02:00
|
|
|
if (Test-Path -Path "${outputDir}\letsencrypt\live") {
|
2017-08-27 04:54:10 +02:00
|
|
|
docker pull certbot/certbot
|
2018-05-31 19:42:00 +02:00
|
|
|
docker run -it --rm --name certbot -p 443:443 -p 80:80 `
|
|
|
|
-v $outputDir/letsencrypt:/etc/letsencrypt/ certbot/certbot `
|
2017-08-23 22:15:42 +02:00
|
|
|
renew --logs-dir /etc/letsencrypt/logs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function Update-Database {
|
2017-10-25 23:21:35 +02:00
|
|
|
Pull-Setup
|
2018-05-31 19:42:00 +02:00
|
|
|
docker run -it --rm --name setup --network container:bitwarden-mssql `
|
|
|
|
-v ${outputDir}:/bitwarden bitwarden/setup:$coreVersion `
|
2017-11-09 04:24:23 +01:00
|
|
|
dotnet Setup.dll -update 1 -db 1 -os win -corev $coreVersion -webv $webVersion
|
2017-08-23 22:15:42 +02:00
|
|
|
echo "Database update complete"
|
|
|
|
}
|
|
|
|
|
2018-08-30 22:25:33 +02:00
|
|
|
function Update([switch] $withpull) {
|
|
|
|
if ($withpull) {
|
|
|
|
Pull-Setup
|
|
|
|
}
|
2017-11-09 04:24:23 +01:00
|
|
|
docker run -it --rm --name setup -v ${outputDir}:/bitwarden bitwarden/setup:$coreVersion `
|
|
|
|
dotnet Setup.dll -update 1 -os win -corev $coreVersion -webv $webVersion
|
2017-10-25 23:21:35 +02:00
|
|
|
}
|
|
|
|
|
2017-08-24 17:16:01 +02:00
|
|
|
function Print-Environment {
|
2017-10-25 23:21:35 +02:00
|
|
|
Pull-Setup
|
2017-11-09 04:24:23 +01:00
|
|
|
docker run -it --rm --name setup -v ${outputDir}:/bitwarden bitwarden/setup:$coreVersion `
|
|
|
|
dotnet Setup.dll -printenv 1 -os win -corev $coreVersion -webv $webVersion
|
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
|
|
|
Docker-Compose-Down
|
2017-08-27 04:36:25 +02:00
|
|
|
Docker-Compose-Pull
|
2017-08-23 22:15:42 +02:00
|
|
|
Update-Lets-Encrypt
|
|
|
|
Docker-Compose-Up
|
|
|
|
Docker-Prune
|
2017-08-24 17:16:01 +02:00
|
|
|
Print-Environment
|
2017-08-23 22:15:42 +02:00
|
|
|
}
|
2017-10-25 23:21:35 +02:00
|
|
|
|
|
|
|
function Pull-Setup {
|
2017-11-09 04:24:23 +01:00
|
|
|
docker pull bitwarden/setup:$coreVersion
|
2017-10-25 23:21:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Commands
|
|
|
|
|
2018-05-31 19:43:04 +02:00
|
|
|
if ($install) {
|
2018-05-31 19:42:00 +02:00
|
|
|
Install
|
|
|
|
}
|
2018-05-31 19:43:04 +02:00
|
|
|
elseif ($start -Or $restart) {
|
2017-10-25 23:21:35 +02:00
|
|
|
Restart
|
|
|
|
}
|
2018-05-31 19:43:04 +02:00
|
|
|
elseif ($pull) {
|
2017-08-27 04:36:25 +02:00
|
|
|
Docker-Compose-Pull
|
|
|
|
}
|
2018-05-31 19:43:04 +02:00
|
|
|
elseif ($stop) {
|
2017-08-23 22:15:42 +02:00
|
|
|
Docker-Compose-Down
|
|
|
|
}
|
2018-05-31 19:43:04 +02:00
|
|
|
elseif ($updatedb) {
|
2017-08-23 22:15:42 +02:00
|
|
|
Update-Database
|
|
|
|
}
|
2018-05-31 19:43:04 +02:00
|
|
|
elseif ($update) {
|
2017-10-25 23:21:35 +02:00
|
|
|
Docker-Compose-Down
|
2018-08-30 22:25:33 +02:00
|
|
|
Update -withpull
|
2017-10-25 23:21:35 +02:00
|
|
|
Restart
|
2018-03-11 05:53:21 +01:00
|
|
|
echo "Pausing 60 seconds for database to come online. Please wait..."
|
|
|
|
Start-Sleep -s 60
|
2017-10-25 23:21:35 +02:00
|
|
|
Update-Database
|
|
|
|
}
|
2018-08-30 22:25:33 +02:00
|
|
|
elseif ($rebuild) {
|
|
|
|
Docker-Compose-Down
|
|
|
|
Update
|
|
|
|
}
|