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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

166 lines
4.5 KiB
PowerShell
Raw Normal View History

2017-08-19 17:51:13 +02:00
param (
[switch] $install,
2017-08-21 17:58:15 +02:00
[switch] $start,
2017-08-21 15:40:10 +02:00
[switch] $restart,
2017-08-21 15:39:12 +02:00
[switch] $stop,
2017-08-19 17:51:13 +02:00
[switch] $update,
2018-08-30 22:25:33 +02:00
[switch] $rebuild,
[switch] $updateconf,
2020-06-17 15:05:35 +02:00
[switch] $renewcert,
2017-08-19 17:51:13 +02:00
[switch] $updatedb,
[switch] $updaterun,
2017-08-23 22:15:42 +02:00
[switch] $updateself,
2019-10-25 02:04:09 +02:00
[switch] $help,
2017-08-21 14:49:44 +02:00
[string] $output = ""
2017-08-19 17:51:13 +02:00
)
2017-08-23 22:15:42 +02:00
# Setup
2017-08-23 22:22:02 +02:00
$scriptPath = $MyInvocation.MyCommand.Path
2017-08-19 17:51:13 +02:00
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
2018-05-31 19:43:04 +02:00
if ($output -eq "") {
$output = "${dir}\bwdata"
2017-08-21 14:49:44 +02:00
}
$scriptsDir = "${output}\scripts"
2019-01-19 04:23:46 +01:00
$githubBaseUrl = "https://raw.githubusercontent.com/bitwarden/server/master"
2021-05-17 20:51:29 +02:00
# Please do not create pull requests modifying the version numbers.
$coreVersion = "1.45.2"
$webVersion = "2.25.0"
$keyConnectorVersion = "1.0.0"
2017-08-19 17:51:13 +02:00
2017-08-23 22:15:42 +02:00
# Functions
function Get-Self {
2017-08-23 22:22:02 +02:00
Invoke-RestMethod -OutFile $scriptPath -Uri "${githubBaseUrl}/scripts/bitwarden.ps1"
2017-08-23 22:15:42 +02:00
}
function Get-Run-File {
2018-05-31 19:43:04 +02:00
if (!(Test-Path -Path $scriptsDir)) {
2017-09-18 18:11:03 +02:00
New-Item -ItemType directory -Path $scriptsDir | Out-Null
}
2017-08-23 22:15:42 +02:00
Invoke-RestMethod -OutFile $scriptsDir\run.ps1 -Uri "${githubBaseUrl}/scripts/run.ps1"
}
function Test-Output-Dir-Exists {
2018-05-31 19:43:04 +02:00
if (!(Test-Path -Path $output)) {
2018-06-01 03:47:06 +02:00
throw "Cannot find a Bitwarden installation at $output."
2017-09-18 18:11:03 +02:00
}
}
function Test-Output-Dir-Not-Exists {
if (Test-Path -Path "$output\docker") {
2018-06-01 03:47:06 +02:00
throw "Looks like Bitwarden is already installed at $output."
2017-09-18 18:11:03 +02:00
}
2017-08-23 22:15:42 +02:00
}
function Show-Commands {
2019-10-25 02:04:09 +02:00
Write-Line "
Available commands:
-install
-start
-restart
-stop
-update
-updatedb
-updaterun
2019-10-25 02:04:09 +02:00
-updateself
-updateconf
2020-06-17 15:05:35 +02:00
-renewcert
2019-10-25 02:04:09 +02:00
-rebuild
-help
See more at https://bitwarden.com/help/article/install-on-premise/#script-commands-reference
2019-10-25 02:04:09 +02:00
"
}
2019-03-25 21:46:32 +01:00
function Write-Line($str) {
if($env:BITWARDEN_QUIET -ne "true") {
Write-Host $str
}
}
# Intro
$year = (Get-Date).year
Write-Line @'
_ _ _ _
| |__ (_) |___ ____ _ _ __ __| | ___ _ __
| '_ \| | __\ \ /\ / / _` | '__/ _` |/ _ \ '_ \
| |_) | | |_ \ V V / (_| | | | (_| | __/ | | |
|_.__/|_|\__| \_/\_/ \__,_|_| \__,_|\___|_| |_|
'@
Write-Line "
Open source password management solutions
Copyright 2015-${year}, 8bit Solutions LLC
https://bitwarden.com, https://github.com/bitwarden
===================================================
"
if($env:BITWARDEN_QUIET -ne "true") {
Write-Line "bitwarden.ps1 version ${coreVersion}"
2019-03-25 21:46:32 +01:00
docker --version
docker-compose --version
}
Write-Line ""
2017-08-23 22:15:42 +02:00
# Commands
2018-05-31 19:43:04 +02:00
if ($install) {
Test-Output-Dir-Not-Exists
New-Item -ItemType directory -Path $output -ErrorAction Ignore | Out-Null
Get-Run-File
Invoke-Expression "& `"$scriptsDir\run.ps1`" -install -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
2017-08-19 17:51:13 +02:00
}
2018-05-31 19:43:04 +02:00
elseif ($start -Or $restart) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -restart -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
2017-08-19 17:51:13 +02:00
}
2018-05-31 19:43:04 +02:00
elseif ($update) {
Test-Output-Dir-Exists
Get-Run-File
Invoke-Expression "& `"$scriptsDir\run.ps1`" -update -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
2017-08-19 17:51:13 +02:00
}
2018-08-30 22:25:33 +02:00
elseif ($rebuild) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -rebuild -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
2018-08-30 22:25:33 +02:00
}
elseif ($updateconf) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -updateconf -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
}
2018-05-31 19:43:04 +02:00
elseif ($updatedb) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -updatedb -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
2017-08-19 17:51:13 +02:00
}
2018-05-31 19:43:04 +02:00
elseif ($stop) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -stop -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
2017-08-23 22:15:42 +02:00
}
2020-06-17 15:05:35 +02:00
elseif ($renewcert) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -renewcert -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
2020-06-17 15:05:35 +02:00
}
elseif ($updaterun) {
Test-Output-Dir-Exists
Get-Run-File
}
2018-05-31 19:43:04 +02:00
elseif ($updateself) {
Get-Self
2019-03-25 21:46:32 +01:00
Write-Line "Updated self."
2017-08-21 15:39:12 +02:00
}
2019-10-25 02:04:09 +02:00
elseif ($help) {
Show-Commands
2019-10-25 02:04:09 +02:00
}
2017-08-19 17:51:13 +02:00
else {
2019-03-25 21:46:32 +01:00
Write-Line "No command found."
2019-10-25 02:04:09 +02:00
Write-Line ""
Show-Commands
2017-08-19 17:51:13 +02:00
}