+# Update Shelly Certificate
+update_shelly_certificate () {
+ local ip="$1"
+ local cert_file="$2"
+ local key_file="$3"
+ local user="$4"
+ local password="$5"
+
+ local cert_json
+ local key_json
+
+ cert_json=$(jq -Rs . < "$cert_file")
+ key_json=$(jq -Rs . < "$key_file")
+
+ echo "[$ip] Upload certificate..."
+ response=$(
+ curl -s \
+ --anyauth \
+ -u "$user:$password" \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"id\":1,
+ \"method\":\"Shelly.PutHTTPServerCert\",
+ \"params\":{\"data\":${cert_json}}
+ }" \
+ "http://${ip}/rpc"
+ ) || return 1
+ if echo "$response" | jq -e '.id == 1 and has("result")' >/dev/null; then
+ echo "[$ip] Certificate uploaded"
+ else
+ echo "[$ip] Certificate upload failed: $response"
+ return 1
+ fi
+
+ echo "[$ip] Upload key..."
+ response=$(
+ curl -s \
+ --anyauth \
+ -u "$user:$password" \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"id\":2,
+ \"method\":\"Shelly.PutHTTPServerKey\",
+ \"params\":{\"data\":${key_json}}
+ }" \
+ "http://${ip}/rpc"
+ ) || return 1
+ if echo "$response" | jq -e '.id == 2 and has("result")' >/dev/null; then
+ echo "[$ip] Key uploaded"
+ else
+ echo "[$ip] Key upload failed: $response"
+ return 1
+ fi
+
+ echo "[$ip] Rebooting..."
+ response=$(
+ curl -s \
+ --anyauth \
+ -u "$user:$password" \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"id\":3,
+ \"method\":\"Shelly.Reboot\"
+ }" \
+ "http://${ip}/rpc"
+ ) || return 1
+ if echo "$response" | jq -e '.id == 3 and has("result")' >/dev/null; then
+ echo "[$ip] Update completed"
+ else
+ echo "[$ip] Reboot failed: $response"
+ return 1
+ fi
+}
+