I want to write auto update script for my embedded device, which can check and download newer version of my program and extract the files on the device.
The download center is hosted on remote web server .
Script checks the hosted file on web site and if the new version is there then download it to the embedded device and extract the files in the dirs. But if the test.tar.gz is already downloaded and the files are already extracted then do nothing.
The embedded device runs Linux.
Example, this script actually does the work, but It replace the files all the time. I don't want to overwrite the files.
#!/bin/sh
wget http:xxx.myftp.org:2322/add/test.tar.gz
tar -zxvf test.tar.gz -C /
rm test.tar.gz
My suggestion is to load up a "version file" together with the software bundle. You script would then download the version file first (the file would contain only the version as text), compare that to the version installed and then either do nothing or go through the update routine.
Something like:
#!/bin/sh
typeset -i installed="$(cat /etc/installed-version)" # get version somehow
typeset -i update=0
wget http://xxx.myftp.org:2322/add/current-version
update=$(cat current-version)
if [ $update -gt $installed ] ; then
wget http://xxx.myftp.org:2322/add/current-version
tar -zxvf test.tar.gz -C /
mv current-version /etc/installed-version # update installed version
rm test.tar.gz
fi
Probably not the most elegant solution, but you sure can start with that and add some elaboration, so i hope this helps.
Have you prepared the version-files? If yes, what have you written in them? You are supposed to write there a single line with a number on it, like "1" or "123" or whatever (to be precise, whatever fits into a signed 32-bit integer value as this is the value range for shell variables).
I haven't mentioned this thinking that it would be obvious. Presumably it wasn't.