|
@@ -1,14 +1,6 @@
|
|
#!/usr/bin/env bash
|
|
#!/usr/bin/env bash
|
|
set -e # Exit immediately if a command exits with a non-zero status.
|
|
set -e # Exit immediately if a command exits with a non-zero status.
|
|
|
|
|
|
-# Get field from json file
|
|
|
|
-function get_json_field() {
|
|
|
|
- local json_file="$1"
|
|
|
|
- local field="$2"
|
|
|
|
-
|
|
|
|
- echo $(jq -r ".${field}" "${json_file}")
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
# use greadlink instead of readlink on osx
|
|
# use greadlink instead of readlink on osx
|
|
if [[ "$(uname)" == "Darwin" ]]; then
|
|
if [[ "$(uname)" == "Darwin" ]]; then
|
|
readlink=greadlink
|
|
readlink=greadlink
|
|
@@ -21,6 +13,31 @@ STATE_FOLDER="${ROOT_FOLDER}/state"
|
|
INTERNAL_IP="$(hostname -I | awk '{print $1}')"
|
|
INTERNAL_IP="$(hostname -I | awk '{print $1}')"
|
|
DNS_IP=9.9.9.9
|
|
DNS_IP=9.9.9.9
|
|
|
|
|
|
|
|
+# Get field from json file
|
|
|
|
+function get_json_field() {
|
|
|
|
+ local json_file="$1"
|
|
|
|
+ local field="$2"
|
|
|
|
+
|
|
|
|
+ echo $(jq -r ".${field}" "${json_file}")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+# Deterministically derives 128 bits of cryptographically secure entropy
|
|
|
|
+function derive_entropy() {
|
|
|
|
+ SEED_FILE="${STATE_FOLDER}/seed"
|
|
|
|
+ identifier="${1}"
|
|
|
|
+ tipi_seed=$(cat "${SEED_FILE}") || true
|
|
|
|
+
|
|
|
|
+ if [[ -z "$tipi_seed" ]] || [[ -z "$identifier" ]]; then
|
|
|
|
+ >&2 echo "Missing derivation parameter, this is unsafe, exiting."
|
|
|
|
+ exit 1
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ # We need `sed 's/^.* //'` to trim the "(stdin)= " prefix from some versions of openssl
|
|
|
|
+ printf "%s" "${identifier}" | openssl dgst -sha256 -hmac "${tipi_seed}" | sed 's/^.* //'
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
# Get dns ip if pihole is installed
|
|
# Get dns ip if pihole is installed
|
|
str=$(get_json_field ${STATE_FOLDER}/apps.json installed)
|
|
str=$(get_json_field ${STATE_FOLDER}/apps.json installed)
|
|
|
|
|
|
@@ -61,25 +78,36 @@ export COMPOSE_HTTP_TIMEOUT=240
|
|
echo "Generating config files..."
|
|
echo "Generating config files..."
|
|
# Remove current .env file
|
|
# Remove current .env file
|
|
[[ -f "${ROOT_FOLDER}/.env" ]] && rm -f "${ROOT_FOLDER}/.env"
|
|
[[ -f "${ROOT_FOLDER}/.env" ]] && rm -f "${ROOT_FOLDER}/.env"
|
|
|
|
+[[ -f "${ROOT_FOLDER}/system-api/.env" ]] && rm -f "${ROOT_FOLDER}/system-api/.env"
|
|
|
|
|
|
# Store paths to intermediary config files
|
|
# Store paths to intermediary config files
|
|
ENV_FILE="$ROOT_FOLDER/templates/.env"
|
|
ENV_FILE="$ROOT_FOLDER/templates/.env"
|
|
|
|
+ENV_FILE_SYSTEM_API="$ROOT_FOLDER/templates/.env-api"
|
|
|
|
|
|
# Remove intermediary config files
|
|
# Remove intermediary config files
|
|
[[ -f "$ENV_FILE" ]] && rm -f "$ENV_FILE"
|
|
[[ -f "$ENV_FILE" ]] && rm -f "$ENV_FILE"
|
|
|
|
+[[ -f "$ENV_FILE_SYSTEM_API" ]] && rm -f "$ENV_FILE_SYSTEM_API"
|
|
|
|
|
|
# Copy template configs to intermediary configs
|
|
# Copy template configs to intermediary configs
|
|
[[ -f "$ROOT_FOLDER/templates/env-sample" ]] && cp "$ROOT_FOLDER/templates/env-sample" "$ENV_FILE"
|
|
[[ -f "$ROOT_FOLDER/templates/env-sample" ]] && cp "$ROOT_FOLDER/templates/env-sample" "$ENV_FILE"
|
|
|
|
+[[ -f "$ROOT_FOLDER/templates/env-api-sample" ]] && cp "$ROOT_FOLDER/templates/env-api-sample" "$ENV_FILE_SYSTEM_API"
|
|
|
|
+
|
|
|
|
+JWT_SECRET=$(derive_entropy "jwt")
|
|
|
|
+
|
|
|
|
+echo $JWT_SECRET
|
|
|
|
|
|
-for template in "${ENV_FILE}"; do
|
|
|
|
|
|
+for template in "${ENV_FILE}" "${ENV_FILE_SYSTEM_API}"; do
|
|
sed -i "s/<dns_ip>/${DNS_IP}/g" "${template}"
|
|
sed -i "s/<dns_ip>/${DNS_IP}/g" "${template}"
|
|
sed -i "s/<internal_ip>/${INTERNAL_IP}/g" "${template}"
|
|
sed -i "s/<internal_ip>/${INTERNAL_IP}/g" "${template}"
|
|
sed -i "s/<puid>/${PUID}/g" "${template}"
|
|
sed -i "s/<puid>/${PUID}/g" "${template}"
|
|
sed -i "s/<pgid>/${PGID}/g" "${template}"
|
|
sed -i "s/<pgid>/${PGID}/g" "${template}"
|
|
sed -i "s/<tz>/${TZ}/g" "${template}"
|
|
sed -i "s/<tz>/${TZ}/g" "${template}"
|
|
|
|
+ sed -i "s/<root_folder>/${ROOT_FOLDER}/g" "${template}"
|
|
|
|
+ sed -i "s/<jwt_secret>/${JWT_SECRET}/g" "${template}"
|
|
done
|
|
done
|
|
|
|
|
|
mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"
|
|
mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"
|
|
|
|
+mv -f "$ENV_FILE_SYSTEM_API" "$ROOT_FOLDER/system-api/.env"
|
|
|
|
|
|
ansible-playbook ansible/start.yml -i ansible/hosts -K
|
|
ansible-playbook ansible/start.yml -i ansible/hosts -K
|
|
|
|
|