From a527d425fd63e81cd584f3f11b094dbb6c774ee1 Mon Sep 17 00:00:00 2001 From: Michiel Hazelhof Date: Tue, 12 Aug 2025 16:15:51 +0200 Subject: [PATCH] Improve naming --- .servers/serverlist.txt | 2 +- README.md | 2 +- build.ps1 | 6 +- build.sh | 248 ++++++++++++++++++++-------------------- 4 files changed, 129 insertions(+), 129 deletions(-) diff --git a/.servers/serverlist.txt b/.servers/serverlist.txt index f1debc9..3d99d6b 100644 --- a/.servers/serverlist.txt +++ b/.servers/serverlist.txt @@ -1,4 +1,4 @@ # Uncomment a line below and fill in the missing values or add your own. Every line in this file will be called by build.[sh|ps1] once the patched image is built. -# docker run -d --name bitwarden -v \logs:/var/log/bitwarden -v \bwdata:/etc/bitwarden -p 80:8080 --env-file \settings.env bitwarden-patch +# docker run -d --name bitwarden -v \logs:/var/log/bitwarden -v \bwdata:/etc/bitwarden -p 80:8080 --env-file \settings.env bitwarden-patched # # docker-compose -f /docker-compose.yml up -d diff --git a/README.md b/README.md index 6890eee..7225b9a 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ From the BitBetter directory, simply run: ./build.[sh|ps1] ``` -This will create a new self-signed certificate in the `.keys` directory if one does not already exist and then create a modified version of the official `ghcr.io/bitwarden/self-host` image called `bitwarden-patch`. +This will create a new self-signed certificate in the `.keys` directory if one does not already exist and then create a modified version of the official `ghcr.io/bitwarden/self-host` image called `bitwarden-patched`. Afterwards it will automatically generate the license generator and start all previously specified containers which are **now ready to accept self-issued licenses.** diff --git a/build.ps1 b/build.ps1 index f5271c2..4d60b6b 100644 --- a/build.ps1 +++ b/build.ps1 @@ -55,12 +55,12 @@ if ($args[0] -eq 'y') { } # stop and remove previous existing patch(ed) container -$oldinstances = docker container ps --all -f Ancestor=bitwarden-patch --format '{{.ID}}' +$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-patch --format '{{.ID}}' +$oldinstances = docker image ls bitwarden-patched --format '{{.ID}}' foreach ($instance in $oldinstances) { docker image rm $instance } @@ -92,7 +92,7 @@ docker rm bitwarden-extract 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" +docker build . --tag bitwarden-patched --file "$pwd\src\bitBetter\Dockerfile-bitwarden-patch" # start all user requested instances if (Test-Path -Path "$pwd\.servers\serverlist.txt" -PathType Leaf) { diff --git a/build.sh b/build.sh index 993a82f..c8bb337 100755 --- a/build.sh +++ b/build.sh @@ -1,125 +1,125 @@ -#!/bin/bash -set -e - -# define temporary directory -TEMPDIRECTORY="$PWD/temp" - -# define services to patch -COMPONENTS=("Api" "Identity") - -# delete old directories / files if applicable -if [ -d "$TEMPDIRECTORY" ]; then - rm -rf "$TEMPDIRECTORY" -fi - -if [ -f "$PWD/src/licenseGen/Core.dll" ]; then - rm -f "$PWD/src/licenseGen/Core.dll" -fi - -if [ -f "$PWD/src/licenseGen/cert.pfx" ]; then - rm -f "$PWD/src/licenseGen/cert.pfx" -fi - -if [ -f "$PWD/src/bitBetter/cert.cert" ]; then - rm -f "$PWD/src/bitBetter/cert.cert" -fi - -# generate keys if none are available -if [ ! -d "$PWD/.keys" ]; then - ./generateKeys.sh -fi - -# copy the key to bitBetter -cp -f "$PWD/.keys/cert.cert" "$PWD/src/bitBetter" - -# build bitBetter and clean the source directory after -docker build --no-cache -t bitbetter/bitbetter "$PWD/src/bitBetter" -rm -f "$PWD/src/bitBetter/cert.cert" - -# gather all running instances -OLDINSTANCES=$(docker container ps --all -f Name=bitwarden --format '{{.ID}}') - -# stop and remove all running instances -for INSTANCE in ${OLDINSTANCES[@]}; do - docker stop $INSTANCE - docker rm $INSTANCE -done - -# update bitwarden itself -if [ "$1" = "update" ]; then - docker pull ghcr.io/bitwarden/self-host:beta -else - read -p "Update (or get) bitwarden source container (y/n): " -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]] - then - docker pull ghcr.io/bitwarden/self-host:beta - fi -fi - -# stop and remove previous existing patch(ed) container -OLDINSTANCES=$(docker container ps --all -f Ancestor=bitwarden-patch --format '{{.ID}}') -for INSTANCE in ${OLDINSTANCES[@]}; do - docker stop $INSTANCE - docker rm $INSTANCE -done -OLDINSTANCES=$(docker image ls bitwarden-patch --format '{{.ID}}') -for INSTANCE in ${OLDINSTANCES[@]}; do - docker image rm $INSTANCE -done - -# remove old extract containers -OLDINSTANCES=$(docker container ps --all -f Name=bitwarden-extract --format '{{.ID}}') -for INSTANCE in ${OLDINSTANCES[@]}; do - docker stop $INSTANCE - docker rm $INSTANCE -done - -# start a new bitwarden instance so we can patch it -PATCHINSTANCE=$(docker run -d --name bitwarden-extract ghcr.io/bitwarden/self-host:beta) - -# create our temporary directory -mkdir $TEMPDIRECTORY - -# extract the files that need to be patched from the services that need to be patched into our temporary directory -for COMPONENT in ${COMPONENTS[@]}; do - mkdir "$TEMPDIRECTORY/$COMPONENT" - docker cp $PATCHINSTANCE:/app/$COMPONENT/Core.dll "$TEMPDIRECTORY/$COMPONENT/Core.dll" -done - -# 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" - -# start all user requested instances -if [ -f "$PWD/src/bitBetter/cert.cert" ]; then - sed -i 's/\r$//' "$PWD/.servers/serverlist.txt" - cat "$PWD/.servers/serverlist.txt" | while read -r LINE; do - if [[ $LINE == "#*" ]]; then - bash -c "$LINE" - fi - done -fi - -# remove our bitBetter image -docker image rm bitbetter/bitbetter - -# copy our patched library to the licenseGen source directory -cp -f "$TEMPDIRECTORY/Identity/Core.dll" "$PWD/src/licenseGen" -cp -f "$PWD/.keys/cert.pfx" "$PWD/src/licenseGen" - -# build the licenseGen -docker build -t bitbetter/licensegen "$PWD/src/licenseGen" - -# clean the licenseGen source directory -rm -f "$PWD/src/licenseGen/Core.dll" -rm -f "$PWD/src/licenseGen/cert.pfx" - -# remove our temporary directory +#!/bin/bash +set -e + +# define temporary directory +TEMPDIRECTORY="$PWD/temp" + +# define services to patch +COMPONENTS=("Api" "Identity") + +# delete old directories / files if applicable +if [ -d "$TEMPDIRECTORY" ]; then + rm -rf "$TEMPDIRECTORY" +fi + +if [ -f "$PWD/src/licenseGen/Core.dll" ]; then + rm -f "$PWD/src/licenseGen/Core.dll" +fi + +if [ -f "$PWD/src/licenseGen/cert.pfx" ]; then + rm -f "$PWD/src/licenseGen/cert.pfx" +fi + +if [ -f "$PWD/src/bitBetter/cert.cert" ]; then + rm -f "$PWD/src/bitBetter/cert.cert" +fi + +# generate keys if none are available +if [ ! -d "$PWD/.keys" ]; then + ./generateKeys.sh +fi + +# copy the key to bitBetter +cp -f "$PWD/.keys/cert.cert" "$PWD/src/bitBetter" + +# build bitBetter and clean the source directory after +docker build --no-cache -t bitbetter/bitbetter "$PWD/src/bitBetter" +rm -f "$PWD/src/bitBetter/cert.cert" + +# gather all running instances +OLDINSTANCES=$(docker container ps --all -f Name=bitwarden --format '{{.ID}}') + +# stop and remove all running instances +for INSTANCE in ${OLDINSTANCES[@]}; do + docker stop $INSTANCE + docker rm $INSTANCE +done + +# update bitwarden itself +if [ "$1" = "update" ]; then + docker pull ghcr.io/bitwarden/self-host:beta +else + read -p "Update (or get) bitwarden source container (y/n): " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]] + then + docker pull ghcr.io/bitwarden/self-host:beta + fi +fi + +# stop and remove previous existing patch(ed) container +OLDINSTANCES=$(docker container ps --all -f Ancestor=bitwarden-patched --format '{{.ID}}') +for INSTANCE in ${OLDINSTANCES[@]}; do + docker stop $INSTANCE + docker rm $INSTANCE +done +OLDINSTANCES=$(docker image ls bitwarden-patched --format '{{.ID}}') +for INSTANCE in ${OLDINSTANCES[@]}; do + docker image rm $INSTANCE +done + +# remove old extract containers +OLDINSTANCES=$(docker container ps --all -f Name=bitwarden-extract --format '{{.ID}}') +for INSTANCE in ${OLDINSTANCES[@]}; do + docker stop $INSTANCE + docker rm $INSTANCE +done + +# start a new bitwarden instance so we can patch it +PATCHINSTANCE=$(docker run -d --name bitwarden-extract ghcr.io/bitwarden/self-host:beta) + +# create our temporary directory +mkdir $TEMPDIRECTORY + +# extract the files that need to be patched from the services that need to be patched into our temporary directory +for COMPONENT in ${COMPONENTS[@]}; do + mkdir "$TEMPDIRECTORY/$COMPONENT" + docker cp $PATCHINSTANCE:/app/$COMPONENT/Core.dll "$TEMPDIRECTORY/$COMPONENT/Core.dll" +done + +# 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-patched --file "$PWD/src/bitBetter/Dockerfile-bitwarden-patch" + +# start all user requested instances +if [ -f "$PWD/src/bitBetter/cert.cert" ]; then + sed -i 's/\r$//' "$PWD/.servers/serverlist.txt" + cat "$PWD/.servers/serverlist.txt" | while read -r LINE; do + if [[ $LINE == "#*" ]]; then + bash -c "$LINE" + fi + done +fi + +# remove our bitBetter image +docker image rm bitbetter/bitbetter + +# copy our patched library to the licenseGen source directory +cp -f "$TEMPDIRECTORY/Identity/Core.dll" "$PWD/src/licenseGen" +cp -f "$PWD/.keys/cert.pfx" "$PWD/src/licenseGen" + +# build the licenseGen +docker build -t bitbetter/licensegen "$PWD/src/licenseGen" + +# clean the licenseGen source directory +rm -f "$PWD/src/licenseGen/Core.dll" +rm -f "$PWD/src/licenseGen/cert.pfx" + +# remove our temporary directory rm -rf "$TEMPDIRECTORY" \ No newline at end of file