From db0e6dadfc83d099b9b43e726c769b7d9f22ae7a Mon Sep 17 00:00:00 2001 From: Wessel Tip Date: Mon, 8 Sep 2025 11:59:58 +0200 Subject: [PATCH] feat: Add JOZ scripts --- bin/.expect-btg-login | 11 +++++++++++ bin/.expect-btg-pass | 12 ++++++++++++ bin/.expect-btg-test-jozagv | 14 ++++++++++++++ bin/btg | 1 + bin/btg-download | 1 + bin/btg-download-database | 1 + bin/btg-download-full | 11 +++++++++++ bin/btg-download-jozagv | 1 + bin/btg-download-logs | 2 ++ bin/btg-download-map | 1 + bin/btg-download-ram | 1 + bin/btg-mount-fs | 26 ++++++++++++++++++++++++++ bin/btg-ping | 1 + bin/btg-scp | 33 +++++++++++++++++++++++++++++++++ bin/btg-test-jozagv | 2 ++ bin/btg-upload-database | 1 + bin/btg-upload-jozagv | 4 ++++ bin/btg-upload-jozagv-configs | 1 + bin/btg-upload-jozagv-debug | 5 +++++ bin/btg-upload-jozagv-release | 4 ++++ bin/btg-upload-map | 1 + bin/btg-upload-ram | 1 + bin/btg-upload-remote | 3 +++ 23 files changed, 138 insertions(+) create mode 100755 bin/.expect-btg-login create mode 100755 bin/.expect-btg-pass create mode 100755 bin/.expect-btg-test-jozagv create mode 100755 bin/btg create mode 100755 bin/btg-download create mode 100755 bin/btg-download-database create mode 100755 bin/btg-download-full create mode 100755 bin/btg-download-jozagv create mode 100755 bin/btg-download-logs create mode 100755 bin/btg-download-map create mode 100755 bin/btg-download-ram create mode 100755 bin/btg-mount-fs create mode 100755 bin/btg-ping create mode 100755 bin/btg-scp create mode 100755 bin/btg-test-jozagv create mode 100755 bin/btg-upload-database create mode 100755 bin/btg-upload-jozagv create mode 100755 bin/btg-upload-jozagv-configs create mode 100755 bin/btg-upload-jozagv-debug create mode 100755 bin/btg-upload-jozagv-release create mode 100755 bin/btg-upload-map create mode 100755 bin/btg-upload-ram create mode 100755 bin/btg-upload-remote diff --git a/bin/.expect-btg-login b/bin/.expect-btg-login new file mode 100755 index 0000000..849dc2c --- /dev/null +++ b/bin/.expect-btg-login @@ -0,0 +1,11 @@ +#!/usr/bin/expect -f +eval spawn $argv +set timeout -1 +match_max 100000 +expect "*?assword:*" +puts "\nAutofill password..." +send -- "$env(BTG_PASSWORD)\r" +sleep 0.3 +send -- "su\r" +send -- "cd /media/ram\r" +interact diff --git a/bin/.expect-btg-pass b/bin/.expect-btg-pass new file mode 100755 index 0000000..64101f8 --- /dev/null +++ b/bin/.expect-btg-pass @@ -0,0 +1,12 @@ +#!/usr/bin/expect -f +eval spawn $argv +set timeout -1 +match_max 100000 +expect "*?assword:*" +puts "\nAutofill password..." +send -- "$env(BTG_PASSWORD)\r" +expect eof + +set return_code [wait] +exit [lindex $return_code 3] + diff --git a/bin/.expect-btg-test-jozagv b/bin/.expect-btg-test-jozagv new file mode 100755 index 0000000..e4b215a --- /dev/null +++ b/bin/.expect-btg-test-jozagv @@ -0,0 +1,14 @@ +#!/usr/bin/expect -f +eval spawn $argv +set timeout -1 +match_max 100000 +expect "*?assword:*" +puts "\nAutofill password..." +send -- "$env(BTG_PASSWORD)\r" +sleep 0.3 +send -- "su\r" +send -- "/etc/init.d/crond stop\r" +send -- "/etc/init.d/jozagv stop\r" +send -- "killall -9 jozagv\r" +send -- "/media/ram/jozagv\r" +interact diff --git a/bin/btg b/bin/btg new file mode 100755 index 0000000..2da7e89 --- /dev/null +++ b/bin/btg @@ -0,0 +1 @@ +~/.local/bin/.expect-btg-login ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no btg@$BTG_IP diff --git a/bin/btg-download b/bin/btg-download new file mode 100755 index 0000000..790f8e3 --- /dev/null +++ b/bin/btg-download @@ -0,0 +1 @@ +btg-scp btg@$BTG_IP:$@ . diff --git a/bin/btg-download-database b/bin/btg-download-database new file mode 100755 index 0000000..5ca28bf --- /dev/null +++ b/bin/btg-download-database @@ -0,0 +1 @@ +btg-scp btg@$BTG_IP:/usr/share/joz/jozdb.sqlite3 . diff --git a/bin/btg-download-full b/bin/btg-download-full new file mode 100755 index 0000000..0f8d7a0 --- /dev/null +++ b/bin/btg-download-full @@ -0,0 +1,11 @@ +out_dir=$(date +'full_%Y_%m_%d__%H_%M_%S') + +mkdir $out_dir +cd $out_dir + +# Download logs +btg-scp -r btg@$BTG_IP:/joz/agv/logs . + +btg-download-jozagv +btg-download-map +btg-download-database diff --git a/bin/btg-download-jozagv b/bin/btg-download-jozagv new file mode 100755 index 0000000..32f43fb --- /dev/null +++ b/bin/btg-download-jozagv @@ -0,0 +1 @@ +btg-scp btg@$BTG_IP:/joz/agv/jozagv . diff --git a/bin/btg-download-logs b/bin/btg-download-logs new file mode 100755 index 0000000..fdb3f08 --- /dev/null +++ b/bin/btg-download-logs @@ -0,0 +1,2 @@ +logs_dir=$(date +'logs_%Y_%m_%d__%H_%M_%S') +btg-scp -r btg@$BTG_IP:/joz/agv/logs $logs_dir diff --git a/bin/btg-download-map b/bin/btg-download-map new file mode 100755 index 0000000..c6030fa --- /dev/null +++ b/bin/btg-download-map @@ -0,0 +1 @@ +btg-scp btg@$BTG_IP:/etc/joz/*.xml . diff --git a/bin/btg-download-ram b/bin/btg-download-ram new file mode 100755 index 0000000..df5dda3 --- /dev/null +++ b/bin/btg-download-ram @@ -0,0 +1 @@ +btg-download /media/ram/$@ . diff --git a/bin/btg-mount-fs b/bin/btg-mount-fs new file mode 100755 index 0000000..9323102 --- /dev/null +++ b/bin/btg-mount-fs @@ -0,0 +1,26 @@ +mount_folder=/mnt/btg +.enable_sshfs_user_allow_other.sh + +if [[ ! $(sudo echo 0) ]]; then exit; fi + +if mountpoint -q $mount_folder +then + echo "Mount point $mount_folder is already mounted, to unmount call 'umount $mount_folder'" + exit 0 +fi + +sudo mkdir -p $mount_folder +sudo chmod 777 $mount_folder + +#Execute the sshfs command using the expect script +sshfs -o allow_other -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o password_stdin btg@$BTG_IP:/ $mount_folder <<< $BTG_PASSWORD + +retval=$? + +# Check if retval is zero +if [ $retval -eq 0 ]; then + echo "Successfully mounted to $mount_folder" +else + echo "Error: command failed with return code $retval" + exit $retval +fi diff --git a/bin/btg-ping b/bin/btg-ping new file mode 100755 index 0000000..f4acb38 --- /dev/null +++ b/bin/btg-ping @@ -0,0 +1 @@ +ping $BTG_IP diff --git a/bin/btg-scp b/bin/btg-scp new file mode 100755 index 0000000..cb61169 --- /dev/null +++ b/bin/btg-scp @@ -0,0 +1,33 @@ +#Execute the scp command using the expect script +~/.local/bin/.expect-btg-pass scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $@ + +#get result +retval=$? + +# Define error code messages +case $retval in + 0) + echo "Upload/Download Successfull!" + ;; + 1) + echo "Invalid command line argument" + ;; + 2) + echo "Conflicting arguments given" + ;; + 3) + echo "General runtime error" + ;; + 4) + echo "Unrecognized response from ssh (parse error)" + ;; + 5) + echo "Invalid/incorrect password" + ;; + 6) + echo "Host public key is unknown. sshpass exits without confirming the new key." + ;; + *) + echo "Unknown error code: $retval" + ;; +esac diff --git a/bin/btg-test-jozagv b/bin/btg-test-jozagv new file mode 100755 index 0000000..70f447e --- /dev/null +++ b/bin/btg-test-jozagv @@ -0,0 +1,2 @@ +btg-upload-jozagv +~/bin/.expect-btg-test-jozagv ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no btg@$BTG_IP diff --git a/bin/btg-upload-database b/bin/btg-upload-database new file mode 100755 index 0000000..8704079 --- /dev/null +++ b/bin/btg-upload-database @@ -0,0 +1 @@ +btg-scp $@ btg@$BTG_IP:/usr/share/joz/jozdb.sqlite3 diff --git a/bin/btg-upload-jozagv b/bin/btg-upload-jozagv new file mode 100755 index 0000000..986dcde --- /dev/null +++ b/bin/btg-upload-jozagv @@ -0,0 +1,4 @@ +JOZAGV_PATH=$JOZ_PATH/jozagv/build/JOZ_Robot_Controller_SDK/MinSizeRel/jozagv + +btg-upload-jozagv-configs +btg-upload-jozagv-release diff --git a/bin/btg-upload-jozagv-configs b/bin/btg-upload-jozagv-configs new file mode 100755 index 0000000..fce11d4 --- /dev/null +++ b/bin/btg-upload-jozagv-configs @@ -0,0 +1 @@ +btg-scp -r $JOZ_PATH/jozagv/config/* btg@$BTG_IP:/etc/joz diff --git a/bin/btg-upload-jozagv-debug b/bin/btg-upload-jozagv-debug new file mode 100755 index 0000000..5263abc --- /dev/null +++ b/bin/btg-upload-jozagv-debug @@ -0,0 +1,5 @@ +JOZAGV_PATH=$JOZ_PATH/jozagv/build/JOZ_Robot_Controller_SDK/Debug/jozagv + +btg-upload-jozagv-configs +echo "Upload jozagv with modification date: $(stat -c '%y' $JOZAGV_PATH)" +btg-scp-ram $JOZAGV_PATH diff --git a/bin/btg-upload-jozagv-release b/bin/btg-upload-jozagv-release new file mode 100755 index 0000000..74b2786 --- /dev/null +++ b/bin/btg-upload-jozagv-release @@ -0,0 +1,4 @@ +JOZAGV_PATH=$JOZ_PATH/jozagv/build/JOZ_Robot_Controller_SDK/MinSizeRel/jozagv + +echo "Upload jozagv with modification date: $(stat -c '%y' $JOZAGV_PATH)" +btg-upload-ram $JOZAGV_PATH diff --git a/bin/btg-upload-map b/bin/btg-upload-map new file mode 100755 index 0000000..8b2cb29 --- /dev/null +++ b/bin/btg-upload-map @@ -0,0 +1 @@ +btg-scp $@ btg@$BTG_IP:/etc/joz/map.xml diff --git a/bin/btg-upload-ram b/bin/btg-upload-ram new file mode 100755 index 0000000..0d86345 --- /dev/null +++ b/bin/btg-upload-ram @@ -0,0 +1 @@ +btg-scp $@ btg@$BTG_IP:/media/ram diff --git a/bin/btg-upload-remote b/bin/btg-upload-remote new file mode 100755 index 0000000..cddd38d --- /dev/null +++ b/bin/btg-upload-remote @@ -0,0 +1,3 @@ +newest_build_file=$(ls -td $JOZ_PATH/remote/build/joz/*/* | head -1) +newest_build_dir=$(dirname ${newest_build_file}) +btg-scp $newest_build_dir/language.bin $newest_build_dir/version $newest_build_dir/firmware.bin btg@$BTG_IP:/etc/joz/remote/0