#!/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.4.155" "10.2.3.178" "10.2.3.164" "10.2.4.114" "10.2.3.133" "10.2.2.72" "10.2.2.11" "10.2.2.128" "10.2.2.100" "10.2.2.243") # #venus_ip_addresses=( # "10.2.1.35" "10.2.0.104" "10.2.1.159" "10.2.0.224" "10.2.0.155" "10.2.0.209" "10.2.0.227" "10.2.0.211" # "10.2.1.134" "10.2.0.130" "10.2.1.169" "10.2.0.105" "10.2.0.220" "10.2.1.124" "10.2.1.2" "10.2.1.158" # "10.2.0.195" "10.2.1.171" "10.2.0.225" "10.2.1.53" "10.2.0.107" "10.2.0.153" "10.2.1.106" "10.2.1.117" # "10.2.0.145" "10.2.0.110" "10.2.1.177" "10.2.1.247" "10.2.0.101" "10.2.0.108" "10.2.1.120" "10.2.1.160" # "10.2.0.98" "10.2.0.94" "10.2.1.173" "10.2.0.113" "10.2.0.150" "10.2.0.233" "10.2.1.162" "10.2.1.138" # "10.2.1.165" "10.2.1.163" "10.2.1.32" "10.2.1.110" "10.2.0.103" "10.2.1.113" "10.2.0.216" "10.2.0.184" # "10.2.0.191" "10.2.1.60" "10.2.1.219" "10.2.0.214" "10.2.1.83" "10.2.1.39" "10.2.0.194" "10.2.1.81" # "10.2.1.125" "10.2.0.154" "10.2.0.196" "10.2.0.99" "10.2.1.130" "10.2.1.33" "10.2.0.249" "10.2.0.133" # "10.2.1.118" "10.2.0.138" "10.2.0.144" "10.2.0.141" "10.2.0.188" "10.2.1.74" "10.2.1.141" "10.2.1.142" # "10.2.0.193" "10.2.1.145" "10.2.1.15" "10.2.1.70" "10.2.0.135" "10.2.0.247" "10.2.0.134" "10.2.1.21" # "10.2.0.131" "10.2.1.1" "10.2.1.73" "10.2.0.243" "10.2.1.19" "10.2.1.166" "10.2.0.192" "10.2.1.12" # "10.2.2.188" "10.2.0.158" "10.2.1.146" "10.2.1.27" "10.2.0.202" "10.2.0.157" "10.2.1.55" "10.2.1.16" # "10.2.1.28" "10.2.4.242" "10.2.0.254" "10.2.1.128" "10.2.1.58" "10.2.1.156" "10.2.1.137" "10.2.1.135" # "10.2.1.24" "10.2.0.128" "10.2.1.90" "10.2.1.153" "10.2.1.93" "10.2.1.111" "10.2.1.71" "10.2.1.37" # "10.2.0.127" "10.2.0.126" "10.2.1.22" "10.2.1.91" "10.2.1.123" "10.2.1.220" "10.2.1.114" "10.2.1.41" # "10.2.0.125" "10.2.1.62" "10.2.0.161" "10.2.1.121" "10.2.1.10" "10.2.0.112" "10.2.0.111" "10.2.0.218" # "10.2.1.49" "10.2.0.230" "10.2.1.170" "10.2.0.114" "10.2.0.140" "10.2.4.241" "10.2.1.107" "10.2.0.185" # "10.2.0.124" "10.2.1.85" "10.2.0.123" "10.2.1.23" "10.2.1.44" "10.2.1.172" "10.2.1.129" "10.2.1.14" # "10.2.1.59" "10.2.1.56" "10.2.1.149" "10.2.1.140" "10.2.1.116" "10.2.1.57" "10.2.1.26" "10.2.0.210" # "10.2.0.237" "10.2.1.47" "10.2.1.127" "10.2.0.199" "10.2.0.252" "10.2.1.119" "10.2.0.122" "10.2.0.251" # "10.2.1.7" "10.2.1.45" "10.2.1.157" "10.2.1.139" "10.2.0.119" "10.2.0.250" "10.2.1.148" "10.2.1.92" # "10.2.0.245" "10.2.0.246" "10.2.1.80" "10.2.0.204" "10.2.0.203" "10.2.0.205" "10.2.1.78" "10.2.4.210" # "10.2.0.222" "10.2.1.36" "10.2.1.3" "10.2.0.244" "10.2.1.176" "10.2.0.242" "10.2.1.30" "10.2.1.61" # "10.2.1.168" "10.2.0.215" "10.2.1.76" "10.2.1.43" "10.2.0.200" "10.2.0.115" "10.2.1.115" "10.2.0.238" # "10.2.0.189" "10.2.0.160" "10.2.0.149" "10.2.1.161" "10.2.1.101" "10.2.1.40" "10.2.0.229" "10.2.1.52" # "10.2.0.239" "10.2.0.132" "10.2.0.162" "10.2.1.25" "10.2.0.118" "10.2.1.151" "10.2.0.190" "10.2.1.108" # "10.2.0.219" "10.2.1.100" "10.2.1.109" #) #cerbo_ip_addresses=("10.2.1.150") # cerbo_ip_addresses=( 10.2.5.5 10.2.4.98 10.2.4.97 10.2.4.96 10.2.4.95 10.2.4.94 10.2.4.92 10.2.4.91 10.2.4.90 10.2.4.9 10.2.4.88 10.2.4.87 10.2.4.84 10.2.4.83 10.2.4.82 10.2.4.81 10.2.4.80 10.2.4.78 10.2.4.77 10.2.4.75 10.2.4.73 10.2.4.71 10.2.4.70 10.2.4.69 10.2.4.68 10.2.4.66 10.2.4.63 10.2.4.61 10.2.4.60 10.2.4.59 10.2.4.57 10.2.4.55 10.2.4.51 10.2.4.48 10.2.4.47 10.2.4.45 10.2.4.44 10.2.4.42 10.2.4.4 10.2.4.37 10.2.4.34 10.2.4.31 10.2.4.30 10.2.4.28 10.2.4.27 10.2.4.25 10.2.4.24 10.2.4.24 10.2.4.232 10.2.4.223 10.2.4.213 10.2.4.206 10.2.4.205 10.2.4.201 10.2.4.20 10.2.4.193 10.2.4.191 10.2.4.190 10.2.4.188 10.2.4.183 10.2.4.181 10.2.4.180 10.2.4.179 10.2.4.178 10.2.4.177 10.2.4.175 10.2.4.17 10.2.4.169 10.2.4.166 10.2.4.160 10.2.4.158 10.2.4.157 10.2.4.155 10.2.4.15 10.2.4.149 10.2.4.148 10.2.4.146 10.2.4.143 10.2.4.141 10.2.4.140 10.2.4.14 10.2.4.137 10.2.4.136 10.2.4.135 10.2.4.134 10.2.4.129 10.2.4.127 10.2.4.126 10.2.4.125 10.2.4.123 10.2.4.122 10.2.4.120 10.2.4.12 10.2.4.119 10.2.4.118 10.2.4.116 10.2.4.115 10.2.4.114 10.2.4.111 10.2.4.11 10.2.4.109 10.2.4.108 10.2.4.103 10.2.4.102 10.2.4.100 10.2.4.10 10.2.3.98 10.2.3.97 10.2.3.91 10.2.3.90 10.2.3.9 10.2.3.83 10.2.3.8 10.2.3.79 10.2.3.76 10.2.3.75 10.2.3.74 10.2.3.73 10.2.3.72 10.2.3.70 10.2.3.7 10.2.3.69 10.2.3.68 10.2.3.67 10.2.3.66 10.2.3.64 10.2.3.61 10.2.3.6 10.2.3.54 10.2.3.51 10.2.3.5 10.2.3.48 10.2.3.46 10.2.3.45 10.2.3.44 10.2.3.42 10.2.3.41 10.2.3.40 10.2.3.4 10.2.3.38 10.2.3.37 10.2.3.36 10.2.3.35 10.2.3.34 10.2.3.30 10.2.3.3 10.2.3.28 10.2.3.26 10.2.3.253 10.2.3.252 10.2.3.251 10.2.3.249 10.2.3.247 10.2.3.244 10.2.3.243 10.2.3.241 10.2.3.240 10.2.3.24 10.2.3.238 10.2.3.237 10.2.3.236 10.2.3.231 10.2.3.23 10.2.3.226 10.2.3.225 10.2.3.224 10.2.3.223 10.2.3.222 10.2.3.221 10.2.3.220 10.2.3.218 10.2.3.216 10.2.3.215 10.2.3.214 10.2.3.21 10.2.3.209 10.2.3.205 10.2.3.203 10.2.3.202 10.2.3.201 10.2.3.200 10.2.3.2 10.2.3.198 10.2.3.197 10.2.3.195 10.2.3.194 10.2.3.190 10.2.3.19 10.2.3.188 10.2.3.186 10.2.3.185 10.2.3.184 10.2.3.183 10.2.3.182 10.2.3.181 10.2.3.180 10.2.3.18 10.2.3.178 10.2.3.177 10.2.3.176 10.2.3.175 10.2.3.174 10.2.3.173 10.2.3.170 10.2.3.169 10.2.3.168 10.2.3.166 10.2.3.165 10.2.3.164 10.2.3.162 10.2.3.161 10.2.3.160 10.2.3.159 10.2.3.158 10.2.3.157 10.2.3.156 10.2.3.155 10.2.3.154 10.2.3.152 10.2.3.150 10.2.3.15 10.2.3.148 10.2.3.147 10.2.3.146 10.2.3.144 10.2.3.143 10.2.3.141 10.2.3.14 10.2.3.135 10.2.3.134 10.2.3.133 10.2.3.132 10.2.3.131 10.2.3.130 10.2.3.13 10.2.3.129 10.2.3.126 10.2.3.125 10.2.3.124 10.2.3.122 10.2.3.12 10.2.3.119 10.2.3.118 10.2.3.117 10.2.3.116 10.2.3.113 10.2.3.112 10.2.3.111 10.2.3.108 10.2.3.107 10.2.3.102 10.2.3.10 10.2.3.1 10.2.2.99 10.2.2.98 10.2.2.96 10.2.2.91 10.2.2.90 10.2.2.89 10.2.2.87 10.2.2.86 10.2.2.85 10.2.2.83 10.2.2.82 10.2.2.81 10.2.2.8 10.2.2.79 10.2.2.78 10.2.2.77 10.2.2.76 10.2.2.74 10.2.2.73 10.2.2.72 10.2.2.71 10.2.2.70 10.2.2.69 10.2.2.66 10.2.2.65 10.2.2.64 10.2.2.61 10.2.2.59 10.2.2.58 10.2.2.57 10.2.2.56 10.2.2.52 10.2.2.5 10.2.2.47 10.2.2.46 10.2.2.45 10.2.2.44 10.2.2.43 10.2.2.42 10.2.2.39 10.2.2.38 10.2.2.36 10.2.2.35 10.2.2.34 10.2.2.33 10.2.2.32 10.2.2.30 10.2.2.3 10.2.2.29 10.2.2.26 10.2.2.254 10.2.2.250 10.2.2.25 10.2.2.249 10.2.2.248 10.2.2.245 10.2.2.244 10.2.2.243 10.2.2.242 10.2.2.240 10.2.2.24 10.2.2.239 10.2.2.238 10.2.2.235 10.2.2.234 10.2.2.233 10.2.2.232 10.2.2.231 10.2.2.23 10.2.2.229 10.2.2.228 10.2.2.227 10.2.2.225 10.2.2.224 10.2.2.223 10.2.2.222 10.2.2.221 10.2.2.220 10.2.2.22 10.2.2.219 10.2.2.216 10.2.2.215 10.2.2.214 10.2.2.213 10.2.2.212 10.2.2.211 10.2.2.21 10.2.2.208 10.2.2.207 10.2.2.205 10.2.2.204 10.2.2.203 10.2.2.202 10.2.2.201 10.2.2.2 10.2.2.198 10.2.2.197 10.2.2.196 10.2.2.194 10.2.2.193 10.2.2.192 10.2.2.190 10.2.2.19 10.2.2.189 10.2.2.184 10.2.2.183 10.2.2.182 10.2.2.181 10.2.2.180 10.2.2.178 10.2.2.176 10.2.2.174 10.2.2.173 10.2.2.172 10.2.2.171 10.2.2.170 10.2.2.169 10.2.2.166 10.2.2.164 10.2.2.163 10.2.2.162 10.2.2.161 10.2.2.16 10.2.2.159 10.2.2.158 10.2.2.156 10.2.2.153 10.2.2.152 10.2.2.151 10.2.2.150 10.2.2.15 10.2.2.146 10.2.2.145 10.2.2.144 10.2.2.143 10.2.2.142 10.2.2.141 10.2.2.140 10.2.2.14 10.2.2.137 10.2.2.133 10.2.2.131 10.2.2.13 10.2.2.129 10.2.2.128 10.2.2.127 10.2.2.126 10.2.2.124 10.2.2.122 10.2.2.121 10.2.2.120 10.2.2.12 10.2.2.118 10.2.2.117 10.2.2.116 10.2.2.115 10.2.2.114 10.2.2.111 10.2.2.11 10.2.2.109 10.2.2.107 10.2.2.105 10.2.2.104 10.2.2.103 10.2.2.101 10.2.2.100 10.2.2.10 10.2.2.1 10.2.1.86 10.2.1.79 10.2.1.254 10.2.1.253 10.2.1.252 10.2.1.251 10.2.1.244 10.2.1.243 10.2.1.240 10.2.1.237 10.2.1.234 10.2.1.231 10.2.1.230 10.2.1.229 10.2.1.228 10.2.1.227 10.2.1.226 10.2.1.225 10.2.1.224 10.2.1.223 10.2.1.216 10.2.1.215 10.2.1.213 10.2.1.212 10.2.1.211 10.2.1.209 10.2.1.208 10.2.1.207 10.2.1.206 10.2.1.205 10.2.1.204 10.2.1.203 10.2.1.200 10.2.1.199 10.2.1.196 10.2.1.195 10.2.1.194 10.2.1.193 10.2.1.192 10.2.1.191 10.2.1.190 10.2.1.189 10.2.1.187 10.2.1.186 10.2.1.185 10.2.1.180 10.2.1.179 10.2.1.150 10.2.1.133 10.2.1.104 10.2.0.179 ) 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 echo "SSH connection successful: $ip_address" # Stop aggregator service if changing aggregator-related files if ssh -o StrictHostKeyChecking=no "$username@$ip_address" "svc -d /service/aggregator"; then echo "Stopped aggregator service on $ip_address" else echo "Warning: Failed to stop aggregator 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 # Copy files if scp -o ConnectTimeout=10 "$release_file_path/dbus-fzsonick-48tl/aggregator.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/aggregator.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 # Start aggregator service if ssh -o StrictHostKeyChecking=no "$username@$ip_address" "svc -u /service/aggregator"; then echo "Started aggregator service on $ip_address" else echo "Warning: Failed to start aggregator 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"