From 21e90ba691e2142279a5510d89cf5534196b05df Mon Sep 17 00:00:00 2001 From: John Cudd Date: Thu, 7 Nov 2024 11:43:56 -0500 Subject: [PATCH] Tools: Checksum for gcc-arm download on arch prereqs This will check to see if the tar.bz2 file exists and if it does it will run a checksum and skip redownloading the file if its already there. If the checksum fails or the file doesn't exist it will redownload the file. I ran into issues with the download taking so long that my sudo permissions timed out and the install failed to complete. When rerunning the script it would redownload the file even if the file was already there. This change solves this issue. --- .../install-prereqs-arch.sh | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/Tools/environment_install/install-prereqs-arch.sh b/Tools/environment_install/install-prereqs-arch.sh index 6b304799a75a2..6abdb7f5926b8 100755 --- a/Tools/environment_install/install-prereqs-arch.sh +++ b/Tools/environment_install/install-prereqs-arch.sh @@ -33,6 +33,7 @@ PYTHON_PKGS="future lxml pymavlink MAVProxy pexpect argparse matplotlib pyparsin ARM_ROOT="gcc-arm-none-eabi-10-2020-q4-major" ARM_TARBALL="$ARM_ROOT-x86_64-linux.tar.bz2" ARM_TARBALL_URL="https://firmware.ardupilot.org/Tools/STM32-tools/$ARM_TARBALL" +ARM_TARBALL_CHECKSUM="21134caa478bbf5352e239fbc6e2da3038f8d2207e089efc96c3b55f1edcd618" # Ardupilot Tools ARDUPILOT_TOOLS="ardupilot/Tools/autotest" @@ -85,9 +86,33 @@ pip3 -q install -U $PYTHON_PKGS if [ ! -d $OPT/$ARM_ROOT ]; then ( cd $OPT; - sudo wget --progress=dot:giga $ARM_TARBALL_URL; - sudo tar xjf ${ARM_TARBALL}; - sudo rm ${ARM_TARBALL}; + + # Check if file exists and verify checksum + download_required=false + if [ -e "$ARM_TARBALL" ]; then + echo "File exists. Verifying checksum..." + + # Calculate the checksum of the existing file + ACTUAL_CHECKSUM=$(sha256sum "$ARM_TARBALL" | awk '{ print $1 }') + + # Compare the actual checksum with the expected one + if [ "$ACTUAL_CHECKSUM" == "$ARM_TARBALL_CHECKSUM" ]; then + echo "Checksum valid. No need to redownload." + else + echo "Checksum invalid. Redownloading the file..." + download_required=true + sudo rm $ARM_TARBALL + fi + else + echo "File does not exist. Downloading..." + download_required=true + fi + + if $download_required; then + sudo wget -O "$ARM_TARBALL" --progress=dot:giga $ARM_TARBALL_URL + fi + + sudo tar xjf ${ARM_TARBALL} ) fi