[fpc-pascal] Methods for autoupdating fpc programs?
waldo kitty
wkitty42 at windstream.net
Sun Oct 4 18:13:46 CEST 2015
On 10/03/2015 05:40 PM, Bo Berglund wrote:
> On Sat, 3 Oct 2015 15:04:31 -0400, waldo kitty
> <wkitty42 at windstream.net> wrote:
>
>> On 10/03/2015 02:30 PM, Bo Berglund wrote:
>>> The program will probably be started by cron every minute to check if
>>> it has anything to do and if so execute its data collection task and
>>> quit. Otherwise just quit, but here maybe also check for an update on
>>> the web?
>>> But how could one exchange a running program on the pi from within
>>> itself?
>>
>> off the top of my head:
>>
>> since you're running from cron and exiting, this could be pretty simple...
>>
>> 1. at start up, check if self is named known temp name. if yes, copy self to
>> normal name, spawn normal name and die.
>> 2. at start up pull md5 checksum file from server and compare with own md5 checksum.
>> 3. if md5 sums are different, download new version to known temp name.
>
> Would this not compare equal for the exact same version? All others
> including old and newer would fail and thus trigger an update.
if the md5 on the server is the same as the md5 of the currently running
program, there should not be an update made...
> BTW, how does one get the md5 value of ones own executable file?
there's a command line tool known as md5sum... it is also possible to calculate
the same in your own code... what i tried to propose is that when you create the
new binary, you run md5sum on it and place both on the server... you would also
have a md5 file beside the current binary... then you only need to pull the md5
file from the server and compare it with the local one...
>> 4. at end of execution, see if known temp name exists. if it does, spawn it and die.
>>
>> maybe something like that... of course, somewhere in there you'll still do your
>> required processing... the end of execution will wait for everything to be done
>> before doing step 4...
>>
>> one might also use a special command line parameter to tell the known temp name
>> to copy itself over to the normal name in step 1.
>
> Interesting ideas, will have to think about it.
as i noted at the beginning, this was off the top of my head and likely how i
would start if i were to do something similar... it may look and act completely
different in the end as each set of bugs and problems is worked out ;)
> I have not programmed in Linux before so I have no idea if programs
> for Linux carry a version resource that can be checked for the version
> number. Is this the case or is that only a Windows thingie?
the version resource can be done, sure... but how can you check that when
querying the server other than remembering to manually update it each time?
yeah, the md5 file needs to be done and uploaded so it is almost the same type
of thing...
> If not then the MD5 checksum seems to be a good way...
it is actually pretty common... i do a lot of work with IDS/IPS stuff and we use
md5 files on the server with each set of rules archives... we pull the 30someodd
byte md5 file and compare it with the one we have locally before considering to
download the XXsomeodd Meg files...
> I just tested on Lazarus inside the Pi2B and it was simple to do a MD5
> sum of one's own executable:
>
> strMD5 := MD5Print(MD5File(Application.Exename));
>
> The only problem is that it seems to take quite some time to do
> (several seconds) is that normal?
depending on the size of the binary, it could... so if you save that to a file
to put with that binary on the server, then you could pull the md5 file and
compare it with the output of the above when checking if there's an update... is
several seconds execution too long? if so, then write it to a local md5 file to
compare with the server's md5...
--
NOTE: No off-list assistance is given without prior approval.
*Please keep mailing list traffic on the list* unless
private contact is specifically requested and granted.
More information about the fpc-pascal
mailing list