From: Giorgio Ravera Date: Sat, 1 Aug 2026 14:03:38 +0000 (+0200) Subject: Added shelly gen 4 (shellyem) certificates X-Git-Url: http://git.giorgioravera.it/?a=commitdiff_plain;p=scripts.git Added shelly gen 4 (shellyem) certificates --- diff --git a/update_certificate b/update_certificate index 3f25125..f2a0266 100755 --- a/update_certificate +++ b/update_certificate @@ -57,6 +57,80 @@ function update_certificate () { fi } +# 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 +} + # Update Server function update_server() { echo " ------------------------------------ " @@ -193,6 +267,27 @@ function update_ap1 () { echo "" } +# Update Shelly EM Gen 4 +function update_shellyem () { + echo " ------------------------------------ " + echo "| Updating Shelly EM Certificate |" + echo " ------------------------------------ " + HOST="shellyem.giorgioravera.it" + USER="admin" + ALIVE=$(ping -c 1 $HOST |grep ttl) + if [ ! -z "$ALIVE" ]; then + if [ -f "$SECRET_FILE" ]; then + password=$(awk -F':' -v host="$HOST" '$1 == host {print $2}' "$SECRET_FILE") + update_shelly_certificate $HOST $SRC_FULLCHAIN $SRC_KEY $USER $password + else + echo "$SECRET_FILE not found" + fi + else + echo "Host $HOST not alive, skipped" + fi + echo "" +} + # Update Xenserver function update_xenserver () { echo " ------------------------------------ " @@ -231,6 +326,7 @@ function update_all () update_firewall update_fritz update_ap1 + update_shellyem #update_xenserver update_pve } @@ -278,6 +374,10 @@ function parse_options () update_ap1 shift ;; + shellyem ) + update_shellyem + shift + ;; xenserver ) update_xenserver shift