Files
server/scripts/bitwarden.ps1

110 lines
3.0 KiB
PowerShell
Raw Normal View History

2017-08-19 11:51:13 -04:00
param (
[switch] $install,
2017-08-21 11:58:15 -04:00
[switch] $start,
2017-08-21 09:40:10 -04:00
[switch] $restart,
2017-08-21 09:39:12 -04:00
[switch] $stop,
2017-08-19 11:51:13 -04:00
[switch] $update,
2018-08-30 16:25:33 -04:00
[switch] $rebuild,
2017-08-19 11:51:13 -04:00
[switch] $updatedb,
2017-08-23 16:15:42 -04:00
[switch] $updateself,
2017-08-21 08:49:44 -04:00
[string] $output = ""
2017-08-19 11:51:13 -04:00
)
2017-08-21 10:58:00 -04:00
$year = (Get-Date).year
2017-08-19 11:51:13 -04:00
Write-Host @'
_ _ _ _
| |__ (_) |___ ____ _ _ __ __| | ___ _ __
| '_ \| | __\ \ /\ / / _` | '__/ _` |/ _ \ '_ \
| |_) | | |_ \ V V / (_| | | | (_| | __/ | | |
|_.__/|_|\__| \_/\_/ \__,_|_| \__,_|\___|_| |_|
'@
Write-Host "
Open source password management solutions
2017-08-21 10:58:00 -04:00
Copyright 2015-${year}, 8bit Solutions LLC
2017-08-19 11:51:13 -04:00
https://bitwarden.com, https://github.com/bitwarden
2017-08-23 16:15:42 -04:00
===================================================
2017-08-19 11:51:13 -04:00
"
2017-08-23 16:29:55 -04:00
docker --version
docker-compose --version
2017-08-23 16:33:41 -04:00
echo ""
2017-08-23 16:15:42 -04:00
# Setup
2017-08-23 16:22:02 -04:00
$scriptPath = $MyInvocation.MyCommand.Path
2017-08-19 11:51:13 -04:00
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
2018-05-31 13:43:04 -04:00
if ($output -eq "") {
$output = "${dir}\bwdata"
2017-08-21 08:49:44 -04:00
}
$scriptsDir = "${output}\scripts"
2019-01-18 22:23:46 -05:00
$githubBaseUrl = "https://raw.githubusercontent.com/bitwarden/server/master"
2019-01-05 11:26:02 -05:00
$coreVersion = "1.29.0"
$webVersion = "2.8.0"
2017-08-19 11:51:13 -04:00
2017-08-23 16:15:42 -04:00
# Functions
function Download-Self {
2017-08-23 16:22:02 -04:00
Invoke-RestMethod -OutFile $scriptPath -Uri "${githubBaseUrl}/scripts/bitwarden.ps1"
2017-08-23 16:15:42 -04:00
}
function Download-Run-File {
2018-05-31 13:43:04 -04:00
if (!(Test-Path -Path $scriptsDir)) {
2017-09-18 12:11:03 -04:00
New-Item -ItemType directory -Path $scriptsDir | Out-Null
}
2017-08-23 16:15:42 -04:00
Invoke-RestMethod -OutFile $scriptsDir\run.ps1 -Uri "${githubBaseUrl}/scripts/run.ps1"
}
2017-09-18 12:11:03 -04:00
function Check-Output-Dir-Exists {
2018-05-31 13:43:04 -04:00
if (!(Test-Path -Path $output)) {
2018-05-31 21:47:06 -04:00
throw "Cannot find a Bitwarden installation at $output."
2017-09-18 12:11:03 -04:00
}
}
function Check-Output-Dir-Not-Exists {
if (Test-Path -Path "$output\docker") {
2018-05-31 21:47:06 -04:00
throw "Looks like Bitwarden is already installed at $output."
2017-09-18 12:11:03 -04:00
}
2017-08-23 16:15:42 -04:00
}
# Commands
2018-05-31 13:43:04 -04:00
if ($install) {
2017-09-18 12:11:03 -04:00
Check-Output-Dir-Not-Exists
New-Item -ItemType directory -Path $output -ErrorAction Ignore | Out-Null
2017-11-08 23:51:24 -05:00
Download-Run-File
Invoke-Expression "& `"$scriptsDir\run.ps1`" -install -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion"
2017-08-19 11:51:13 -04:00
}
2018-05-31 13:43:04 -04:00
elseif ($start -Or $restart) {
2017-09-18 12:11:03 -04:00
Check-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -restart -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion"
2017-08-19 11:51:13 -04:00
}
2018-05-31 13:43:04 -04:00
elseif ($update) {
2017-09-18 12:11:03 -04:00
Check-Output-Dir-Exists
2017-11-08 22:24:23 -05:00
Download-Run-File
Invoke-Expression "& `"$scriptsDir\run.ps1`" -update -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion"
2017-08-19 11:51:13 -04:00
}
2018-08-30 16:25:33 -04:00
elseif ($rebuild) {
Check-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -rebuild -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion"
2018-08-30 16:25:33 -04:00
}
2018-05-31 13:43:04 -04:00
elseif ($updatedb) {
2017-09-18 12:11:03 -04:00
Check-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -updatedb -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion"
2017-08-19 11:51:13 -04:00
}
2018-05-31 13:43:04 -04:00
elseif ($stop) {
2017-09-18 12:11:03 -04:00
Check-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -stop -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion"
2017-08-23 16:15:42 -04:00
}
2018-05-31 13:43:04 -04:00
elseif ($updateself) {
2017-08-23 16:15:42 -04:00
Download-Self
echo "Updated self."
2017-08-21 09:39:12 -04:00
}
2017-08-19 11:51:13 -04:00
else {
echo "No command found."
}