-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathbitwarden.ps1
172 lines (150 loc) · 4.75 KB
/
bitwarden.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
param (
[switch] $install,
[switch] $start,
[switch] $restart,
[switch] $stop,
[switch] $update,
[switch] $rebuild,
[switch] $updateconf,
[switch] $renewcert,
[switch] $updatedb,
[switch] $updaterun,
[switch] $updateself,
[switch] $uninstall,
[switch] $help,
[string] $output = ""
)
# Setup
$scriptPath = $MyInvocation.MyCommand.Path
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
if ($output -eq "") {
$output = "${dir}\bwdata"
}
$scriptsDir = "${output}\scripts"
$bitwardenScriptUrl = "https://func.bitwarden.com/api/dl/?app=self-host&platform=windows"
$runScriptUrl = "https://func.bitwarden.com/api/dl/?app=self-host&platform=windows&variant=run"
# Please do not create pull requests modifying the version numbers.
$coreVersion = "2024.12.1"
$webVersion = "2024.12.1"
$keyConnectorVersion = "2024.8.0"
# Functions
function Get-Self {
Invoke-RestMethod -OutFile $scriptPath -Uri $bitwardenScriptUrl
}
function Get-Run-File {
if (!(Test-Path -Path $scriptsDir)) {
New-Item -ItemType directory -Path $scriptsDir | Out-Null
}
Invoke-RestMethod -OutFile $scriptsDir\run.ps1 -Uri $runScriptUrl
}
function Test-Output-Dir-Exists {
if (!(Test-Path -Path $output)) {
throw "Cannot find a Bitwarden installation at $output."
}
}
function Test-Output-Dir-Not-Exists {
if (Test-Path -Path "$output\docker") {
throw "Looks like Bitwarden is already installed at $output."
}
}
function Show-Commands {
Write-Line "
Available commands:
-install
-start
-restart
-stop
-update
-updatedb
-updaterun
-updateself
-updateconf
-uninstall
-renewcert
-rebuild
-help
See more at https://bitwarden.com/help/article/install-on-premise/#script-commands-reference
"
}
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}"
docker --version
docker-compose --version
}
Write-Line ""
# Commands
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"
}
elseif ($start -Or $restart) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -restart -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
}
elseif ($update) {
Test-Output-Dir-Exists
Get-Run-File
Invoke-Expression "& `"$scriptsDir\run.ps1`" -update -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
}
elseif ($rebuild) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -rebuild -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
}
elseif ($updateconf) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -updateconf -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
}
elseif ($updatedb) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -updatedb -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
}
elseif ($stop) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -stop -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
}
elseif ($renewcert) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -renewcert -outputDir `"$output`" -coreVersion $coreVersion -webVersion $webVersion -keyConnectorVersion $keyConnectorVersion"
}
elseif ($updaterun) {
Test-Output-Dir-Exists
Get-Run-File
}
elseif ($updateself) {
Get-Self
Write-Line "Updated self."
}
elseif ($uninstall) {
Test-Output-Dir-Exists
Invoke-Expression "& `"$scriptsDir\run.ps1`" -uninstall -outputDir `"$output`" "
}
elseif ($help) {
Show-Commands
}
else {
Write-Line "No command found."
Write-Line ""
Show-Commands
}