Fix scripts

This commit is contained in:
Michiel Hazelhof 2023-01-04 01:02:07 +01:00
parent bb086b99dd
commit 8a69076dd1
No known key found for this signature in database
GPG Key ID: EECB9B96355B5EBF
4 changed files with 120 additions and 22 deletions

107
build.sh
View File

@ -0,0 +1,107 @@
#!/bin/bash
# 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/licenseGen/Core.dll" ]; then
rm -f "$PWD/licenseGen/Core.dll"
fi
if [ -f "$PWD/licenseGen/cert.pfx" ]; then
rm -f "$PWD/licenseGen/cert.pfx"
fi
if [ -f "$PWD/bitBetter/cert.cert" ]; then
rm -f "$PWD/bitBetter/cert.cert"
fi
# generate keys if none are available
if [ ! -d "$PWD/.keys" ]; then
./generateKeys.sh
fi
# copy the key to bitBetter and licenseGen
cp -f "$PWD/.keys/cert.cert" "$PWD/bitBetter"
cp -f "$PWD/.keys/cert.pfx" "$PWD/licenseGen"
# build bitBetter and clean the source directory after
docker build -t bitbetter/bitbetter "$PWD/bitBetter"
rm -f "$PWD/bitBetter/cert.cert"
# gather all running instances
OLDINSTANCES=$(docker container ps --all -f Name=bitwarden --format '{{.ID}}')
# stop all running instances
for INSTANCE in ${OLDINSTANCES[@]}; do
docker stop $INSTANCE
docker rm $INSTANCE
done
# update bitwarden itself
read -p "Update (or get) bitwarden source container: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
docker pull bitwarden/self-host:beta
fi
# stop and remove previous existing patch(ed) container
docker stop bitwarden-patch
docker 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)
# 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
# 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
for COMPONENT in ${COMPONENTS[@]}; do
docker cp "$TEMPDIRECTORY/$COMPONENT/Core.dll" $PATCHINSTANCE:/app/$COMPONENT/Core.dll
done
# create a new image from our patched instanced
docker commit $PATCHINSTANCE 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
cp -f "$TEMPDIRECTORY/Identity/Core.dll" "$PWD/licenseGen"
# remove our temporary directory
rm -rf "$TEMPDIRECTORY"
# start all user requested instances
cat "$PWD/.servers/serverlist.txt" | while read LINE; do
bash -c "$LINE"
done
# remove our bitBetter image
docker image rm bitbetter/bitbetter
# build the licenseGen
docker build -t bitbetter/licensegen "$PWD/licenseGen"
# clean the licenseGen source directory
rm -f "$PWD/licenseGen/Core.dll"
rm -f "$PWD/licenseGen/cert.pfx"

View File

@ -1,21 +1,17 @@
#!/bin/sh
#!/bin/bash
# Check for openssl
command -v openssl >/dev/null 2>&1 || { echo >&2 "openssl required but not found. Aborting."; exit 1; }
DIR=`dirname "$0"`
DIR=`exec 2>/dev/null;(cd -- "$DIR") && cd -- "$DIR"|| cd "$DIR"; unset PWD; /usr/bin/pwd || /bin/pwd || pwd`
DIR="$DIR/.keys"
DIR="$PWD/.keys"
if [ ! -d "$DIR" ]; then
mkdir $DIR
# if previous keys exist, remove them
if [ -d "$DIR" ]; then
rm -rf "$DIR"
fi
# Remove any existing key files
[ ! -e "$DIR/cert.pem" ] || rm "$DIR/cert.pem"
[ ! -e "$DIR/key.pem" ] || rm "$DIR/key.pem"
[ ! -e "$DIR/cert.cert" ] || rm "$DIR/cert.cert"
[ ! -e "$DIR/cert.pfx" ] || rm "$DIR/cert.pfx"
# create new directory
mkdir "$DIR"
# Generate new keys
openssl req -x509 -newkey rsa:4096 -keyout "$DIR/key.pem" -out "$DIR/cert.cert" -days 36500 -subj '/CN=www.mydom.com/O=My Company Name LTD./C=US' -outform DER -passout pass:test

View File

@ -8,8 +8,7 @@ if ($($args.Count) -lt 1) {
}
if ($args[0] = "interactive") {
$shiftedarray = $args[1 .. ($args.count-1)]
docker run -it --rm bitbetter/licensegen "$shiftedarray"
docker run -it --rm bitbetter/licensegen interactive
} else {
docker run bitbetter/licensegen "$shiftedarray"
docker run bitbetter/licensegen $args
}

View File

@ -1,9 +1,6 @@
#!/bin/sh
#!/bin/bash
DIR=`dirname "$0"`
DIR=`exec 2>/dev/null;(cd -- "$DIR") && cd -- "$DIR"|| cd "$DIR"; unset PWD; /usr/bin/pwd || /bin/pwd || pwd`
if [ "$#" -lt "2" ]; then
if [ $# -lt 1 ]; then
echo "USAGE: <License Gen action> [License Gen args...]"
echo "ACTIONS:"
echo " interactive"
@ -13,8 +10,7 @@ if [ "$#" -lt "2" ]; then
fi
if [ "$1" = "interactive" ]; then
shift
docker run -it --rm bitbetter/licensegen "$@"
docker run -it --rm bitbetter/licensegen interactive
else
docker run --rm bitbetter/licensegen "$@"
docker run --rm bitbetter/licensegen "$@"
fi