1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00
bitwarden-server/scripts/run.ps1

161 lines
4.6 KiB
PowerShell
Raw Normal View History

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
[string]$email = $( Read-Host "Enter your email address (Let's Encrypt will send you certificate " +
"expiration reminders)" )
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
echo ""
echo "Setup complete"
echo ""
}
2017-08-23 22:15:42 +02:00
function Docker-Compose-Up {
2018-05-31 19:43:04 +02: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-05-31 19:43:04 +02: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-05-31 19:43:04 +02: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 {
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"
}
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: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
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
}