From 747bec2762f0d701cfbbf902b1acacabf42a1fd8 Mon Sep 17 00:00:00 2001 From: AGG2017 Date: Tue, 19 Mar 2024 09:58:53 -0400 Subject: [PATCH] Support for a custom update tool for both pack and build scripts --- TOOLS/custom_install.sh | 32 +++++++++++++++++++ build.sh | 18 +++++++++++ options.cfg | 6 ++++ pack.sh | 70 +++++++++++++++++++++++++++-------------- patch.sh | 3 +- 5 files changed, 105 insertions(+), 24 deletions(-) create mode 100755 TOOLS/custom_install.sh diff --git a/TOOLS/custom_install.sh b/TOOLS/custom_install.sh new file mode 100755 index 0000000..20229d3 --- /dev/null +++ b/TOOLS/custom_install.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +username="root" +ip="192.168.1.242" +port="22" + +# SCP file transfer +echo "Uploading..." +scp -o StrictHostKeyChecking=no -P $port update/update.swu $username@$ip:/mnt/UDISK/update.swu +# MD5 Calculation +md5sum_local=$(md5sum update/update.swu | awk '{ print $1 }') +echo "MD5 Local : $md5sum_local" +md5sum_remote=$(ssh -p $port $username@$ip "md5sum /mnt/UDISK/update.swu" | awk '{ print $1 }') +echo "MD5 Remote: $md5sum_remote" +if [[ "$md5sum_remote" == "$md5sum_local" ]]; then + # Getting boot partition and updating firmware + current_boot_partition=$(ssh -p $port $username@$ip "fw_printenv boot_partition" | awk -F= '{ print $2 }' | tr -d '[:space:]') + boot_partition="now_B_next_A" + if [[ "$current_boot_partition" == "bootA" ]]; then + boot_partition="now_A_next_B" + fi + # Update + echo "Updating..." + ssh -p $port $username@$ip "swupdate_cmd.sh -i /mnt/UDISK/update.swu -e stable,${boot_partition} -k /etc/swupdate_public.pem" + echo "SUCCESS!" + exit 0 +else + # If MD5 checksums don't match, delete the file and retry + ssh -p $port $username@$ip 'rm -f /mnt/UDISK/update.swu' + echo "FAILED!" + exit 1 +fi diff --git a/build.sh b/build.sh index b30274d..244c097 100755 --- a/build.sh +++ b/build.sh @@ -106,6 +106,7 @@ fi # check the config file for build_input and build_output options build_input="" build_output="" +auto_install_tool="" if [ -f "$selected_config_file" ]; then # parse the enabled options that have a set value @@ -126,6 +127,9 @@ if [ -f "$selected_config_file" ]; then if [ "$option" = "build_output" ]; then build_output="$parameter" fi + if [ "$option" = "auto_install" ]; then + auto_install_tool="$parameter" + fi done fi @@ -233,6 +237,20 @@ if [ -n "$build_output" ]; then rm -f "$project_root/update.bin" fi +# use the auto install tool if present +if [ -f "$auto_install_tool" ]; then + # Ask if the user wants to attempt to auto install the update now. If yes then run the auto install script + read -r -p "Do you want to attempt to auto install the update? [y/N] " response + if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then + # Run the auto update tool + if [[ "$auto_install_tool" == *.py ]]; then + python3 "$auto_install_tool" + else + "$auto_install_tool" + fi + fi +fi + echo echo -e "${YELLOW}Selected firmware file: $selected_firmware_file ${NC}" echo -e "${YELLOW}Selected configuration file: $selected_config_file ${NC}" diff --git a/options.cfg b/options.cfg index 3cf7c68..6f47b5d 100644 --- a/options.cfg +++ b/options.cfg @@ -120,3 +120,9 @@ app_nocamera="default" # Enable kobra unleashed prod version test # https://github.com/anjomro/kobra-unleashed/tree/go-server #kobra_unleashed="kobra_unleashed-v1" + +# Enable this option if you want to be executed after the packing script completes +# if you want to install the generated update by ssh +# You have to have ssh and root_access enabled, and setup the auto_install.cfg +#auto_install="@/TOOLS/custom_install.sh" +#auto_install="@/TOOLS/auto_install.py" \ No newline at end of file diff --git a/pack.sh b/pack.sh index da4ca0f..a7e13a6 100755 --- a/pack.sh +++ b/pack.sh @@ -5,21 +5,11 @@ project_root="$PWD" # Source the utils.sh file source "$project_root/TOOLS/helpers/utils.sh" "$project_root" -# the result of installed options log -installed_options="installed_options.log" - # files needed FILES="sw-description sw-description.sig boot-resource uboot boot0 kernel rootfs dsp0 cpio_item_md5" # check the required tools -check_tools "grep md5sum openssl wc awk sha256sum mksquashfs python3 auto_install.py" - -# set the custom auto update tool -AUTO_UPDATE_TOOL=$(which "auto_install.py") -if [ -z "$AUTO_UPDATE_TOOL" ]; then - # if not installed use the local copy - AUTO_UPDATE_TOOL="TOOLS/auto_install.py" -fi +check_tools "grep md5sum openssl wc awk sha256sum mksquashfs" # remove the last created update rm -rf update @@ -87,18 +77,52 @@ echo "" echo -e "${GREEN}Packing done: Use the file update/update.swu to do USB update${NC}" echo "" -# check if the auto update is possible -if [ -f "$installed_options" ]; then - root_pw=$(grep "root_access=" "$installed_options") - ssh_option=$(grep "ssh=" "$installed_options") - if [ -z "$root_pw" ] || [ "$root_pw" == 'root_access=""' ] || [ -z "$ssh_option" ]; then - echo -e "Root access option is not installed, the root password is empty or the ssh is disabled.\nThe auto update is not possible. Please use the USB update procedure." - else - # Ask if the user wants to attempt to auto install the update. If yes then run the auto install script - read -r -p "Do you want to attempt to auto install the update? [y/N] " response - if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then - # Run the auto update tool - python3 "$AUTO_UPDATE_TOOL" +# select a config file +selected_config_file="options.cfg" +if [ $# -eq 1 ]; then + cfg_file="$project_root/$1" + if [ -f "$cfg_file" ]; then + # it is a configuration file with ext + selected_config_file="$cfg_file" + elif [ -f "${cfg_file}.cfg" ]; then + echo "${cfg_file}.cfg" + # it is a configuration file without ext + selected_config_file="${cfg_file}.cfg" + fi +fi + +# check if the auto update is enabled and get the selected tool +auto_install_tool="" +if [ -f "$selected_config_file" ]; then + + # parse the enabled options that have a set value + options=$(awk -F '=' '{if (! ($0 ~ /^;/) && ! ($0 ~ /^#/) && ! ($0 ~ /^$/) && ! ($2 == "")) print $1}' "$selected_config_file") + + # for each enabled option + for option in $options; do + parameters=$(awk -F '=' "{if (! (substr(\$0,1,1) == \"#\") && ! (substr(\$0,1,1) == \";\") && ! (\$1 == \"\") && ! (\$2 == \"\") && (\$1 ~ /$option/ ) ) print \$2}" "$selected_config_file" | head -n 1) + # replace the project root requests + parameter="${parameters/@/"$project_root"}" + # remove the leading and ending double quotes + parameter=$(echo "$parameter" | sed -e 's/^"//' -e 's/"$//') + # remove the leading and ending single quotes + parameter=$(echo "$parameter" | sed -e 's/^'\''//' -e 's/'\''$//') + if [ "$option" = "auto_install" ]; then + auto_install_tool="$parameter" + fi + done +fi + +# use the auto install tool if present +if [ -f "$auto_install_tool" ]; then + # Ask if the user wants to attempt to auto install the update now. If yes then run the auto install script + read -r -p "Do you want to attempt to auto install the update? [y/N] " response + if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then + # Run the auto update tool + if [[ "$auto_install_tool" == *.py ]]; then + python3 "$auto_install_tool" + else + "$auto_install_tool" fi fi fi diff --git a/patch.sh b/patch.sh index e1d9304..db4a3aa 100755 --- a/patch.sh +++ b/patch.sh @@ -37,7 +37,8 @@ options=$(awk -F '=' '{if (! ($0 ~ /^;/) && ! ($0 ~ /^#/) && ! ($0 ~ /^$/) && ! for option in $options; do # skip the options build_input & build_output that are used only in build.sh - if [ "$option" = "build_input" ] || [ "$option" = "build_output" ]; then + # skip the option auto_install that is used only in pack.sh + if [ "$option" = "build_input" ] || [ "$option" = "build_output" ] || [ "$option" = "auto_install" ]; then continue fi