mirror of
https://github.com/jakeswenson/BitBetter.git
synced 2025-12-16 19:26:18 +00:00
Update and fix unified branch (#257)
* Upstream patches * Fix license generator according to upstream changes (#245) (#249) * Test generating user and organization licenses during build check (#252) * Fix ps1 script and update language * Update class path * Cleanup code * Cleanup code * Cleanup code * Refactor and fixes * Copy all files * Copy files only when needed * Make call consistent * Simplify call * Clarify language * Reuse code * Cleanup * Cleanup * Remove NewtonSoft.Json * Upgrade dnlib * Cleanup * Fix path issue * Fix comparator * Cleanup circleci * Fix type * Fix circleci * Properly detect previous version * Add missing parameter * Better detect running patched containers * Improve naming * Fix line endings * Fix typo * Add comment * Fix tabs * Cleanup org license * Use proper file extension * Add missing file * Migrate cert.cert if exists * Check for the correct file * Fix character check * Add comment * Add more documentation * Add proper line endings * Add potentially correct line * Add auto restart * Update comment * Improve consistency between bash and powerhell * Update documentation * Detect buildx * Fix spelling mistake * Fix check order and improve verbosity
This commit is contained in:
85
build.ps1
85
build.ps1
@@ -1,13 +1,16 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$PSNativeCommandUseErrorActionPreference = $true
|
||||
|
||||
# detect buildx, ErrorActionPreference will ensure the script stops execution if not found
|
||||
docker buildx version
|
||||
|
||||
# define temporary directory
|
||||
$tempdirectory = "$pwd\temp"
|
||||
# define services to patch
|
||||
$components = "Api","Identity"
|
||||
|
||||
# delete old directories / files if applicable
|
||||
if (Test-Path "$tempdirectory") {
|
||||
if (Test-Path "$tempdirectory" -PathType Container) {
|
||||
Remove-Item "$tempdirectory" -Recurse -Force
|
||||
}
|
||||
|
||||
@@ -19,24 +22,27 @@ if (Test-Path -Path "$pwd\src\licenseGen\cert.pfx" -PathType Leaf) {
|
||||
Remove-Item "$pwd\src\licenseGen\cert.pfx" -Force
|
||||
}
|
||||
|
||||
if (Test-Path -Path "$pwd\src\bitBetter\cert.cert" -PathType Leaf) {
|
||||
Remove-Item "$pwd\src\bitBetter\cert.cert" -Force
|
||||
if (Test-Path -Path "$pwd\src\bitBetter\cert.cer" -PathType Leaf) {
|
||||
Remove-Item "$pwd\src\bitBetter\cert.cer" -Force
|
||||
}
|
||||
|
||||
if (Test-Path "$pwd\.keys\cert.cert" -PathType Leaf) {
|
||||
Rename-Item -Path "$pwd\.keys\cert.cert" -NewName "$pwd\.keys\cert.cer"
|
||||
}
|
||||
|
||||
# generate keys if none are available
|
||||
if (!(Test-Path "$pwd\.keys")) {
|
||||
if (!(Test-Path "$pwd\.keys" -PathType Container)) {
|
||||
.\generateKeys.ps1
|
||||
}
|
||||
|
||||
# copy the key to bitBetter and licenseGen
|
||||
Copy-Item "$pwd\.keys\cert.cert" -Destination "$pwd\src\bitBetter"
|
||||
Copy-Item "$pwd\.keys\cert.pfx" -Destination "$pwd\src\licenseGen"
|
||||
# copy the key to bitBetter
|
||||
Copy-Item "$pwd\.keys\cert.cer" -Destination "$pwd\src\bitBetter"
|
||||
|
||||
# build bitBetter and clean the source directory after
|
||||
docker build --no-cache -t bitbetter/bitbetter "$pwd\src\bitBetter"
|
||||
Remove-Item "$pwd\src\bitBetter\cert.cert" -Force
|
||||
Remove-Item "$pwd\src\bitBetter\cert.cer" -Force
|
||||
|
||||
# gather all running instances
|
||||
# gather all running instances, cannot run a wildcard filter on Ancestor= :(, does find all where name = *bitwarden*
|
||||
$oldinstances = docker container ps --all -f Name=bitwarden --format '{{.ID}}'
|
||||
|
||||
# stop and remove all running instances
|
||||
@@ -46,25 +52,35 @@ foreach ($instance in $oldinstances) {
|
||||
}
|
||||
|
||||
# update bitwarden itself
|
||||
if ($args[0] -eq 'y')
|
||||
{
|
||||
if ($args[0] -eq 'update') {
|
||||
docker pull ghcr.io/bitwarden/self-host:beta
|
||||
}
|
||||
else
|
||||
{
|
||||
$confirmation = Read-Host "Update (or get) bitwarden source container"
|
||||
} else {
|
||||
$confirmation = Read-Host "Update (or get) bitwarden source container (y/n)"
|
||||
if ($confirmation -eq 'y') {
|
||||
docker pull ghcr.io/bitwarden/self-host:beta
|
||||
}
|
||||
}
|
||||
|
||||
# remove previous existing patch(ed) image
|
||||
if (docker image ls -q bitwarden-patch) {
|
||||
docker image rm bitwarden-patch
|
||||
# stop and remove previous existing patch(ed) container
|
||||
$oldinstances = docker container ps --all -f Ancestor=bitwarden-patched --format '{{.ID}}'
|
||||
foreach ($instance in $oldinstances) {
|
||||
docker stop $instance
|
||||
docker rm $instance
|
||||
}
|
||||
$oldinstances = docker image ls bitwarden-patched --format '{{.ID}}'
|
||||
foreach ($instance in $oldinstances) {
|
||||
docker image rm $instance
|
||||
}
|
||||
|
||||
# remove old extract containers
|
||||
$oldinstances = docker container ps --all -f Name=bitwarden-extract --format '{{.ID}}'
|
||||
foreach ($instance in $oldinstances) {
|
||||
docker stop $instance
|
||||
docker rm $instance
|
||||
}
|
||||
|
||||
# start a new bitwarden instance so we can patch it
|
||||
$patchinstance = docker run -d --name bitwarden-patch ghcr.io/bitwarden/self-host:beta
|
||||
$patchinstance = docker run -d --name bitwarden-extract ghcr.io/bitwarden/self-host:beta
|
||||
|
||||
# create our temporary directory
|
||||
New-item -ItemType Directory -Path $tempdirectory
|
||||
@@ -75,33 +91,38 @@ foreach ($component in $components) {
|
||||
docker cp $patchinstance`:/app/$component/Core.dll "$tempdirectory\$component\Core.dll"
|
||||
}
|
||||
|
||||
# stop and remove our temporary container
|
||||
docker stop bitwarden-extract
|
||||
docker rm bitwarden-extract
|
||||
|
||||
# run bitBetter, this applies our patches to the required files
|
||||
docker run -v "$tempdirectory`:/app/mount" --rm bitbetter/bitbetter
|
||||
|
||||
# create a new image with the patched files
|
||||
docker build . --tag bitwarden-patch --file "$pwd\src\bitBetter\Dockerfile-bitwarden-patch"
|
||||
|
||||
# stop and remove our temporary container
|
||||
docker stop bitwarden-patch
|
||||
docker rm bitwarden-patch
|
||||
|
||||
# copy our patched library to the licenseGen source directory
|
||||
Copy-Item "$tempdirectory\Identity\Core.dll" -Destination "$pwd\src\licenseGen"
|
||||
|
||||
# remove our temporary directory
|
||||
Remove-Item "$tempdirectory" -Recurse -Force
|
||||
docker build . --tag bitwarden-patched --file "$pwd\src\bitBetter\Dockerfile-bitwarden-patch"
|
||||
|
||||
# start all user requested instances
|
||||
foreach($line in Get-Content "$pwd\.servers\serverlist.txt") {
|
||||
Invoke-Expression "& $line"
|
||||
if (Test-Path -Path "$pwd\.servers\serverlist.txt" -PathType Leaf) {
|
||||
foreach($line in Get-Content "$pwd\.servers\serverlist.txt") {
|
||||
if (!($line.StartsWith("#"))) {
|
||||
Invoke-Expression "& $line"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# remove our bitBetter image
|
||||
docker image rm bitbetter/bitbetter
|
||||
|
||||
# copy our patched library to the licenseGen source directory
|
||||
Copy-Item "$tempdirectory\Identity\Core.dll" -Destination "$pwd\src\licenseGen"
|
||||
Copy-Item "$pwd\.keys\cert.pfx" -Destination "$pwd\src\licenseGen"
|
||||
|
||||
# build the licenseGen
|
||||
docker build -t bitbetter/licensegen "$pwd\src\licenseGen"
|
||||
|
||||
# clean the licenseGen source directory
|
||||
Remove-Item "$pwd\src\licenseGen\Core.dll" -Force
|
||||
Remove-Item "$pwd\src\licenseGen\cert.pfx" -Force
|
||||
|
||||
# remove our temporary directory
|
||||
Remove-Item "$tempdirectory" -Recurse -Force
|
||||
Reference in New Issue
Block a user