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

Perovic
  • 21
  • 2

1 Answers1

1

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.

Gerard H. Pille
  • 2,569
  • 1
  • 13
  • 11
  • Can you please give an example of how can I have the header? Thank you – Perovic May 26 '21 at 09:03
  • "can I have the header" ? Get the header or send the header? – Gerard H. Pille May 29 '21 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 May 31 '21 at 12:08