Skip to content

Commit 4cf8e59

Browse files
committed
Fix #1: always update certUrl from add-on options on restart, add jq for config management
1 parent 98db370 commit 4cf8e59

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

meshcentral/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ARG BUILD_FROM=ghcr.io/home-assistant/amd64-base:latest
22
FROM $BUILD_FROM
33

4-
# Install Node.js (required for MeshCentral)
5-
RUN apk add --no-cache nodejs npm
4+
# Install Node.js and jq (required for MeshCentral and config management)
5+
RUN apk add --no-cache nodejs npm jq
66

77
# Install MeshCentral
88
RUN npm install -g meshcentral

meshcentral/run.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ fi
1414
bashio::log.info "Starting MeshCentral..."
1515
bashio::log.info "Hostname: ${HOSTNAME}"
1616
bashio::log.info "Data path: ${DATA_PATH}"
17+
bashio::log.info "Cert URL: ${CERT_URL:-not set}"
1718

1819
# Create data directory
1920
mkdir -p "${DATA_PATH}"
2021

21-
# Generate config.json if it doesn't exist
2222
CONFIG_FILE="${DATA_PATH}/config.json"
23+
24+
# Generate config.json if it doesn't exist
2325
if [ ! -f "$CONFIG_FILE" ]; then
2426
bashio::log.info "Creating initial MeshCentral config..."
2527
cat > "$CONFIG_FILE" << EOF
@@ -43,7 +45,24 @@ if [ ! -f "$CONFIG_FILE" ]; then
4345
}
4446
}
4547
EOF
46-
bashio::log.info "Config created. NOTE: Set 'newAccounts: true' temporarily to create your first admin account!"
48+
bashio::log.info "Config created."
49+
bashio::log.info "NOTE: Set 'newAccounts: true' temporarily to create your first admin account!"
50+
fi
51+
52+
# Always update certUrl from add-on options (even if config already existed)
53+
# This ensures changes to cert_url in HA options take effect on restart
54+
if command -v jq &> /dev/null; then
55+
if [ -n "$CERT_URL" ]; then
56+
bashio::log.info "Updating certUrl in config.json..."
57+
jq --arg url "$CERT_URL" '.domains[""].certUrl = $url' "$CONFIG_FILE" > /tmp/mc_config_tmp.json \
58+
&& mv /tmp/mc_config_tmp.json "$CONFIG_FILE"
59+
else
60+
bashio::log.info "No cert_url set — removing certUrl from config.json if present..."
61+
jq 'del(.domains[""].certUrl)' "$CONFIG_FILE" > /tmp/mc_config_tmp.json \
62+
&& mv /tmp/mc_config_tmp.json "$CONFIG_FILE"
63+
fi
64+
else
65+
bashio::log.warning "jq not found — certUrl will only be set on first run. Install jq for dynamic updates."
4766
fi
4867

4968
# Start MeshCentral

0 commit comments

Comments
 (0)