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 " ------------------------------------ "
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_firewall
update_fritz
update_ap1
+ update_shellyem
#update_xenserver
update_pve
}
update_ap1
shift
;;
+ shellyem )
+ update_shellyem
+ shift
+ ;;
xenserver )
update_xenserver
shift