Wget download file ( do not overwrite )

Hello all,

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.

bakunin

1 Like

Yes you are right with the "version file", your solution will works.

Unfortunately I am running linux on embedded device and this command "typeset" does not exist.

Hmm...

"typeset" is not a command, it is a shell internal, just like "if", "while", etc.. I suggest you simply try it. It is just to declare variables.

I hope this helps.

bakunin

In other words, if your shell complains, remove the 'typeset -i' from in front of the variables and leave the rest.

1 Like

Lets see now :slight_smile:

---------- Post updated at 11:52 AM ---------- Previous update was at 11:20 AM ----------

It says error

[: 12: Illegal number:

The script you were given only has 10 lines.

Show the script as you have it.

It is the same script which bakunin wrote. I just copied and pasted in Notepad ++, also I changed the http link and files name.

Ahem...

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.

I hope this helps.

bakunin