Merge branch 'main' of ssh://github.com/ultimateshadsform/Anycubic-Kobra-2-Series-Tools

This commit is contained in:
Alexander 2024-03-22 23:10:06 +01:00
commit c5a4e1253a
6 changed files with 109 additions and 28 deletions

32
TOOLS/custom_install.sh Executable file
View file

@ -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

View file

@ -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}"

View file

@ -63,7 +63,7 @@ ssh="dropbear"
# Depends on the option "app_nocamera" only for versions 3.0.5+
# No dependency for versions below 3.0.5
# Available for versions 2.3.9 ... 3.1.0 (recommended)
# webserver="webfs-v5:8000" [app_nocamera]
webserver="webfs-v5:8000" [app_nocamera]
# Enable Python 3 (+14MB to the update, +25MB to the rootfs)
# Select the version you need. Python might be required by some other options
@ -110,13 +110,19 @@ app_dns="208.67.222.222|1.1.1.1"
# Patch the app to stop supporting webcams. This allows a custom camera support
# Available for versions 3.0.5+ (recommended if webcam is used)
# app_nocamera="default"
app_nocamera="default"
# Add a script for custom initializations at startup
# like starting a custom MQTT server, webcam steaming, etc.
# Place startup scripts inside this script.
startup_script="startup.sh"
#startup_script="startup.sh"
# Enable kobra unleashed prod version test
# https://github.com/anjomro/kobra-unleashed/tree/go-server
kobra_unleashed="kobra_unleashed-v1"
#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"

70
pack.sh
View file

@ -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

View file

@ -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