Add comments and fix minor issues

This commit is contained in:
Michiel Hazelhof 2023-01-03 11:59:14 +01:00
parent 86ca7b4100
commit 34b274f24a
No known key found for this signature in database
GPG Key ID: EECB9B96355B5EBF
1 changed files with 46 additions and 18 deletions

View File

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