One of the things I added was a method for checking on, and possibly installing, updates. The basis for it is something like putting in my Makefile
(which takes the version number from $Id$ and puts it into a file). I also have a my $ID='$Id$' at the top of my code. And then a function likeversion: pmchat cat pmchat | grep '\$$Id' | head -1 | cut -f4 -d' ' > version
Eventually, I would like to add some error checking and see if I can't get it to actually update itself, in place (you know: moving $0 to a temp name, creating a new $0 and exec' itself). But the trust-level isn't there yet :)sub autoupdate { my $r=$ua->request(GET "http://www.mrnick.binary9.net/pmchat/version +"); my($ver)=$r->content=~/^([\d\.]+)$/; my($this)=$ID=~/,v\s+([\d\.]+)/; print "This version is $this, the current version is $ver.\n"; if ($this >= $ver) { print "There is no need to update.\n"; return; } $r=$ua->request(GET "http://www.mrnick.binary9.net/pmchat/pmchat"); unless (open (OUT,">/tmp/pmchat.$ver")) { print "Unable to save newest version to /tmp/pmchat.$ver\n"; return; } print OUT $r->content; close OUT; print "/tmp/pmchat.$ver now contains the newest version.\n"; }
So, I was wondering: does anyone have any real experience doing this sort of thing? Any ideas and suggestions, other than "Don't do this, it's terribly unsafe"? Any way to make it less unsafe?
I suppose CPAN is the best Perl example for updating stuff, but I'm looking at a more application level than that (does CPAN (the module) have the facility to update using another site than the CPAN mirrors? Ie, can you make your own, private CPAN site that the module can interface with?).
Update: As tye pointed out, truely "auto" updates suck. I had no intention of making it do the checking and updating without prompting; in fact, in its current incarnation it's a command you have to type "/update"; it'll never be forced on you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: Fun with an auto-update
by tye (Sage) on May 28, 2001 at 22:03 UTC | |
|
Re: Fun with an auto-update
by epoptai (Curate) on May 28, 2001 at 22:24 UTC | |
|
Re: Fun with an auto-update
by chipmunk (Parson) on May 29, 2001 at 02:52 UTC |