So, I'm writing this CB text client and adding more bloat to it everyday, solely in the context of "why the heck not?"

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

version: pmchat cat pmchat | grep '\$$Id' | head -1 | cut -f4 -d' ' > version
(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 like
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"; }
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 :)

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

    I resent and distrust software that tries to automatically update itself. So please provide a manually-triggered "auto update" and provide, at least, the option of turning any automated checks for new versions off and a method of backing out the most recent update.

            - tye (but my friends call me "Tye")
Re: Fun with an auto-update
by epoptai (Curate) on May 28, 2001 at 22:24 UTC
    Very cool idea. I've got update notification in framechat and reputer that merely compares the script version with info in an html comment somewhere on perlmonks when a certain button is selected.

    To update in-place I would try to separate code that's subject to updates into a file to require, so the #! and any user defined vars are left intact. I'd also be concerned with portable methods of creating and executing new files.

    Looking forward to whatever you come up with.

    --
    Check out my Perlmonks Related Scripts like framechat, reputer, and xNN.

Re: Fun with an auto-update
by chipmunk (Parson) on May 29, 2001 at 02:52 UTC
    You may want to look at how the CPAN module's reload command is implemented. When you're in the CPAN shell, you can install CPAN and then reload to immediately load the new version, without leaving the shell.