create script to update files in all Venus and Cerbo
This commit is contained in:
parent
d6267952e9
commit
0592179e75
|
@ -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"
|
Loading…
Reference in New Issue