2023-01-03 11:59:14 +01:00
|
|
|
# define temporary directory
|
|
|
|
$tempdirectory = "$pwd\temp"
|
|
|
|
# define services to patch
|
|
|
|
$components = "Api","Identity"
|
|
|
|
|
|
|
|
# delete old directories / files if applicable
|
|
|
|
if (Test-Path "$tempdirectory") {
|
|
|
|
Remove-Item "$tempdirectory" -Recurse -Force
|
2023-01-02 20:59:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Test-Path -Path "$pwd\licenseGen\Core.dll" -PathType Leaf) {
|
|
|
|
Remove-Item "$pwd\licenseGen\Core.dll" -Force
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Test-Path -Path "$pwd\licenseGen\cert.pfx" -PathType Leaf) {
|
|
|
|
Remove-Item "$pwd\licenseGen\cert.pfx" -Force
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Test-Path -Path "$pwd\bitBetter\cert.cert" -PathType Leaf) {
|
|
|
|
Remove-Item "$pwd\bitBetter\cert.cert" -Force
|
|
|
|
}
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# generate keys if none are available
|
2023-01-02 20:59:14 +01:00
|
|
|
if (!(Test-Path "$pwd\.keys")) {
|
|
|
|
.\generateKeys.ps1
|
|
|
|
}
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# copy the key to bitBetter and licenseGen
|
2023-01-02 20:59:14 +01:00
|
|
|
Copy-Item "$pwd\.keys\cert.cert" -Destination "$pwd\bitBetter"
|
|
|
|
Copy-Item "$pwd\.keys\cert.pfx" -Destination "$pwd\licenseGen"
|
2023-01-03 11:59:14 +01:00
|
|
|
|
|
|
|
# build bitBetter and clean the source directory after
|
2023-01-02 20:59:14 +01:00
|
|
|
docker build -t bitbetter/bitbetter "$pwd\bitBetter"
|
|
|
|
Remove-Item "$pwd\bitBetter\cert.cert" -Force
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# gather all running instances
|
2023-01-02 20:59:14 +01:00
|
|
|
$oldinstances = docker container ps --all -f Name=bitwarden --format '{{.ID}}'
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# stop all running instances
|
2023-01-02 20:59:14 +01:00
|
|
|
foreach ($instance in $oldinstances) {
|
|
|
|
docker stop $instance
|
|
|
|
docker rm $instance
|
|
|
|
}
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# update bitwarden itself
|
|
|
|
$confirmation = Read-Host "Update bitwarden source container"
|
|
|
|
if ($confirmation -eq 'y') {
|
|
|
|
docker pull bitwarden/self-host:beta
|
|
|
|
}
|
2023-01-02 20:59:14 +01:00
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# stop and remove previous existing patch(ed) container
|
2023-01-02 20:59:14 +01:00
|
|
|
docker stop bitwarden-patch
|
|
|
|
docker rm bitwarden-patch
|
|
|
|
docker image rm bitwarden-patch
|
2023-01-03 11:59:14 +01:00
|
|
|
|
|
|
|
# start a new bitwarden instance so we can patch it
|
2023-01-02 20:59:14 +01:00
|
|
|
$patchinstance = docker run -d --name bitwarden-patch bitwarden/self-host:beta
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# create our temporary directory
|
|
|
|
New-item -ItemType Directory -Path $tempdirectory
|
|
|
|
|
|
|
|
# extract the files that need to be patched from the services that need to be patched into our temporary directory
|
2023-01-02 20:59:14 +01:00
|
|
|
foreach ($component in $components) {
|
2023-01-03 11:59:14 +01:00
|
|
|
New-item -itemtype Directory -path "$tempdirectory\$component"
|
|
|
|
docker cp $patchinstance`:/app/$component/Core.dll "$tempdirectory\$component\Core.dll"
|
2023-01-02 20:59:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# run bitBetter, this applies our patches to the required files
|
|
|
|
docker run -v "$tempdirectory`:/app/mount" --rm bitbetter/bitbetter
|
2023-01-02 20:59:14 +01:00
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# copy the patched files back into the temporary instance
|
2023-01-02 20:59:14 +01:00
|
|
|
foreach ($component in $components) {
|
2023-01-03 11:59:14 +01:00
|
|
|
docker cp "$tempdirectory\$component\Core.dll" $patchinstance`:/app/$component/Core.dll
|
2023-01-02 20:59:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# create a new image from our patched instanced
|
2023-01-02 20:59:14 +01:00
|
|
|
docker commit $patchinstance bitwarden-patch
|
2023-01-03 11:59:14 +01:00
|
|
|
|
|
|
|
# stop and remove our temporary container
|
2023-01-02 20:59:14 +01:00
|
|
|
docker stop bitwarden-patch
|
|
|
|
docker rm bitwarden-patch
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# copy our patched library to the licenseGen source directory
|
|
|
|
Copy-Item "$tempdirectory\Identity\Core.dll" -Destination "$pwd\licenseGen"
|
2023-01-03 11:36:37 +01:00
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# remove our temporary directory
|
|
|
|
Remove-Item "$tempdirectory" -Recurse -Force
|
2023-01-02 20:59:14 +01:00
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# start all user requested instances
|
|
|
|
foreach($line in Get-Content "$pwd\.servers\serverlist.txt") {
|
|
|
|
Invoke-Expression "& $line"
|
2023-01-02 20:59:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# remove our bitBetter image
|
2023-01-02 20:59:14 +01:00
|
|
|
docker image rm bitbetter/bitbetter
|
|
|
|
|
2023-01-03 11:59:14 +01:00
|
|
|
# build the licenseGen
|
2023-01-02 20:59:14 +01:00
|
|
|
docker build -t bitbetter/licensegen "$pwd\licenseGen"
|
2023-01-03 11:59:14 +01:00
|
|
|
|
|
|
|
# clean the licenseGen source directory
|
2023-01-02 20:59:14 +01:00
|
|
|
Remove-Item "$pwd\licenseGen\Core.dll" -Force
|
|
|
|
Remove-Item "$pwd\licenseGen\cert.pfx" -Force
|