]> git.giorgioravera.it Git - scripts.git/commitdiff
Added shelly gen 4 (shellyem) certificates master
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Sat, 1 Aug 2026 14:03:38 +0000 (16:03 +0200)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Sat, 1 Aug 2026 14:03:38 +0000 (16:03 +0200)
update_certificate

index 3f251257a8cf862b334b0db7d02c12e1d5dc15a1..f2a02665c276eac6b52c7a72475bc5941b237672 100755 (executable)
@@ -57,6 +57,80 @@ function update_certificate () {
        fi
 }
 
        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 " ------------------------------------ "
 # Update Server
 function update_server() {
        echo " ------------------------------------ "
@@ -193,6 +267,27 @@ function update_ap1 () {
        echo ""
 }
 
        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 " ------------------------------------ "
 # Update Xenserver
 function update_xenserver () {
        echo " ------------------------------------ "
@@ -231,6 +326,7 @@ function update_all ()
        update_firewall
        update_fritz
        update_ap1
        update_firewall
        update_fritz
        update_ap1
+       update_shellyem
        #update_xenserver
        update_pve
 }
        #update_xenserver
        update_pve
 }
@@ -278,6 +374,10 @@ function parse_options ()
                                update_ap1
                                shift
                                ;;
                                update_ap1
                                shift
                                ;;
+                       shellyem )
+                               update_shellyem
+                               shift
+                               ;;
                        xenserver )
                                update_xenserver
                                shift
                        xenserver )
                                update_xenserver
                                shift