2024-01-31 16:31:47 -05:00
|
|
|
#!/usr/bin/env sh
|
2020-03-24 22:57:10 -04:00
|
|
|
|
|
|
|
# Use the value of the corresponding env var (if present),
|
|
|
|
# or a default value otherwise.
|
2024-01-31 16:31:47 -05:00
|
|
|
: "${DATA_FOLDER:="/data"}"
|
2022-07-31 09:45:31 -04:00
|
|
|
: "${ROCKET_PORT:="80"}"
|
2024-01-31 16:31:47 -05:00
|
|
|
: "${ENV_FILE:="/.env"}"
|
2020-03-24 22:57:10 -04:00
|
|
|
|
|
|
|
CONFIG_FILE="${DATA_FOLDER}"/config.json
|
|
|
|
|
2024-01-31 16:31:47 -05:00
|
|
|
# Check if the $ENV_FILE file exist and is readable
|
Several small fixes for open issues (#4143)
* Fix BWDC when re-run with cleared cache
Using the BWDC with a cleared cache caused invited users to be converted
to accepted users.
The problem was a wrong check for the `restore` function.
Fixes #4114
* Remove useless variable
During some refactoring this seems to be overlooked.
This variable gets filled but isn't used at all afterwards.
Fixes #4105
* Check some `.git` paths to force a rebuild
When a checked-out repo switches to a specific tag, and that tag does
not have anything else changed in the files except the tag, it could
happen that the build process doesn't see any changes, while it could be
that the version string needs to be different.
This commit ensures that if some specific paths are changed within the
.git directory, cargo will be triggered to rebuild.
Fixes #4087
* Do not delete dir on file delete
Previously during a `delete_file` check we also tried to delete the
parent directory and ignored all errors, like not being empty for
example.
Since this function is called `delete_file` and does not mention
anything in regards to a directory i have removed that code and it will
now only delete the file and leave the rest as-is.
If this somehow is still needed or wanted, which i do not think we want,
then we should create a new function.
Fixes #4081
* Fix healthcheck when using an ENV file
If someone is using a `.env` file or configured the `ENV_FILE` variable
to use that as it's configuration, this was missed by the healthcheck.
So, `DOMAIN` and `ROCKET_TLS` were not seen, and not used in these cases.
This commit fixes this by checking for this file and if it exists, then
it will load those variables first.
Fixes #4112
* Add missing route
While there was a function and a derive, this endpoint wasn't part of
the routes. Since Bitwarden does have this endpoint ill add the route
instead of deleting it.
Fixes #4076
Fixes #4144
* Update crates to update the openssl crate
Because of a bug in the openssl-sys crate we pinned the version to an
older version. This issue has been fixed and was released 2 days ago.
This commit updates the openssl crates including others.
This should also fix the issues with building Vaultwarden using newer
versions of LibreSSL.
Fixes #4051
2023-12-08 19:21:14 -05:00
|
|
|
# If that is the case, load it into the environment before running any check
|
|
|
|
if [ -r "${ENV_FILE}" ]; then
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
. "${ENV_FILE}"
|
|
|
|
fi
|
|
|
|
|
2020-03-24 22:57:10 -04:00
|
|
|
# Given a config key, return the corresponding config value from the
|
|
|
|
# config file. If the key doesn't exist, return an empty string.
|
|
|
|
get_config_val() {
|
2023-10-22 18:18:38 -04:00
|
|
|
key="$1"
|
2020-03-24 22:57:10 -04:00
|
|
|
# Extract a line of the form:
|
|
|
|
# "domain": "https://bw.example.com/path",
|
|
|
|
grep "\"${key}\":" "${CONFIG_FILE}" |
|
|
|
|
# To extract just the value (https://bw.example.com/path), delete:
|
|
|
|
# (1) everything up to and including the first ':',
|
|
|
|
# (2) whitespace and '"' from the front,
|
|
|
|
# (3) ',' and '"' from the back.
|
|
|
|
sed -e 's/[^:]\+://' -e 's/^[ "]\+//' -e 's/[,"]\+$//'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Extract the base path from a domain URL. For example:
|
|
|
|
# - `` -> ``
|
|
|
|
# - `https://bw.example.com` -> ``
|
|
|
|
# - `https://bw.example.com/` -> ``
|
|
|
|
# - `https://bw.example.com/path` -> `/path`
|
|
|
|
# - `https://bw.example.com/multi/path` -> `/multi/path`
|
|
|
|
get_base_path() {
|
|
|
|
echo "$1" |
|
|
|
|
# Delete:
|
|
|
|
# (1) everything up to and including '://',
|
|
|
|
# (2) everything up to '/',
|
|
|
|
# (3) trailing '/' from the back.
|
|
|
|
sed -e 's|.*://||' -e 's|[^/]\+||' -e 's|/*$||'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Read domain URL from config.json, if present.
|
|
|
|
if [ -r "${CONFIG_FILE}" ]; then
|
|
|
|
domain="$(get_config_val 'domain')"
|
|
|
|
if [ -n "${domain}" ]; then
|
|
|
|
# config.json 'domain' overrides the DOMAIN env var.
|
|
|
|
DOMAIN="${domain}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-10-20 04:04:09 -04:00
|
|
|
addr="${ROCKET_ADDRESS}"
|
|
|
|
if [ -z "${addr}" ] || [ "${addr}" = '0.0.0.0' ] || [ "${addr}" = '::' ]; then
|
|
|
|
addr='localhost'
|
|
|
|
fi
|
2020-03-24 22:57:10 -04:00
|
|
|
base_path="$(get_base_path "${DOMAIN}")"
|
|
|
|
if [ -n "${ROCKET_TLS}" ]; then
|
|
|
|
s='s'
|
|
|
|
fi
|
2020-03-25 23:13:36 -04:00
|
|
|
curl --insecure --fail --silent --show-error \
|
2022-10-20 04:04:09 -04:00
|
|
|
"http${s}://${addr}:${ROCKET_PORT}${base_path}/alive" || exit 1
|