fix: change script
This commit is contained in:
@@ -11,48 +11,48 @@
|
||||
};
|
||||
|
||||
### 3) Write the check‐script into /etc/external-ip/check.sh (0400, executable)
|
||||
environment.etc."updns-client/run.sh".text = lib.mkIf config.cloonar-assistant.updns-client.enable lib.concatStringsSep "\n" [
|
||||
"#!/usr/bin/env bash"
|
||||
"set -euo pipefail"
|
||||
""
|
||||
"# Where our secret lives (encrypted)"
|
||||
"SECRET=${config.cloonar-assistant.updns-client.secretFile}"
|
||||
"# Where we record the last‐seen IP"
|
||||
"LAST_IP_FILE=/var/lib/updns-client/last-ip"
|
||||
""
|
||||
"# Decrypt the API key at runtime"
|
||||
"API_KEY=$(cat \"$SECRET\")"
|
||||
""
|
||||
"# Fetch current external IP"
|
||||
"IP=$(curl -fsSL https://ifconfig.me)"
|
||||
""
|
||||
"# Ensure state directory exists"
|
||||
"mkdir -p \"$(dirname \"$LAST_IP_FILE\")\""
|
||||
""
|
||||
"# Read old IP (if any)"
|
||||
"if [[ -f \"$LAST_IP_FILE\" ]]; then"
|
||||
" OLD_IP=$(< \"$LAST_IP_FILE\")"
|
||||
"else"
|
||||
" OLD_IP=\"\""
|
||||
"fi"
|
||||
""
|
||||
"# If it's changed, notify the API and update the file"
|
||||
"if [[ \"$IP\" != \"$OLD_IP\" ]]; then"
|
||||
""
|
||||
" PAYLOAD=$(jq -n \\"
|
||||
" --arg key \"${config.cloonar-assistant.updns-client.key}\" \\"
|
||||
" --arg secret \"$SECRET\" \\"
|
||||
" --arg host \"${config.cloonar-assistant.domain}\" \\"
|
||||
" --arg ip \"$IP\" \\"
|
||||
" '{key: $key, secret: $secret, host: $host, ip: $ip}')"
|
||||
""
|
||||
" curl -fsS -X POST https://updns-client.cloonar.com/update \\"
|
||||
" -H \"Content-Type: application/json\" \\"
|
||||
" -d \"$PAYLOAD\""
|
||||
""
|
||||
" echo \"$IP\" > \"$LAST_IP_FILE\""
|
||||
"fi"
|
||||
];
|
||||
environment.etc."updns-client/run.sh".text = lib.mkIf config.cloonar-assistant.updns-client.enable ''
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Where our secret lives (encrypted)
|
||||
SECRET=${config.cloonar-assistant.updns-client.secretFile}
|
||||
# Where we record the last‐seen IP
|
||||
LAST_IP_FILE=/var/lib/updns-client/last-ip
|
||||
|
||||
# Decrypt the API key at runtime
|
||||
API_KEY=$(cat "$SECRET")
|
||||
|
||||
# Fetch current external IP
|
||||
IP=$(curl -fsSL https://ifconfig.me)
|
||||
|
||||
# Ensure state directory exists
|
||||
mkdir -p "$(dirname \"$LAST_IP_FILE\")"
|
||||
|
||||
# Read old IP (if any)
|
||||
if [[ -f "$LAST_IP_FILE" ]]; then
|
||||
OLD_IP=$(< "$LAST_IP_FILE")
|
||||
else
|
||||
OLD_IP=""
|
||||
fi
|
||||
|
||||
# If it's changed, notify the API and update the file
|
||||
if [[ "$IP" != "$OLD_IP" ]]; then
|
||||
|
||||
PAYLOAD=$(jq -n \
|
||||
--arg key \"${config.cloonar-assistant.updns-client.key}" \
|
||||
--arg secret "$SECRET" \
|
||||
--arg host "${config.cloonar-assistant.domain}" \
|
||||
--arg ip "$IP" \
|
||||
'{key: $key, secret: $secret, host: $host, ip: $ip}')
|
||||
|
||||
curl -fsS -X POST https://updns-client.cloonar.com/update \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$PAYLOAD"
|
||||
|
||||
echo "$IP" > "$LAST_IP_FILE"
|
||||
fi
|
||||
'';
|
||||
environment.etc."updns-client/run.sh".mode = "0500";
|
||||
|
||||
### 4) Ensure /var/lib/external-ip exists on boot
|
||||
|
||||
Reference in New Issue
Block a user