0

Good morning, I have a custom software that updates with a custom script.sh. Part of the file goes something like this:

if [[ $software == A ]]
  then
    echo "downloading package..."
    rm -rf test.zip >> SoftwareUpdate.log
    wget --user admin --password "test" https://update.example.com/software/test.zip >> SoftwareUpdate.log
    if test -f test.zip
     then
       echo "Performing Backup of Old software"
       zip -r backup/test-$now.zip /var/www/html/* >> SoftwareUpdate.log
       echo "Clearing out old software from folder html"
       rm -rf software/* >> SoftwareUpdate.log
       echo "Unziping new software"
       unzip test.zip -d software  >> SoftwareUpdate.log
       echo "Overwriting / Applying update ..."
       yes | cp -rf software/* /var/www/html/ >> SoftwareUpdate.log
       echo "Changing permissions"
       chown -R www-data /var/www/html/* >> SoftwareUpdate.log
      else
       echo "test.zip doesn't exist, please insure that update is available and try again"
     fi

What I would like to do is have versions in name file, For example: test_1239.zip or test_1531.zip The software should check if the version available to wget is newer than the last one he downloaded, and proceed if that is true.

So scenario If online version = test_1531.zip and last downloaded version = test_1239.zip 1531 is larger than 1239 then proceed with download and update. Thank you

2 Answers 2

2

Save the "Last-Modified" header contents from the last test.zip you downloaded, and add a "If-Modified-Since" header to your next wget request using the date string you received.

The server will answer with a 304 if there's no test.zip more recent.

As an alternative, you could leave test.zip in the current directory, then using wget with the timestamping option (-N), will only download test.zip if the server has a newer version. Check the output of wget, if it contains "304 Not Modified" and "Omitting download", you know you may skip the version control.

3
  • Can you please give an example of how can I have the header? Thank you
    – Perovic
    Commented May 26, 2021 at 9:03
  • "can I have the header" ? Get the header or send the header? Commented May 29, 2021 at 10:18
  • What I would like to do is have test-v3.1334.zip and v.1.3335.zip basically the script should check and see that the version it has is v3.1334 which is smalled than 1.335 and proceed with it as above. else it says already up to date. Thanks
    – Perovic
    Commented May 31, 2021 at 12:08
0

You could use curl like this:

curl -o "$file" -z "$file" "$uri"

source of the information with explanations here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .