Download with Wget only if new version
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
Solution 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.