From 0592179e758ee66311c1fe7e7c994c7d5066b50e Mon Sep 17 00:00:00 2001 From: Yinyin Liu Date: Mon, 24 Feb 2025 12:11:31 +0100 Subject: [PATCH] create script to update files in all Venus and Cerbo --- firmware/update_all_installations.sh | 92 ++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 firmware/update_all_installations.sh diff --git a/firmware/update_all_installations.sh b/firmware/update_all_installations.sh new file mode 100755 index 000000000..8de55743c --- /dev/null +++ b/firmware/update_all_installations.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# Handle Ctrl+C to ensure a clean exit +trap "echo -e '\nScript interrupted by user. Exiting...'; kill 0; exit 1" SIGINT + +username='root' +root_password='salidomo' + +set -e + +venus_release_file_path="./Venus_Release/VenusReleaseFiles" +cerbo_release_file_path="./Cerbo_Release/CerboReleaseFiles" + +venus_ip_addresses=("10.2.0.191" "10.2.1.36" "10.2.1.108") +cerbo_ip_addresses=("10.2.2.212" "10.2.4.181" "10.2.3.198") + +deploy() { + local device_type=$1 + local ip_list=("${!2}") + local release_file_path=$3 + + echo -e "\n============================ Deploying to $device_type ============================\n" + + for ip_address in "${ip_list[@]}"; do + echo "Processing $ip_address for $device_type..." + + # Check if SSH is reachable within 60 seconds + if ! timeout 60 ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no "$username@$ip_address" "echo 'SSH connection successful'" &>/dev/null; then + echo "Skipping $ip_address: SSH connection failed or timed out." + continue + fi + + echo "SSH connection successful: $ip_address" + + # Stop battery service if changing battery-related files + if ssh -o StrictHostKeyChecking=no "$username@$ip_address" "svc -d /service/dbus-fzsonick-48tl.*"; then + echo "Stopped battery service on $ip_address" + else + echo "Warning: Failed to stop battery service on $ip_address" + fi + + # Copy files + if scp -o ConnectTimeout=10 "$release_file_path/dbus-fzsonick-48tl/dbus-fzsonick-48tl.py" "root@$ip_address:/opt/victronenergy/dbus-fzsonick-48tl"; then + echo "Copied file to /opt on $ip_address" + else + echo "Warning: Failed to copy file to /opt on $ip_address" + fi + + if scp -o ConnectTimeout=10 "$release_file_path/dbus-fzsonick-48tl/dbus-fzsonick-48tl.py" "root@$ip_address:/data/dbus-fzsonick-48tl"; then + echo "Copied file to /data on $ip_address" + else + echo "Warning: Failed to copy file to /data on $ip_address" + fi + + # Start battery service + if ssh -o StrictHostKeyChecking=no "$username@$ip_address" "svc -u /service/dbus-fzsonick-48tl.*"; then + echo "Started battery service on $ip_address" + else + echo "Warning: Failed to start battery service on $ip_address" + fi + + echo "Deployment completed for $ip_address ($device_type)" + done + + echo -e "\n============================ Finished deploying to $device_type ============================\n" +} + +# Prompt user for deployment type +echo "Select deployment type:" +echo "1) Deploy to Venus devices" +echo "2) Deploy to Cerbo devices" +echo "3) Deploy to both Venus and Cerbo devices" +read -p "Enter your choice (1/2/3): " choice + +case $choice in + 1) + deploy "Venus" venus_ip_addresses[@] "$venus_release_file_path" + ;; + 2) + deploy "Cerbo" cerbo_ip_addresses[@] "$cerbo_release_file_path" + ;; + 3) + deploy "Venus" venus_ip_addresses[@] "$venus_release_file_path" + deploy "Cerbo" cerbo_ip_addresses[@] "$cerbo_release_file_path" + ;; + *) + echo "Invalid choice. Exiting..." + exit 1 + ;; +esac + +echo -e "\n============================ All Deployments Completed ============================\n"