mirror of
https://github.com/jakeswenson/BitBetter.git
synced 2026-07-21 15:49:49 +00:00
Compare commits
24 Commits
copilot/up
...
lite
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
287b6a4d34 | ||
|
|
d305a3f202 | ||
|
|
389be8cea8 | ||
|
|
f6d7470ce8 | ||
|
|
9bc010cb57 | ||
|
|
29add24126 | ||
|
|
3689cc5ba1 | ||
|
|
34da077778 | ||
|
|
a3803cb3bc | ||
|
|
01cdfa2842 | ||
|
|
076b0a624b | ||
|
|
3d4c10d6f6 | ||
|
|
1597800b89 | ||
|
|
02740e84b6 | ||
|
|
d71aa84e52 | ||
|
|
770dcd33f6 | ||
|
|
b6d2c9244c | ||
|
|
b47fe37279 | ||
|
|
f75731633c | ||
|
|
0a45513872 | ||
|
|
c8192610dc | ||
|
|
e4da85d46e | ||
|
|
38e6ebc5f9 | ||
|
|
d4abc9e5b7 |
@@ -1,4 +1,4 @@
|
|||||||
version: 2
|
version: 2.1
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
machine: true
|
machine: true
|
||||||
@@ -9,16 +9,13 @@ jobs:
|
|||||||
command: date
|
command: date
|
||||||
- run:
|
- run:
|
||||||
name: Generate Keys
|
name: Generate Keys
|
||||||
command: ./.keys/generate-keys.sh
|
command: ./generateKeys.sh
|
||||||
- run:
|
- run:
|
||||||
name: Build script
|
name: Build script
|
||||||
command: ./build.sh
|
command: ./build.sh update
|
||||||
- run:
|
|
||||||
name: Build licenseGen
|
|
||||||
command: ./src/licenseGen/build.sh
|
|
||||||
- run:
|
- run:
|
||||||
name: Test generating user license
|
name: Test generating user license
|
||||||
command: ./src/licenseGen/run.sh ./.keys/cert.pfx user TestName TestEmail@example.com 4a619d4a-522d-4c70-8596-affb5b607c23
|
command: ./licenseGen.sh user TestName TestEmail@example.com 4a619d4a-522d-4c70-8596-affb5b607c23
|
||||||
- run:
|
- run:
|
||||||
name: Test generating organization license
|
name: Test generating organization license
|
||||||
command: ./src/licenseGen/run.sh ./.keys/cert.pfx org TestName TestEmail@example.com 4a619d4a-522d-4c70-8596-affb5b607c23
|
command: ./licenseGen.sh org TestName TestEmail@example.com 4a619d4a-522d-4c70-8596-affb5b607c23
|
||||||
19
.editorconfig
Normal file
19
.editorconfig
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
root=true
|
||||||
|
|
||||||
|
###############################
|
||||||
|
# Core EditorConfig Options #
|
||||||
|
###############################
|
||||||
|
# All files
|
||||||
|
[*]
|
||||||
|
indent_style=tab
|
||||||
|
indent_size=4
|
||||||
|
trim_trailing_whitespace=true
|
||||||
|
end_of_line=lf
|
||||||
|
charset=utf-8
|
||||||
|
|
||||||
|
[*.{cs}]
|
||||||
|
insert_final_newline=false
|
||||||
|
|
||||||
|
[*.{md,mkdn}]
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
indent_style = space
|
||||||
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* text eol=lf
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,8 +1,12 @@
|
|||||||
.idea/
|
.idea/
|
||||||
bin/
|
bin/
|
||||||
obj/
|
obj/
|
||||||
|
src/licenseGen/.vs/*
|
||||||
|
src/bitBetter/.vs/*
|
||||||
*.dll
|
*.dll
|
||||||
*.pem
|
*.pem
|
||||||
.vscode/
|
.vscode/
|
||||||
*.pfx
|
*.pfx
|
||||||
*.cert
|
*.cer
|
||||||
|
*.vsidx
|
||||||
|
.DS_Store
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# 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`
|
|
||||||
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
# 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
|
|
||||||
openssl x509 -inform DER -in "$DIR/cert.cert" -out "$DIR/cert.pem"
|
|
||||||
openssl pkcs12 -export -out "$DIR/cert.pfx" -inkey "$DIR/key.pem" -in "$DIR/cert.pem" -passin pass:test -passout pass:test -certpbe AES-256-CBC -keypbe AES-256-CBC -macalg SHA256
|
|
||||||
|
|
||||||
ls
|
|
||||||
4
.servers/serverlist.txt
Normal file
4
.servers/serverlist.txt
Normal file
@@ -0,0 +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 --restart=always -v <full-local-path>\logs:/var/log/bitwarden -v <full-local-path>\bwdata:/etc/bitwarden -p 80:8080 --env-file <full-local-path>\settings.env bitwarden-patched
|
||||||
|
# <OR>
|
||||||
|
# docker-compose -f <full-local-path>/docker-compose.yml up -d
|
||||||
167
README.md
167
README.md
@@ -1,14 +1,14 @@
|
|||||||
# BitBetter
|
# BitBetter lite
|
||||||
|
|
||||||
BitBetter is is a tool to modify Bitwarden's core dll to allow you to generate your own individual and organisation licenses. **You must have an existing installation of Bitwarden for BitBetter to modify.**
|
BitBetter is is a tool to modify Bitwarden's core dll to allow you to generate your own individual and organisation licenses.
|
||||||
|
|
||||||
Please see the FAQ below for details on why this software was created.
|
Please see the FAQ below for details on why this software was created.
|
||||||
|
|
||||||
Looking for a solution to the Lite (formerly unified) version of bitwarden, [go to the Lite branch](../../tree/lite).
|
Be aware that this branch is **only** for the lite (formerly unified) version of bitwarden. It has been rewritten and works in different ways than the master branch.
|
||||||
|
|
||||||
_Beware! BitBetter does janky stuff to rewrite the bitwarden core dll and allow the installation of a self signed certificate. Use at your own risk!_
|
_Beware! BitBetter is a solution that generates a personal certificate and uses that to generate custom licences. This requires (automated) modifying of libraries. Use at your own risk!_
|
||||||
|
|
||||||
Credit to https://github.com/h44z/BitBetter and https://github.com/jakeswenson/BitBetter
|
Credit to https://github.com/h44z/BitBetter and https://github.com/jakeswenson/BitBetter and https://github.com/GieltjE/BitBetter
|
||||||
|
|
||||||
# Table of Contents
|
# Table of Contents
|
||||||
- [BitBetter](#bitbetter)
|
- [BitBetter](#bitbetter)
|
||||||
@@ -27,19 +27,19 @@ Credit to https://github.com/h44z/BitBetter and https://github.com/jakeswenson/B
|
|||||||
- [Footnotes](#footnotes)
|
- [Footnotes](#footnotes)
|
||||||
|
|
||||||
# Getting Started
|
# Getting Started
|
||||||
The following instructions are for unix-based systems (Linux, BSD, macOS), it is possible to use a Windows systems assuming you are able to enable and install [WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
|
The following instructions are for unix-based systems (Linux, BSD, macOS) and Windows, just choose the correct script extension (.sh or .ps1 respectively).
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
Aside from docker, which you also need for Bitwarden, BitBetter requires the following:
|
Aside from docker, which you also need for Bitwarden, BitBetter requires the following:
|
||||||
|
|
||||||
* Bitwarden (tested with 1.47.1, might work on lower versions)
|
* Bitwarden (tested with 2025.11.1 might work on lower versions), for safety always stay up to date
|
||||||
* openssl (probably already installed on most Linux or WSL systems, any version should work)
|
* openssl (probably already installed on most Linux or WSL systems, any version should work, on Windows it will be auto installed using winget)
|
||||||
|
|
||||||
## Setting up BitBetter
|
## Setting up BitBetter
|
||||||
With your dependencies installed, begin the installation of BitBetter by downloading it through Github or using the git command:
|
With your dependencies installed, begin the installation of BitBetter by downloading it through Github or using the git command:
|
||||||
|
|
||||||
```bash
|
```
|
||||||
git clone https://github.com/jakeswenson/BitBetter.git
|
git clone https://github.com/jakeswenson/BitBetter.git -b lite
|
||||||
```
|
```
|
||||||
|
|
||||||
### Optional: Manually generating Certificate & Key
|
### Optional: Manually generating Certificate & Key
|
||||||
@@ -48,126 +48,90 @@ If you wish to generate your self-signed cert & key manually, you can run the fo
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd .keys
|
cd .keys
|
||||||
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.cert -days 36500 -outform DER -passout pass:test
|
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.cer -days 36500 -outform DER -passout pass:test
|
||||||
openssl x509 -inform DER -in cert.cert -out cert.pem
|
openssl x509 -inform DER -in cert.cer -out cert.pem
|
||||||
openssl pkcs12 -export -out cert.pfx -inkey key.pem -in cert.pem -passin pass:test -passout pass:test
|
openssl pkcs12 -export -out cert.pfx -inkey key.pem -in cert.pem -passin pass:test -passout pass:test
|
||||||
```
|
```
|
||||||
|
|
||||||
> Note that the password here must be `test`.<sup>[1](#f1)</sup>
|
> Note that the password here must be `test`.<sup>[1](#f1)</sup>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
## Building BitBetter
|
## Building BitBetter
|
||||||
|
|
||||||
Now that you've set up your build environment, you can **run the main build script** to generate a modified version of the `bitwarden/api` and `bitwarden/identity` docker images.
|
Now that you've set up your build environment, we need to specify which servers to start after the work is done.
|
||||||
|
The scripts supports running and patching multi instances.
|
||||||
|
|
||||||
|
Edit the .servers/serverlist.txt file and fill in the missing values, they can be replaced with existing installation values.
|
||||||
|
This file may be empty, but there will be no containers will be spun up automatically.
|
||||||
|
|
||||||
|
Now it is time to **run the main build script** to generate a modified version of the `ghcr.io/bitwarden/lite` docker image and the license generator.
|
||||||
|
|
||||||
From the BitBetter directory, simply run:
|
From the BitBetter directory, simply run:
|
||||||
```bash
|
```
|
||||||
./build.sh
|
./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 `bitwarden/api` called `bitbetter/api` and a modified version of the `bitwarden/identity` called `bitbetter/identity`.
|
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/lite` image called `bitwarden-patched`.
|
||||||
|
|
||||||
By default, the build script runs in **fast patch mode**: it pulls the official Bitwarden images from the GitHub Container Registry and patches the license certificate directly inside them — no local compilation required.
|
Afterwards it will automatically generate the license generator and start all previously specified containers which are **now ready to accept self-issued licenses.**
|
||||||
|
|
||||||
To instead **build from source**, set the `BITBETTER_BUILD_FROM_SOURCE` environment variable to `1` before running the script:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
BITBETTER_BUILD_FROM_SOURCE=1 ./build.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
In source build mode the script clones the Bitwarden server repository at the matching version tag, replaces the embedded license certificate, and compiles the `api` and `identity` images from scratch. This takes considerably longer but gives you full control over the build.
|
|
||||||
|
|
||||||
You may now simply create the file `/path/to/bwdata/docker/docker-compose.override.yml` with the following contents to utilize the modified images.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
services:
|
|
||||||
api:
|
|
||||||
image: bitbetter/api
|
|
||||||
pull_policy: never
|
|
||||||
|
|
||||||
identity:
|
|
||||||
image: bitbetter/identity
|
|
||||||
pull_policy: never
|
|
||||||
```
|
|
||||||
|
|
||||||
You'll also want to edit the `/path/to/bwdata/scripts/run.sh` file. In the `function restart()` block, comment out the call to `dockerComposePull`.
|
|
||||||
|
|
||||||
> Replace `dockerComposePull`<br>with `#dockerComposePull`
|
|
||||||
|
|
||||||
You can now start or restart Bitwarden as normal and the modified api will be used. **It is now ready to accept self-issued licenses.**
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Updating Bitwarden and BitBetter
|
## Updating Bitwarden and BitBetter
|
||||||
|
|
||||||
To update Bitwarden, the provided `update-bitwarden.sh` script can be used. It will rebuild the BitBetter images and automatically update Bitwarden afterwards. Docker pull errors can be ignored for api and identity images.
|
To update Bitwarden, the same `build.[sh|ps1]` script can be used. It will rebuild the BitBetter image and automatically update Bitwarden before doing so.
|
||||||
|
|
||||||
By default, the images are built in **fast patch mode**: the official Bitwarden images are pulled from the GitHub Container Registry and the license certificate are directly patched inside them.
|
|
||||||
|
|
||||||
To instead **build from source**, set the `BITBETTER_BUILD_FROM_SOURCE` environment variable to `1` before running the script:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
BITBETTER_BUILD_FROM_SOURCE=1 ./update-bitwarden.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
In source build mode the script clones the Bitwarden server repository at the matching version tag, replaces the embedded license certificate, and compiles the `api` and `identity` images from scratch. This takes considerably longer but gives you full control over the build.
|
|
||||||
|
|
||||||
You can either run this script without providing any parameters in interactive mode (`./update-bitwarden.sh`) or by setting the parameters as follows, to run the script in non-interactive mode:
|
|
||||||
```bash
|
|
||||||
./update-bitwarden.sh param1 param2 param3
|
|
||||||
```
|
|
||||||
`param1`: The path to the directory containing your bwdata directory
|
|
||||||
|
|
||||||
`param2`: If you want the docker-compose file to be overwritten (either `y` or `n`)
|
|
||||||
|
|
||||||
`param3`: If you want the bitbetter images to be rebuild (either `y` or `n`)
|
|
||||||
|
|
||||||
If you are updating from versions <= 1.46.2, you may need to run `update-bitwarden.sh` twice to complete the update process.
|
|
||||||
|
|
||||||
## Generating Signed Licenses
|
## Generating Signed Licenses
|
||||||
|
|
||||||
There is a tool included in the directory `src/licenseGen/` that will generate new individual and organization licenses. These licenses will be accepted by the modified Bitwarden because they will be signed by the certificate you generated in earlier steps.
|
There is a tool included in the directory `licenseGen/` that will generate new individual and organization licenses. These licenses will be accepted by the modified Bitwarden because they will be signed by the certificate you generated in earlier steps.
|
||||||
|
|
||||||
|
|
||||||
First, from the `BitBetter/src/licenseGen` directory, **build the license generator**.<sup>[2](#f2)</sup>
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./build.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
In order to run the tool and generate a license you'll need to get a **user's GUID** in order to generate an **invididual license** or the server's **install ID** to generate an **Organization license**. These can be retrieved most easily through the Bitwarden [Admin Portal](https://help.bitwarden.com/article/admin-portal/).
|
In order to run the tool and generate a license you'll need to get a **user's GUID** in order to generate an **invididual license** or the server's **install ID** to generate an **Organization license**. These can be retrieved most easily through the Bitwarden [Admin Portal](https://help.bitwarden.com/article/admin-portal/).
|
||||||
|
|
||||||
**The user must have a verified email address at the time of license import, otherwise Bitwarden will reject the license key. Nevertheless, the license key can be generated even before the user's email is verified.**
|
**The user must have a verified email address at the time of license import, otherwise Bitwarden will reject the license key. Nevertheless, the license key can be generated even before the user's email is verified.**
|
||||||
|
|
||||||
If you generated your keys in the default `BitBetter/.keys` directory, you can **simply run the license gen in interactive mode** from the `Bitbetter` directory and **follow the prompts to generate your license**.
|
If you ran the build script, you can **simply run the license gen in interactive mode** from the `Bitbetter` directory and **follow the prompts to generate your license**.
|
||||||
|
|
||||||
```bash
|
```
|
||||||
./src/licenseGen/run.sh interactive
|
./licenseGen.[sh|ps1] interactive
|
||||||
```
|
```
|
||||||
|
|
||||||
**The license generator will spit out a JSON-formatted license which can then be used within the Bitwarden web front-end to license your user or org!**
|
**The license generator will spit out a JSON-formatted license which can then be used within the Bitwarden web front-end to license your user or org!**
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Note: Alternative Ways to Generate License
|
## Migrating from mssql to a real database
|
||||||
|
|
||||||
If you wish to run the license gen from a directory aside from the root `BitBetter` one, you'll have to provide the absolute path to your cert.pfx.
|
Prepare a new database and bwdata directory, download and prepare the new settings.env (https://raw.githubusercontent.com/bitwarden/self-host/refs/heads/main/bitwarden-lite/settings.env)
|
||||||
|
|
||||||
```bash
|
Make sure you can get the data from either the backup file or by connecting directly to the mssql database (navicat has a trial).
|
||||||
./src/licenseGen/run.sh /Absolute/Path/To/BitBetter/.keys/cert.pfx interactive
|
|
||||||
|
If required (e.g. you cannot connect to your docker mssql server directly) download Microsoft SQL Server 2022 and SQL Server Management Studio (the latter can be used to import the .bak file)
|
||||||
|
|
||||||
|
After cloning this repo and modifying .servers/serverlist.txt to suit your new environment do the following:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker exec -i bitwarden-mssql /backup-db.sh
|
||||||
|
./bitwarden.sh stop
|
||||||
```
|
```
|
||||||
|
|
||||||
Additional, instead of interactive mode, you can also pass the parameters directly to the command as follows.
|
Run build.sh and ensure your new instance serves a webpage AND has populated the new database with the tables (should be empty now)
|
||||||
|
|
||||||
```bash
|
Proceed to stop the new container for now.
|
||||||
./src/licenseGen/run.sh /Absolute/Path/To/BitBetter/.keys/cert.pfx user "Name" "E-Mail" "User-GUID" ["Storage Space in GB"] ["Custom LicenseKey"]
|
|
||||||
./src/licenseGen/run.sh /Absolute/Path/To/BitBetter/.keys/cert.pfx org "Name" "E-Mail" "Install-ID used to install the server" ["Storage Space in GB"] ["Custom LicenseKey"]
|
Copy from the old to the new bwdata directory (do not copy/overwrite identity.pfx!):
|
||||||
```
|
- bwdata/core/licenses to bwdata-new/licenses
|
||||||
|
- bwdata/core/aspnet-dataprotection to bwdata-new/data-protection
|
||||||
|
- bwdata/core/attachments to bwdata-new/attachments
|
||||||
|
|
||||||
|
Export data only from the old sql server database, if needed import the .bak file to a local mssql instance.
|
||||||
|
|
||||||
|
Only export tables that have rows, makes it much quicker, .json is the easiest with navicat.
|
||||||
|
|
||||||
|
Import the rows to the real database, start the new docker container.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
# FAQ: Questions you might have.
|
# FAQ: Questions you might have.
|
||||||
|
|
||||||
## Why build a license generator for open source software?
|
## Why build a license generator for open source software?
|
||||||
@@ -182,10 +146,29 @@ In the past we have done so but they were not focused on the type of customer th
|
|||||||
|
|
||||||
UPDATE: Bitwarden now offers a cheap license called [Families Organization](https://bitwarden.com/pricing/) that provides premium features and the ability to self-host Bitwarden for six persons.
|
UPDATE: Bitwarden now offers a cheap license called [Families Organization](https://bitwarden.com/pricing/) that provides premium features and the ability to self-host Bitwarden for six persons.
|
||||||
|
|
||||||
|
## 2fa doesn't work
|
||||||
|
|
||||||
|
Unfortunately the new BitWarden container doesn't set the timezone and ignores TZ= from the environment, can be fixed by:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker exec bitwarden ln -s /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
|
||||||
|
```
|
||||||
|
|
||||||
|
## Changes in settings.env
|
||||||
|
|
||||||
|
Require a recreation of the docker container, build.sh will suffice too.
|
||||||
|
|
||||||
|
## Migrating from the old unified branch
|
||||||
|
|
||||||
|
```
|
||||||
|
git branch -m unified lite
|
||||||
|
git fetch origin
|
||||||
|
git branch -u origin/lite lite
|
||||||
|
git remote set-head origin -a
|
||||||
|
```
|
||||||
|
|
||||||
# Footnotes
|
# Footnotes
|
||||||
|
|
||||||
<a name="#f1"><sup>1</sup></a> If you wish to change this you'll need to change the value that `src/licenseGen/Program.cs` uses for its `GenerateUserLicense` and `GenerateOrgLicense` calls. Remember, this is really unnecessary as this certificate does not represent any type of security-related certificate.
|
<a name="#f1"><sup>1</sup></a>This tool builds on top of the `bitbetter/api` container image so make sure you've built that above using the root `./build.sh` script.
|
||||||
|
|
||||||
<a name="#f2"><sup>2</sup></a>This tool builds on top of the `bitbetter/api` container image so make sure you've built that above using the root `./build.sh` script.
|
|
||||||
|
|
||||||
|
<a name="#f2"><sup>2</sup></a> If you wish to change this you'll need to change the value that `licenseGen/Program.cs` uses for its `GenerateUserLicense` and `GenerateOrgLicense` calls. Remember, this is really unnecessary as this certificate does not represent any type of security-related certificate.
|
||||||
|
|||||||
146
build.ps1
Normal file
146
build.ps1
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$PSNativeCommandUseErrorActionPreference = $true
|
||||||
|
|
||||||
|
# detect buildx, ErrorActionPreference will ensure the script stops execution if not found
|
||||||
|
docker buildx version
|
||||||
|
|
||||||
|
# Enable BuildKit for better build experience and to ensure platform args are populated
|
||||||
|
$env:DOCKER_BUILDKIT=1
|
||||||
|
$env:COMPOSE_DOCKER_CLI_BUILD=1
|
||||||
|
|
||||||
|
# define temporary directory
|
||||||
|
$tempdirectory = "$pwd\temp"
|
||||||
|
# define services to patch
|
||||||
|
$components = "Api","Identity"
|
||||||
|
|
||||||
|
# delete old directories / files if applicable
|
||||||
|
if (Test-Path "$tempdirectory" -PathType Container) {
|
||||||
|
Remove-Item "$tempdirectory" -Recurse -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Test-Path -Path "$pwd\src\licenseGen\Core.dll" -PathType Leaf) {
|
||||||
|
Remove-Item "$pwd\src\licenseGen\Core.dll" -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
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.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" -PathType Container)) {
|
||||||
|
.\generateKeys.ps1
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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.cer" -Force
|
||||||
|
|
||||||
|
# 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
|
||||||
|
foreach ($instance in $oldinstances) {
|
||||||
|
docker stop $instance
|
||||||
|
docker rm $instance
|
||||||
|
}
|
||||||
|
|
||||||
|
# update bitwarden itself
|
||||||
|
if ($args[0] -eq 'update') {
|
||||||
|
docker pull ghcr.io/bitwarden/lite:latest
|
||||||
|
} else {
|
||||||
|
$confirmation = Read-Host "Update (or get) bitwarden source container (y/n)"
|
||||||
|
if ($confirmation -eq 'y') {
|
||||||
|
docker pull ghcr.io/bitwarden/lite:latest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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-extract ghcr.io/bitwarden/lite:latest
|
||||||
|
|
||||||
|
# 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) {
|
||||||
|
New-item -itemtype Directory -path "$tempdirectory\$component"
|
||||||
|
docker cp $patchinstance`:/app/$component/$component "$tempdirectory\$component\$component"
|
||||||
|
docker cp $patchinstance`:/etc/supervisor.d/$($component.ToLower()).ini "$tempdirectory\$($component.ToLower()).ini"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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
|
||||||
|
if (Test-Path -Path "$pwd\Dockerfile-bitwarden-patch" -PathType Leaf) {
|
||||||
|
Remove-Item "$pwd\Dockerfile-bitwarden-patch" -Force
|
||||||
|
}
|
||||||
|
$dockerFile = "FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine3.23"
|
||||||
|
$dockerFile = -join($dockerFile, "FROM ghcr.io/bitwarden/lite:latest")
|
||||||
|
$dockerFile = -join($dockerFile, "COPY --from=0 /usr/share/dotnet /usr/share/dotnet")
|
||||||
|
foreach ($component in $components) {
|
||||||
|
$dockerFile = -join($dockerFile, "`n`nCOPY ./temp/$component/ /app/$component/")
|
||||||
|
$dockerFile = -join($dockerFile, "`nCOPY ./temp/$($component.ToLower()).ini /etc/supervisor.d/$($component.ToLower()).ini")
|
||||||
|
$dockerFile = -join($dockerFile, "`nRUN rm -f /app/$component/$component")
|
||||||
|
}
|
||||||
|
[System.IO.File]::WriteAllLines("$pwd\Dockerfile-bitwarden-patch", $dockerFile)
|
||||||
|
docker build . --tag bitwarden-patched --file "$pwd\Dockerfile-bitwarden-patch"
|
||||||
|
Remove-Item "$pwd\Dockerfile-bitwarden-patch" -Force
|
||||||
|
|
||||||
|
# start all user requested instances
|
||||||
|
if (Test-Path -Path "$pwd\.servers\serverlist.txt" -PathType Leaf) {
|
||||||
|
foreach($line in Get-Content "$pwd\.servers\serverlist.txt") {
|
||||||
|
if ((-not ($line.StartsWith("#"))) -and (-not [string]::IsNullOrWhiteSpace($line))) {
|
||||||
|
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
|
||||||
232
build.sh
232
build.sh
@@ -1,107 +1,149 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
DIR=`dirname "$0"`
|
|
||||||
DIR=`exec 2>/dev/null;(cd -- "$DIR") && cd -- "$DIR"|| cd "$DIR"; unset PWD; /usr/bin/pwd || /bin/pwd || pwd`
|
|
||||||
|
|
||||||
# Check prerequisite libraries and executables
|
# detect buildx, set -e will ensure the script stops execution if not found
|
||||||
for cmd in docker curl openssl jq; do
|
docker buildx version
|
||||||
command -v "$cmd" >/dev/null 2>&1 || { echo "Error: '$cmd' is required but not installed." >&2; exit 1; }
|
|
||||||
done
|
|
||||||
if [ "${BITBETTER_BUILD_FROM_SOURCE:-0}" = "1" ]; then
|
|
||||||
command -v git >/dev/null 2>&1 || { echo "Error: 'git' is required for BITBETTER_BUILD_FROM_SOURCE=1 but not installed." >&2; exit 1; }
|
|
||||||
fi
|
|
||||||
BW_VERSION=$(curl -fsSL https://raw.githubusercontent.com/bitwarden/self-host/refs/heads/main/version.json | jq -er '.versions.coreVersion')
|
|
||||||
|
|
||||||
echo "Building BitBetter for BitWarden version $BW_VERSION"
|
|
||||||
|
|
||||||
# Enable BuildKit for better build experience and to ensure platform args are populated
|
# Enable BuildKit for better build experience and to ensure platform args are populated
|
||||||
export DOCKER_BUILDKIT=1
|
export DOCKER_BUILDKIT=1
|
||||||
export COMPOSE_DOCKER_CLI_BUILD=1
|
export COMPOSE_DOCKER_CLI_BUILD=1
|
||||||
|
|
||||||
# Determine host architecture to use as default BUILDPLATFORM / TARGETPLATFORM if not supplied.
|
# define temporary directory
|
||||||
# Allow override via environment variables when invoking the script.
|
TEMPDIRECTORY="$PWD/temp"
|
||||||
HOST_UNAME_ARCH=$(uname -m 2>/dev/null || echo unknown)
|
|
||||||
case "$HOST_UNAME_ARCH" in
|
|
||||||
x86_64|amd64) DEFAULT_ARCH=amd64 ;;
|
|
||||||
aarch64|arm64) DEFAULT_ARCH=arm64 ;;
|
|
||||||
armv7l|armv7) DEFAULT_ARCH=arm/v7 ;;
|
|
||||||
*) DEFAULT_ARCH=amd64 ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
: "${BUILDPLATFORM:=linux/${DEFAULT_ARCH}}"
|
# define services to patch
|
||||||
: "${TARGETPLATFORM:=linux/${DEFAULT_ARCH}}"
|
COMPONENTS=("Api" "Identity")
|
||||||
|
|
||||||
echo "Using BUILDPLATFORM=$BUILDPLATFORM TARGETPLATFORM=$TARGETPLATFORM"
|
# delete old directories / files if applicable
|
||||||
|
if [ -d "$TEMPDIRECTORY" ]; then
|
||||||
# If there aren't any keys, generate them first.
|
rm -rf "$TEMPDIRECTORY"
|
||||||
[ -e "$DIR/.keys/cert.cert" ] || "$DIR/.keys/generate-keys.sh"
|
|
||||||
|
|
||||||
if [ "${BITBETTER_BUILD_FROM_SOURCE:-0}" = "1" ]; then
|
|
||||||
echo "--- Source build mode ---"
|
|
||||||
|
|
||||||
# Prepare Bitwarden server repository
|
|
||||||
rm -rf $DIR/server
|
|
||||||
git clone --branch "v${BW_VERSION}" --depth 1 https://github.com/bitwarden/server.git $DIR/server
|
|
||||||
|
|
||||||
# Replace certificate file and thumbprint
|
|
||||||
old_thumbprint=$(openssl x509 -inform DER -fingerprint -noout -in $DIR/server/src/Core/licensing.cer | cut -d= -f2 | tr -d ':')
|
|
||||||
new_thumbprint=$(openssl x509 -inform DER -fingerprint -noout -in $DIR/.keys/cert.cert | cut -d= -f2 | tr -d ':')
|
|
||||||
sed -i -e "s/$old_thumbprint/$new_thumbprint/g" $DIR/server/src/Core/Billing/Services/Implementations/LicensingService.cs
|
|
||||||
cp $DIR/.keys/cert.cert $DIR/server/src/Core/licensing.cer
|
|
||||||
|
|
||||||
docker build \
|
|
||||||
--no-cache \
|
|
||||||
--platform "$TARGETPLATFORM" \
|
|
||||||
--build-arg BUILDPLATFORM="$BUILDPLATFORM" \
|
|
||||||
--build-arg TARGETPLATFORM="$TARGETPLATFORM" \
|
|
||||||
--label com.bitwarden.product="bitbetter" \
|
|
||||||
-f $DIR/server/src/Api/Dockerfile \
|
|
||||||
-t bitbetter/api \
|
|
||||||
$DIR/server
|
|
||||||
|
|
||||||
docker build \
|
|
||||||
--no-cache \
|
|
||||||
--platform "$TARGETPLATFORM" \
|
|
||||||
--build-arg BUILDPLATFORM="$BUILDPLATFORM" \
|
|
||||||
--build-arg TARGETPLATFORM="$TARGETPLATFORM" \
|
|
||||||
--label com.bitwarden.product="bitbetter" \
|
|
||||||
-f $DIR/server/src/Identity/Dockerfile \
|
|
||||||
-t bitbetter/identity \
|
|
||||||
$DIR/server
|
|
||||||
else
|
|
||||||
echo "--- Fast patch mode ---"
|
|
||||||
|
|
||||||
mkdir -p "$DIR/src/bitBetter/.keys"
|
|
||||||
cp "$DIR/.keys/cert.cert" "$DIR/src/bitBetter/.keys/cert.cert"
|
|
||||||
|
|
||||||
# Build the patcher tool inside the SDK container
|
|
||||||
docker run --rm \
|
|
||||||
-v "$DIR/src/bitBetter:/bitBetter" \
|
|
||||||
-w /bitBetter \
|
|
||||||
mcr.microsoft.com/dotnet/sdk:10.0 sh build.sh
|
|
||||||
|
|
||||||
docker build \
|
|
||||||
--no-cache \
|
|
||||||
--platform "$TARGETPLATFORM" \
|
|
||||||
--label com.bitwarden.product="bitbetter" \
|
|
||||||
--build-arg BITWARDEN_TAG="ghcr.io/bitwarden/api:$BW_VERSION" \
|
|
||||||
-t bitbetter/api \
|
|
||||||
"$DIR/src/bitBetter"
|
|
||||||
|
|
||||||
docker build \
|
|
||||||
--no-cache \
|
|
||||||
--platform "$TARGETPLATFORM" \
|
|
||||||
--label com.bitwarden.product="bitbetter" \
|
|
||||||
--build-arg BITWARDEN_TAG="ghcr.io/bitwarden/identity:$BW_VERSION" \
|
|
||||||
-t bitbetter/identity \
|
|
||||||
"$DIR/src/bitBetter"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
docker tag bitbetter/api bitbetter/api:latest
|
if [ -f "$PWD/src/licenseGen/Core.dll" ]; then
|
||||||
docker tag bitbetter/identity bitbetter/identity:latest
|
rm -f "$PWD/src/licenseGen/Core.dll"
|
||||||
docker tag bitbetter/api bitbetter/api:$BW_VERSION
|
fi
|
||||||
docker tag bitbetter/identity bitbetter/identity:$BW_VERSION
|
|
||||||
|
|
||||||
# Remove old instances of the image after a successful build.
|
if [ -f "$PWD/src/licenseGen/cert.pfx" ]; then
|
||||||
ids=$( docker image ls --format="{{ .ID }} {{ .Tag }}" 'bitbetter/*' | grep -E -v -- "CREATED|latest|${BW_VERSION}" | awk '{ ids = (ids ? ids FS $1 : $1) } END { print ids }' )
|
rm -f "$PWD/src/licenseGen/cert.pfx"
|
||||||
[ -n "$ids" ] && docker rmi $ids || true
|
fi
|
||||||
|
|
||||||
|
if [ -f "$PWD/src/bitBetter/cert.cer" ]; then
|
||||||
|
rm -f "$PWD/src/bitBetter/cert.cer"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$PWD/.keys/cert.cert" ]; then
|
||||||
|
mv "$PWD/.keys/cert.cert" "$PWD/.keys/cert.cer"
|
||||||
|
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.cer" "$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.cer"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
for INSTANCE in ${OLDINSTANCES[@]}; do
|
||||||
|
docker stop $INSTANCE
|
||||||
|
docker rm $INSTANCE
|
||||||
|
done
|
||||||
|
|
||||||
|
# update bitwarden itself
|
||||||
|
if [ "$1" = "update" ]; then
|
||||||
|
docker pull ghcr.io/bitwarden/lite:latest
|
||||||
|
else
|
||||||
|
read -p "Update (or get) bitwarden source container (y/n): "
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
docker pull ghcr.io/bitwarden/lite:latest
|
||||||
|
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/lite:latest)
|
||||||
|
|
||||||
|
# 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/$COMPONENT "$TEMPDIRECTORY/$COMPONENT/$COMPONENT"
|
||||||
|
docker cp $PATCHINSTANCE:/etc/supervisor.d/${COMPONENT,,}.ini "$TEMPDIRECTORY/${COMPONENT,,}.ini"
|
||||||
|
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
|
||||||
|
if [ -f "$PWD/Dockerfile-bitwarden-patch" ]; then
|
||||||
|
rm -f "$PWD/Dockerfile-bitwarden-patch"
|
||||||
|
fi
|
||||||
|
echo "FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine3.23" >> "$PWD/Dockerfile-bitwarden-patch"
|
||||||
|
echo "FROM ghcr.io/bitwarden/lite:latest" >> "$PWD/Dockerfile-bitwarden-patch"
|
||||||
|
echo "COPY --from=0 /usr/share/dotnet /usr/share/dotnet" >> "$PWD/Dockerfile-bitwarden-patch"
|
||||||
|
for COMPONENT in ${COMPONENTS[@]}; do
|
||||||
|
echo "" >> "$PWD/Dockerfile-bitwarden-patch"
|
||||||
|
echo "RUN rm -f /app/$COMPONENT/$COMPONENT" >> "$PWD/Dockerfile-bitwarden-patch"
|
||||||
|
echo "COPY ./temp/${COMPONENT,,}.ini /etc/supervisor.d/${COMPONENT,,}.ini" >> "$PWD/Dockerfile-bitwarden-patch"
|
||||||
|
echo "COPY ./temp/$COMPONENT/ /app/$COMPONENT/" >> "$PWD/Dockerfile-bitwarden-patch"
|
||||||
|
done
|
||||||
|
docker build . --tag bitwarden-patched --file "$PWD/Dockerfile-bitwarden-patch"
|
||||||
|
rm -f "$PWD/Dockerfile-bitwarden-patch"
|
||||||
|
|
||||||
|
# start all user requested instances
|
||||||
|
if [ -f "$PWD/.servers/serverlist.txt" ]; then
|
||||||
|
# convert line endings to unix
|
||||||
|
sed -i 's/\r$//' "$PWD/.servers/serverlist.txt"
|
||||||
|
cat "$PWD/.servers/serverlist.txt" | while read -r LINE; do
|
||||||
|
if [[ $LINE != "#"* && -n $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"
|
||||||
|
|||||||
25
generateKeys.ps1
Normal file
25
generateKeys.ps1
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$PSNativeCommandUseErrorActionPreference = $true
|
||||||
|
|
||||||
|
# get the basic openssl binary path
|
||||||
|
$opensslbinary = "$Env:Programfiles\OpenSSL-Win64\bin\openssl.exe"
|
||||||
|
|
||||||
|
# if openssl is not installed attempt to install it
|
||||||
|
if (!(Get-Command $opensslbinary -errorAction SilentlyContinue))
|
||||||
|
{
|
||||||
|
winget install openssl
|
||||||
|
}
|
||||||
|
|
||||||
|
# if previous keys exist, remove them
|
||||||
|
if (Test-Path "$pwd\.keys")
|
||||||
|
{
|
||||||
|
Remove-Item "$pwd\.keys" -Recurse -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
# create new directory
|
||||||
|
New-item -ItemType Directory -Path "$pwd\.keys"
|
||||||
|
|
||||||
|
# generate actual keys
|
||||||
|
Invoke-Expression "& '$opensslbinary' req -x509 -newkey rsa:4096 -keyout `"$pwd\.keys\key.pem`" -out `"$pwd\.keys\cert.cer`" -days 36500 -subj '/CN=www.mydom.com/O=My Company Name LTD./C=US' -outform DER -passout pass:test"
|
||||||
|
Invoke-Expression "& '$opensslbinary' x509 -inform DER -in `"$pwd\.keys\cert.cer`" -out `"$pwd\.keys\cert.pem`""
|
||||||
|
Invoke-Expression "& '$opensslbinary' pkcs12 -export -out `"$pwd\.keys\cert.pfx`" -inkey `"$pwd\.keys\key.pem`" -in `"$pwd\.keys\cert.pem`" -passin pass:test -passout pass:test -certpbe AES-256-CBC -keypbe AES-256-CBC -macalg SHA256"
|
||||||
20
generateKeys.sh
Executable file
20
generateKeys.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check for openssl
|
||||||
|
command -v openssl >/dev/null 2>&1 || { echo >&2 "openssl required but not found. Aborting."; exit 1; }
|
||||||
|
|
||||||
|
DIR="$PWD/.keys"
|
||||||
|
|
||||||
|
# if previous keys exist, remove them
|
||||||
|
if [ -d "$DIR" ]; then
|
||||||
|
rm -rf "$DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# create new directory
|
||||||
|
mkdir "$DIR"
|
||||||
|
|
||||||
|
# Generate new keys
|
||||||
|
openssl req -x509 -newkey rsa:4096 -keyout "$DIR/key.pem" -out "$DIR/cert.cer" -days 36500 -subj '/CN=www.mydom.com/O=My Company Name LTD./C=US' -outform DER -passout pass:test
|
||||||
|
openssl x509 -inform DER -in "$DIR/cert.cer" -out "$DIR/cert.pem"
|
||||||
|
openssl pkcs12 -export -out "$DIR/cert.pfx" -inkey "$DIR/key.pem" -in "$DIR/cert.pem" -passin pass:test -passout pass:test -certpbe AES-256-CBC -keypbe AES-256-CBC -macalg SHA256
|
||||||
17
licenseGen.ps1
Normal file
17
licenseGen.ps1
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$PSNativeCommandUseErrorActionPreference = $true
|
||||||
|
|
||||||
|
if ($($args.Count) -lt 1) {
|
||||||
|
echo "USAGE: <License Gen action> [License Gen args...]"
|
||||||
|
echo "ACTIONS:"
|
||||||
|
echo " interactive"
|
||||||
|
echo " user"
|
||||||
|
echo " org"
|
||||||
|
Exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($args[0] -eq "interactive") {
|
||||||
|
docker run -it --rm bitbetter/licensegen interactive
|
||||||
|
} else {
|
||||||
|
docker run bitbetter/licensegen $args
|
||||||
|
}
|
||||||
17
licenseGen.sh
Executable file
17
licenseGen.sh
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ $# -lt 1 ]; then
|
||||||
|
echo "USAGE: <License Gen action> [License Gen args...]"
|
||||||
|
echo "ACTIONS:"
|
||||||
|
echo " interactive"
|
||||||
|
echo " user"
|
||||||
|
echo " org"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "interactive" ]; then
|
||||||
|
docker run -it --rm bitbetter/licensegen interactive
|
||||||
|
else
|
||||||
|
docker run --rm bitbetter/licensegen "$@"
|
||||||
|
fi
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
ARG BITWARDEN_TAG
|
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||||
FROM ${BITWARDEN_TAG}
|
WORKDIR /bitBetter
|
||||||
|
|
||||||
COPY bin/Release/net10.0/publish/* /bitBetter/
|
COPY . /bitBetter
|
||||||
COPY ./.keys/cert.cert /newLicensing.cer
|
COPY cert.cer /app/
|
||||||
|
|
||||||
RUN set -e; set -x; \
|
RUN dotnet restore
|
||||||
if [ -f /app/Api ]; then EXEC=Api; else EXEC=Identity; fi && \
|
RUN dotnet publish -c Release -o /app --no-restore
|
||||||
dotnet /bitBetter/bitBetter.dll /newLicensing.cer /app/$EXEC && \
|
|
||||||
rm -f /app/$EXEC && \
|
FROM mcr.microsoft.com/dotnet/sdk:10.0
|
||||||
printf '#!/bin/sh\nexec dotnet /app/%s.dll "$@"\n' "$EXEC" > /app/$EXEC && \
|
WORKDIR /app
|
||||||
chmod +x /app/$EXEC && \
|
COPY --from=build /app .
|
||||||
rm -rf /bitBetter /newLicensing.cer
|
|
||||||
|
ENTRYPOINT ["dotnet", "/app/bitBetter.dll"]
|
||||||
|
|||||||
@@ -2,153 +2,141 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text;
|
||||||
using Mono.Cecil;
|
using dnlib.DotNet;
|
||||||
using Mono.Cecil.Cil;
|
using dnlib.DotNet.Emit;
|
||||||
using Mono.Cecil.Rocks;
|
using dnlib.DotNet.Writer;
|
||||||
|
using dnlib.IO;
|
||||||
using SingleFileExtractor.Core;
|
using SingleFileExtractor.Core;
|
||||||
|
|
||||||
namespace BitwardenSelfLicensor
|
namespace bitBetter;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
{
|
{
|
||||||
class Program
|
private static Int32 Main()
|
||||||
{
|
{
|
||||||
static int Main(string[] args)
|
const String certFile = "/app/cert.cer";
|
||||||
{
|
|
||||||
string cerFile = args.Length >= 1 ? args[0] : "/newLicensing.cer";
|
|
||||||
string inputPath = args.Length >= 2 ? args[1] : "/app/Api";
|
|
||||||
|
|
||||||
string coreDllPath;
|
foreach (String iniFile in Directory.GetFiles("/app/mount/", "*.ini", SearchOption.TopDirectoryOnly))
|
||||||
string extractDir = Path.GetDirectoryName(Path.GetFullPath(inputPath));
|
{
|
||||||
|
Console.WriteLine("Patching: " + iniFile);
|
||||||
|
|
||||||
if (string.Equals(Path.GetExtension(inputPath), ".dll", StringComparison.OrdinalIgnoreCase))
|
String[] lines = File.ReadAllLines(iniFile);
|
||||||
{
|
for (Int32 i = 0; i < lines.Length; i++)
|
||||||
// Input is already a direct Core.dll path — skip bundle extraction
|
{
|
||||||
coreDllPath = inputPath;
|
String line = lines[i];
|
||||||
}
|
if (!line.StartsWith("command=", StringComparison.Ordinal)) continue;
|
||||||
else
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var reader = new ExecutableReader(inputPath);
|
|
||||||
reader.ExtractToDirectory(extractDir);
|
|
||||||
Console.WriteLine($"Extracted bundle to {extractDir}");
|
|
||||||
coreDllPath = Path.Combine(extractDir, "Core.dll");
|
|
||||||
|
|
||||||
// The extracted runtimeconfig.json is in self-contained format (no "framework" key).
|
String appNameAndPath = line[(line.LastIndexOf('=') + 1)..];
|
||||||
// Running "dotnet App.dll" requires framework-dependent format; without it .NET looks
|
lines[i] = "command=/usr/bin/dotnet \"" + appNameAndPath + ".dll\" --runtimeconfig \"" + appNameAndPath + ".runtimeconfig.json\"";
|
||||||
// for libhostpolicy.so in the app dir (which isn't there) and crashes.
|
break;
|
||||||
FixRuntimeConfig(extractDir, Path.GetFileNameWithoutExtension(inputPath));
|
}
|
||||||
}
|
File.WriteAllText(iniFile, String.Join("\n", lines), new UTF8Encoding(false));
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
|
||||||
Console.Error.WriteLine($"ERROR: Failed to extract single-file bundle '{inputPath}': {ex.Message}");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"Patching: {coreDllPath}");
|
foreach (String singleFile in Directory.GetFiles("/app/mount/", "*", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
if (Path.HasExtension(singleFile)) continue;
|
||||||
|
|
||||||
var certBytes = File.ReadAllBytes(cerFile);
|
Console.WriteLine("Extracting: " + singleFile);
|
||||||
var module = ModuleDefinition.ReadModule(new MemoryStream(File.ReadAllBytes(coreDllPath)));
|
|
||||||
|
|
||||||
// Replace embedded certificate resource
|
ExecutableReader reader1 = new(singleFile);
|
||||||
var existingRes = module.Resources
|
String currentDirectory = Path.GetDirectoryName(singleFile);
|
||||||
.OfType<EmbeddedResource>()
|
String newCoreDll = Path.Combine(currentDirectory, "Core.dll");
|
||||||
.FirstOrDefault(r => r.Name == "Bit.Core.licensing.cer");
|
reader1.ExtractToDirectory(currentDirectory);
|
||||||
|
reader1.Dispose();
|
||||||
|
|
||||||
if (existingRes == null)
|
File.Delete(singleFile);
|
||||||
{
|
|
||||||
Console.Error.WriteLine("ERROR: Embedded resource 'Bit.Core.licensing.cer' not found in Core.dll");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"Found resource: {existingRes.Name}");
|
if (!File.Exists(newCoreDll))
|
||||||
module.Resources.Add(new EmbeddedResource("Bit.Core.licensing.cer", existingRes.Attributes, certBytes));
|
{
|
||||||
module.Resources.Remove(existingRes);
|
Console.WriteLine("Could not extract Core.dll for " + singleFile);
|
||||||
|
Environment.Exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
var existingCert = X509CertificateLoader.LoadCertificate(existingRes.GetResourceData());
|
Console.WriteLine("Extracted: " + newCoreDll);
|
||||||
var newCert = X509CertificateLoader.LoadCertificate(certBytes);
|
ModuleDefMD moduleDefMd = ModuleDefMD.Load(newCoreDll);
|
||||||
Console.WriteLine($"Old thumbprint: {existingCert.Thumbprint}");
|
Byte[] cert = File.ReadAllBytes(certFile);
|
||||||
Console.WriteLine($"New thumbprint: {newCert.Thumbprint}");
|
|
||||||
|
|
||||||
// Find LicensingService by class name (namespace-agnostic to handle renames)
|
EmbeddedResource embeddedResourceToRemove = moduleDefMd.Resources.OfType<EmbeddedResource>().First(r => r.Name.Equals("Bit.Core.licensing.cer"));
|
||||||
var type = module.Types.FirstOrDefault(t => t.Name == "LicensingService");
|
EmbeddedResource embeddedResourceToAdd = new("Bit.Core.licensing.cer", cert) { Attributes = embeddedResourceToRemove.Attributes };
|
||||||
if (type == null)
|
moduleDefMd.Resources.Add(embeddedResourceToAdd);
|
||||||
{
|
moduleDefMd.Resources.Remove(embeddedResourceToRemove);
|
||||||
Console.Error.WriteLine("ERROR: LicensingService not found in Core.dll");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Console.WriteLine($"Found: {type.FullName}");
|
|
||||||
|
|
||||||
var ctor = type.Resolve().GetConstructors().First();
|
DataReader reader = embeddedResourceToRemove.CreateReader();
|
||||||
var rewriter = ctor.Body.GetILProcessor();
|
|
||||||
|
|
||||||
// Use Contains() to handle the hidden Unicode LRM character (\u200E) that Bitwarden
|
X509Certificate2 existingCert = X509CertificateLoader.LoadCertificate(reader.ReadRemainingBytes());
|
||||||
// prepends to the production thumbprint string literal in LicensingService.cs
|
X509Certificate2 certificate = X509CertificateLoader.LoadCertificate(cert);
|
||||||
// Replace ALL occurrences since const fields are inlined at compile time and used in
|
Console.WriteLine($"Existing certificate Thumbprint: {existingCert.Thumbprint}");
|
||||||
// multiple validation checks (both _creationCertificate and _verificationCertificates)
|
Console.WriteLine($"New certificate Thumbprint: {certificate.Thumbprint}");
|
||||||
var instructionsToReplace = ctor.Body.Instructions
|
|
||||||
.Where(i => i.OpCode == OpCodes.Ldstr)
|
|
||||||
.Where(i => ((string)i.Operand)
|
|
||||||
.Contains(existingCert.Thumbprint, StringComparison.OrdinalIgnoreCase))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (instructionsToReplace.Count > 0)
|
// Find LicensingService by class name (namespace-agnostic to handle renames)
|
||||||
{
|
TypeDef type = moduleDefMd.Types.FirstOrDefault(t => String.Equals(t.Name, "LicensingService", StringComparison.OrdinalIgnoreCase));
|
||||||
Console.WriteLine($"Found {instructionsToReplace.Count} thumbprint Ldstr instruction(s) to replace");
|
if (type == null)
|
||||||
foreach (var inst in instructionsToReplace)
|
{
|
||||||
{
|
Console.Error.WriteLine("ERROR: LicensingService class not found");
|
||||||
Console.WriteLine($" Replacing: '{inst.Operand}'");
|
return -1;
|
||||||
rewriter.Replace(inst, Instruction.Create(OpCodes.Ldstr, newCert.Thumbprint));
|
}
|
||||||
}
|
Console.WriteLine($"Found: {type.FullName}");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("WARNING: Thumbprint Ldstr not found — cert resource replaced anyway");
|
|
||||||
}
|
|
||||||
|
|
||||||
module.Write(coreDllPath);
|
MethodDef constructor = type.FindConstructors().First();
|
||||||
Console.WriteLine("Done.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Converts a self-contained runtimeconfig.json to framework-dependent so the app can be
|
if (constructor == null)
|
||||||
// launched with "dotnet App.dll" using the system-installed ASP.NET Core runtime.
|
{
|
||||||
static void FixRuntimeConfig(string dir, string appName)
|
Console.Error.WriteLine("ERROR: Cannot find constructor");
|
||||||
{
|
return -1;
|
||||||
var path = Path.Combine(dir, $"{appName}.runtimeconfig.json");
|
}
|
||||||
if (!File.Exists(path))
|
|
||||||
{
|
|
||||||
Console.WriteLine($"runtimeconfig not found at {path}, skipping");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var root = JsonNode.Parse(File.ReadAllText(path))!;
|
Instruction[] instructionToPatch = constructor.Body.Instructions
|
||||||
var opts = root["runtimeOptions"]!.AsObject();
|
.Where(i => i.OpCode == OpCodes.Ldstr)
|
||||||
|
.Where(i => ((String)i.Operand)
|
||||||
|
.Contains(existingCert.Thumbprint, StringComparison.OrdinalIgnoreCase))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
// Derive framework name/version from the self-contained includedFrameworks before removing it
|
if (instructionToPatch.Length > 0)
|
||||||
string fwName = "Microsoft.AspNetCore.App";
|
{
|
||||||
string fwVersion = "10.0.0";
|
Console.WriteLine($"Found {instructionToPatch.Length} thumbprint Ldstr instruction(s) to replace");
|
||||||
if (opts["includedFrameworks"] is JsonArray included && included.Count > 0)
|
foreach (Instruction inst in instructionToPatch)
|
||||||
{
|
{
|
||||||
var first = included[0]!.AsObject();
|
Console.WriteLine($" Replacing: '{inst.Operand}'");
|
||||||
fwName = first["name"]?.GetValue<string>() ?? fwName;
|
inst.Operand = certificate.Thumbprint;
|
||||||
fwVersion = first["version"]?.GetValue<string>() ?? fwVersion;
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("ERROR: Can't find instruction to patch");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove self-contained markers
|
Console.WriteLine("Writing: " + newCoreDll);
|
||||||
opts.Remove("includedFrameworks");
|
|
||||||
|
|
||||||
// Add framework-dependent reference (LatestPatch allows compatibility across patch releases only)
|
ModuleWriterOptions moduleWriterOptions = new(moduleDefMd);
|
||||||
opts["framework"] = new JsonObject
|
moduleWriterOptions.MetadataOptions.Flags |= MetadataFlags.KeepOldMaxStack;
|
||||||
{
|
moduleWriterOptions.MetadataOptions.Flags |= MetadataFlags.PreserveAll;
|
||||||
["name"] = fwName,
|
moduleWriterOptions.MetadataOptions.Flags |= MetadataFlags.PreserveRids;
|
||||||
["version"] = fwVersion
|
|
||||||
};
|
|
||||||
opts["rollForward"] = "LatestPatch";
|
|
||||||
|
|
||||||
File.WriteAllText(path, root.ToJsonString(new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
|
moduleDefMd.Write(newCoreDll + ".new");
|
||||||
Console.WriteLine($"Fixed runtimeconfig: {path}");
|
moduleDefMd.Dispose();
|
||||||
}
|
File.Delete(newCoreDll);
|
||||||
}
|
File.Move(newCoreDll + ".new", newCoreDll);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (String runtimeConfigFile in Directory.GetFiles("/app/mount/", "*.runtimeconfig.json", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Patching: " + runtimeConfigFile);
|
||||||
|
|
||||||
|
String[] lines = File.ReadAllLines(runtimeConfigFile);
|
||||||
|
for (Int32 i = 0; i < lines.Length; i++)
|
||||||
|
{
|
||||||
|
String line = lines[i];
|
||||||
|
if (!line.Contains("includedFrameworks", StringComparison.Ordinal)) continue;
|
||||||
|
|
||||||
|
lines[i] = lines[i].Replace("includedFrameworks", "frameworks", StringComparison.Ordinal);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
File.WriteAllText(runtimeConfigFile, String.Join("\n", lines), new UTF8Encoding(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
|
<PackageReference Include="dnlib" Version="4.5.0" />
|
||||||
<PackageReference Include="SingleFileExtractor.Core" Version="2.3.0" />
|
<PackageReference Include="SingleFileExtractor.Core" Version="2.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
set -x
|
|
||||||
|
|
||||||
dotnet restore
|
|
||||||
dotnet publish -c Release -o bin/Release/net10.0/publish
|
|
||||||
@@ -1,17 +1,15 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||||
|
|
||||||
WORKDIR /licenseGen
|
WORKDIR /licenseGen
|
||||||
|
|
||||||
COPY . /licenseGen
|
COPY . /licenseGen
|
||||||
|
COPY Core.dll /app/
|
||||||
|
COPY cert.pfx /app/
|
||||||
|
|
||||||
RUN set -e; set -x; \
|
RUN dotnet restore
|
||||||
dotnet add package Newtonsoft.Json --version 13.0.1 \
|
RUN dotnet publish -c Release -o /app --no-restore
|
||||||
&& dotnet restore \
|
|
||||||
&& dotnet publish
|
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:10.0
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=build /app .
|
||||||
|
|
||||||
FROM bitbetter/api
|
ENTRYPOINT ["dotnet", "/app/licenseGen.dll", "--cert=/app/cert.pfx", "--core=/app/Core.dll"]
|
||||||
|
|
||||||
COPY --from=build /licenseGen/bin/Release/net10.0/publish/* /app/
|
|
||||||
|
|
||||||
ENTRYPOINT [ "dotnet", "/app/licenseGen.dll", "--core", "/app/Core.dll", "--executable", "/app/Api", "--cert", "/cert.pfx" ]
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
DIR=`dirname "$0"`
|
|
||||||
DIR=`exec 2>/dev/null;(cd -- "$DIR") && cd -- "$DIR"|| cd "$DIR"; unset PWD; /usr/bin/pwd || /bin/pwd || pwd`
|
|
||||||
|
|
||||||
docker build -t bitbetter/licensegen "$DIR" # --squash
|
|
||||||
@@ -1,16 +1,11 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
|
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="5.1.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
|
||||||
<PackageReference Include="SingleFileExtractor.Core" Version="2.3.0" />
|
|
||||||
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.17.0" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.17.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
DIR=`dirname "$0"`
|
|
||||||
DIR=`exec 2>/dev/null;(cd -- "$DIR") && cd -- "$DIR"|| cd "$DIR"; unset PWD; /usr/bin/pwd || /bin/pwd || pwd`
|
|
||||||
|
|
||||||
# Grab the absolute path to the default pfx location
|
|
||||||
cert_path="$DIR/../../.keys/cert.pfx"
|
|
||||||
|
|
||||||
if [ "$#" -lt "2" ]; then
|
|
||||||
echo "USAGE: $0 <ABSOLUTE PATH TO CERT.PFX> <License Gen action> [License Gen args...]"
|
|
||||||
echo "ACTIONS:"
|
|
||||||
echo " interactive"
|
|
||||||
echo " user"
|
|
||||||
echo " org"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cert_path="$1"
|
|
||||||
action="$2"
|
|
||||||
shift
|
|
||||||
|
|
||||||
if [ $action = "interactive" ]; then
|
|
||||||
docker run -it --rm -v "$cert_path:/cert.pfx" bitbetter/licensegen "$@"
|
|
||||||
else
|
|
||||||
docker run --rm -v "$cert_path:/cert.pfx" bitbetter/licensegen "$@"
|
|
||||||
fi
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
ask () {
|
|
||||||
local __resultVar=$1
|
|
||||||
local __result="$2"
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
read -p "$3" __result
|
|
||||||
fi
|
|
||||||
eval $__resultVar="'$__result'"
|
|
||||||
}
|
|
||||||
|
|
||||||
SCRIPT_BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
||||||
|
|
||||||
# Check prerequisite libraries and executables
|
|
||||||
for cmd in docker curl openssl jq; do
|
|
||||||
command -v "$cmd" >/dev/null 2>&1 || { echo "Error: '$cmd' is required but not installed." >&2; exit 1; }
|
|
||||||
done
|
|
||||||
|
|
||||||
BW_VERSION=$(curl -fsSL https://raw.githubusercontent.com/bitwarden/self-host/refs/heads/main/version.json | jq -er '.versions.coreVersion')
|
|
||||||
|
|
||||||
echo "Starting Bitwarden update, newest server version: $BW_VERSION"
|
|
||||||
|
|
||||||
# Default path is the parent directory of the BitBetter location
|
|
||||||
BITWARDEN_BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )"
|
|
||||||
|
|
||||||
# Get Bitwarden base from user (or keep default value) or use first argument
|
|
||||||
ask tmpbase "$1" "Enter Bitwarden base directory [$BITWARDEN_BASE]: "
|
|
||||||
BITWARDEN_BASE=${tmpbase:-$BITWARDEN_BASE}
|
|
||||||
|
|
||||||
# Check if directory exists and is valid
|
|
||||||
[ -d "$BITWARDEN_BASE" ] || { echo "Bitwarden base directory $BITWARDEN_BASE not found!"; exit 1; }
|
|
||||||
[ -f "$BITWARDEN_BASE/bitwarden.sh" ] || { echo "Bitwarden base directory $BITWARDEN_BASE is not valid!"; exit 1; }
|
|
||||||
|
|
||||||
# Check if user wants to recreate the docker-compose override file
|
|
||||||
RECREATE_OV="y"
|
|
||||||
ask tmprecreate "$2" "Rebuild docker-compose override? [Y/n]: "
|
|
||||||
RECREATE_OV=${tmprecreate:-$RECREATE_OV}
|
|
||||||
|
|
||||||
if [[ $RECREATE_OV =~ ^[Yy]$ ]]
|
|
||||||
then
|
|
||||||
{
|
|
||||||
echo "services:"
|
|
||||||
echo " api:"
|
|
||||||
echo " image: bitbetter/api:$BW_VERSION"
|
|
||||||
echo " pull_policy: never"
|
|
||||||
echo ""
|
|
||||||
echo " identity:"
|
|
||||||
echo " image: bitbetter/identity:$BW_VERSION"
|
|
||||||
echo " pull_policy: never"
|
|
||||||
echo ""
|
|
||||||
} > $BITWARDEN_BASE/bwdata/docker/docker-compose.override.yml
|
|
||||||
echo "BitBetter docker-compose override created!"
|
|
||||||
else
|
|
||||||
echo "Make sure to check if the docker override contains the correct image version ($BW_VERSION) in $BITWARDEN_BASE/bwdata/docker/docker-compose.override.yml!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if user wants to rebuild the bitbetter images
|
|
||||||
REBUILD_BB="n"
|
|
||||||
REBUILD_BB_DESCR="[y/N]"
|
|
||||||
if ! docker images bitbetter/api --format="{{ .Tag }}" | grep -F -- "${BW_VERSION}" > /dev/null; then
|
|
||||||
REBUILD_BB="y"
|
|
||||||
REBUILD_BB_DESCR="[Y/n]"
|
|
||||||
fi
|
|
||||||
ask tmprebuild "$3" "Rebuild BitBetter images? $REBUILD_BB_DESCR: "
|
|
||||||
REBUILD_BB=${tmprebuild:-$REBUILD_BB}
|
|
||||||
|
|
||||||
if [[ $REBUILD_BB =~ ^[Yy]$ ]]
|
|
||||||
then
|
|
||||||
$SCRIPT_BASE/build.sh
|
|
||||||
echo "BitBetter images updated to version: $BW_VERSION"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Now start the bitwarden update
|
|
||||||
cd $BITWARDEN_BASE
|
|
||||||
|
|
||||||
./bitwarden.sh updateself
|
|
||||||
|
|
||||||
# Update the bitwarden.sh: automatically patch run.sh to fix docker-compose pull errors for private images
|
|
||||||
sed -i 's/chmod u+x $SCRIPTS_DIR\/run.sh/chmod u+x $SCRIPTS_DIR\/run.sh\n sed -i \x27s\/dccmd pull\/dccmd pull --ignore-pull-failures || true\/g\x27 $SCRIPTS_DIR\/run.sh/g' -i $BITWARDEN_BASE/bitwarden.sh
|
|
||||||
chmod +x $BITWARDEN_BASE/bitwarden.sh
|
|
||||||
echo "Patching bitwarden.sh completed..."
|
|
||||||
|
|
||||||
./bitwarden.sh update
|
|
||||||
|
|
||||||
# Prune Docker images without at least one container associated to them.
|
|
||||||
echo "Pruning Docker images without at least one container associated to them..."
|
|
||||||
docker image prune -a
|
|
||||||
|
|
||||||
cd $SCRIPT_BASE
|
|
||||||
echo "Bitwarden update completed!"
|
|
||||||
Reference in New Issue
Block a user