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
|
|
|
|
|
2017-11-09 04:24:23 +01: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
|
|
|
|
[string]$domain = $( Read-Host "Enter the domain name for your bitwarden instance (ex. bitwarden.company.com)" )
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
if($domain -eq "") {
|
|
|
|
$domain = "localhost"
|
|
|
|
}
|
|
|
|
|
|
|
|
if($domain -ne "localhost") {
|
|
|
|
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 ""
|
|
|
|
|
|
|
|
if($letsEncrypt -eq "y") {
|
|
|
|
Write-Host "(!) " -f cyan -nonewline
|
|
|
|
[string]$email = $( Read-Host "Enter your email address (Let's Encrypt will send you certificate " +
|
|
|
|
"expiration reminders)" )
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
$letsEncryptPath = "${outputDir}/letsencrypt"
|
|
|
|
if(!(Test-Path -Path $letsEncryptPath )){
|
|
|
|
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
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Setup complete"
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
2017-08-23 22:15:42 +02:00
|
|
|
function Docker-Compose-Up {
|
2018-02-20 17:09:47 +01:00
|
|
|
if(Test-Path -Path "${dockerDir}\docker-compose.override.yml" -PathType leaf) {
|
|
|
|
docker-compose -f ${dockerDir}\docker-compose.yml -f ${dockerDir}\docker-compose.override.yml up -d
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
docker-compose -f ${dockerDir}\docker-compose.yml up -d
|
|
|
|
}
|
2017-08-23 22:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Docker-Compose-Down {
|
2018-02-20 17:09:47 +01:00
|
|
|
if(Test-Path -Path "${dockerDir}\docker-compose.override.yml" -PathType leaf) {
|
|
|
|
docker-compose -f ${dockerDir}\docker-compose.yml -f ${dockerDir}\docker-compose.override.yml down
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
docker-compose -f ${dockerDir}\docker-compose.yml down
|
|
|
|
}
|
2017-08-23 22:15:42 +02:00
|
|
|
}
|
|
|
|
|
2017-08-27 04:36:25 +02:00
|
|
|
function Docker-Compose-Pull {
|
2018-02-20 17:09:47 +01:00
|
|
|
if(Test-Path -Path "${dockerDir}\docker-compose.override.yml" -PathType leaf) {
|
|
|
|
docker-compose -f ${dockerDir}\docker-compose.yml -f ${dockerDir}\docker-compose.override.yml pull
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
docker-compose -f ${dockerDir}\docker-compose.yml pull
|
|
|
|
}
|
|
|
|
|
2017-08-27 04:36:25 +02:00
|
|
|
}
|
|
|
|
|
2017-08-23 22:15:42 +02:00
|
|
|
function Docker-Prune {
|
|
|
|
docker image prune -f
|
|
|
|
}
|
|
|
|
|
|
|
|
function Update-Lets-Encrypt {
|
2017-08-23 22:29:55 +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"
|
|
|
|
}
|
|
|
|
|
2017-10-25 23:21:35 +02:00
|
|
|
function Update {
|
|
|
|
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:42:00 +02:00
|
|
|
if($install) {
|
|
|
|
Install
|
|
|
|
}
|
|
|
|
elseif($start -Or $restart) {
|
2017-10-25 23:21:35 +02:00
|
|
|
Restart
|
|
|
|
}
|
2017-08-27 04:36:25 +02:00
|
|
|
elseif($pull) {
|
|
|
|
Docker-Compose-Pull
|
|
|
|
}
|
2017-08-23 22:15:42 +02:00
|
|
|
elseif($stop) {
|
|
|
|
Docker-Compose-Down
|
|
|
|
}
|
|
|
|
elseif($updatedb) {
|
|
|
|
Update-Database
|
|
|
|
}
|
2017-10-25 23:21:35 +02:00
|
|
|
elseif($update) {
|
|
|
|
Docker-Compose-Down
|
|
|
|
Update
|
|
|
|
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
|
|
|
|
}
|