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.


In reply to Fun with an auto-update by mr.nick

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.