@@ -4,11 +4,24 @@ projectDir=RaspberryPi
44piUserName=team02
55piIpAddressLocal=10.21.221.64
66piIpAddressRemote=10.21.221.19
7- piPath=/home/team02
7+ piPathBin=/opt/vehicle/bin
8+ piPathEtc=/opt/vehicle/etc/zenoh
89piPass=seameteam2
9-
1010architecture=$( uname -m)
11- echo " Detected architecture: $architecture "
11+
12+ check_ssh_connection () {
13+ local host=$1
14+ local user=$2
15+ echo " Checking connection to $host ..."
16+ # Use nc (netcat) to test connection with 5 second timeout
17+ if nc -G 5 -z " $host " 22 > /dev/null 2>&1 ; then
18+ # Test SSH login
19+ if sshpass -p " $piPass " ssh -q -o ConnectTimeout=5 " $user @$host " exit ; then
20+ return 0
21+ fi
22+ fi
23+ return 1
24+ }
1225
1326# Build docker image with appropriate platform flag
1427echo " Building docker image to build app..."
@@ -33,7 +46,31 @@ echo "Copy the binary from tmp container"
3346docker cp tmpapp:/home/$projectDir /InstrumentClusterApp ./InstrumentClusterApp
3447docker cp tmpapp:/home/$projectDir /HandClusterApp ./HandClusterApp
3548docker cp tmpapp:/home/$projectDir /MiddleWareApp ./MiddleWareApp
36- echo " Send binary to local rasp over scp"
37- sshpass -p " $piPass " scp InstrumentClusterApp MiddleWareApp " $piUserName " @" $piIpAddressLocal " :" $piPath "
38- echo " Send binary to remote rasp over scp"
39- sshpass -p " $piPass " scp HandClusterApp " $piUserName " @" $piIpAddressRemote " :" $piPath "
49+
50+ if check_ssh_connection " $piIpAddressLocal " " $piUserName " ; then
51+ echo " Stopping services on local Raspberry Pi..."
52+ sshpass -p " $piPass " ssh " $piUserName " @" $piIpAddressLocal " " sudo systemctl stop middleware.service && pkill InstrumentClus"
53+
54+ echo " Send binary to local rasp over scp"
55+ sshpass -p " $piPass " scp InstrumentClusterApp MiddleWareApp " $piUserName " @" $piIpAddressLocal " :" $piPathBin "
56+ sshpass -p " $piPass " scp ./$projectDir /ZenohConfig/InstrumentClusterConfig.json ./$projectDir /ZenohConfig/MiddleWareConfig.json " $piUserName " @" $piIpAddressLocal " :" $piPathEtc "
57+
58+ echo " Restarting services on local Raspberry Pi..."
59+ sshpass -p " $piPass " ssh " $piUserName " @" $piIpAddressLocal " " sudo systemctl start middleware.service"
60+
61+ echo " InstrumentCluster will restart on next login"
62+ else
63+ echo " ERROR: Cannot connect to local Raspberry Pi at $piIpAddressLocal "
64+ fi
65+
66+ if check_ssh_connection " $piIpAddressRemote " " $piUserName " ; then
67+ echo " Stopping service on remote Raspberry Pi..."
68+ sshpass -p " $piPass " ssh " $piUserName " @" $piIpAddressRemote " " pkill HandCluster"
69+
70+ echo " Send binary to remote rasp over scp"
71+ sshpass -p " $piPass " scp HandClusterApp " $piUserName " @" $piIpAddressRemote " :" $piPathBin "
72+
73+ echo " HandCluster will restart on next login"
74+ else
75+ echo " ERROR: Cannot connect to remote Raspberry Pi at $piIpAddressRemote "
76+ fi
0 commit comments