From 7322898b4442df440c70ccccacc104fd7e07a974 Mon Sep 17 00:00:00 2001 From: Elijah Perrault Date: Tue, 8 Feb 2011 20:26:54 -0700 Subject: [PATCH] Start Lib::Auto. --- bin/auto | 31 ++----------------------------- src/Lib/Auto.pm | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 src/Lib/Auto.pm diff --git a/bin/auto b/bin/auto index e1f39de..d641d5e 100755 --- a/bin/auto +++ b/bin/auto @@ -30,6 +30,7 @@ BEGIN { GR => substr `cat $Bin/../.git/refs/heads/indev`, 0, 7 }; } +use Lib::Auto; use API::Std qw(conf_get err); use API::Log qw(println alog dbug); use DB::Flatfile; @@ -38,7 +39,6 @@ use Parser::Lang; use Parser::IRC; use Core::IRC; - our $VERSION = 3.0.0; local $PROGRAM_NAME = 'auto'; @@ -119,34 +119,7 @@ if (defined $ARGV[0]) { } # Check for updates. -if (!$NUC and RSTAGE ne 'd') { - println '* Connecting to update server...'; - my $uss = IO::Socket::INET->new( - 'Proto' => 'tcp', - 'PeerAddr' => 'dist.xelhua.org', - 'PeerPort' => 80, - 'Timeout' => 30 - ) or err(1, 'Cannot connect to update server! Aborting update check.'); - send $uss, "GET http://dist.xelhua.org/auto/version.txt\n", 0; - my $dll = q{}; - while (my $data = readline $uss) { - $data =~ s/(\n|\r)//g; - my ($v, $c) = split m/[=]/, $data; - - if ($v eq 'url') { - $dll = $c; - } - elsif ($v eq 'version') { - if (VER.q{.}.SVER.q{.}.REV.RSTAGE ne $c) { - println('!!! NOTICE !!! Your copy of Auto is outdated. Current version: '.VER.q{.}.SVER.q{.}.REV.RSTAGE.' - Latest version: '.$c); - println('!!! NOTICE !!! You can get the latest Auto by downloading '.$dll); - } - else { - println('* Auto is up-to-date.'); - } - } - } -} +&Lib::Auto::checkver(); # Include IPv6 if Auto was built for it. if ($ENFEAT =~ /ipv6/) { require IO::Socket::INET6; } diff --git a/src/Lib/Auto.pm b/src/Lib/Auto.pm new file mode 100644 index 0000000..4858c81 --- /dev/null +++ b/src/Lib/Auto.pm @@ -0,0 +1,41 @@ +# Auto IRC Bot. An advanced, lightweight and powerful IRC bot. +# Copyright (C) 2010-2011 Xelhua Development Team (doc/CREDITS) +# This program is free software; rights to this code are stated in doc/LICENSE. +package Lib::Auto; +use strict; +use warnings; +use API::Log qw(println); +our $VERSION = 3.000000; + +# Update checker. +sub checkver +{ + if (!$Auto::NUC and Auto::RSTAGE ne 'd') { + println '* Connecting to update server...'; + my $uss = IO::Socket::INET->new( + 'Proto' => 'tcp', + 'PeerAddr' => 'dist.xelhua.org', + 'PeerPort' => 80, + 'Timeout' => 30 + ) or err(1, 'Cannot connect to update server! Aborting update check.'); + send $uss, "GET http://dist.xelhua.org/auto/version.txt\n", 0; + my $dll = q{}; + while (my $data = readline $uss) { + $data =~ s/(\n|\r)//g; + my ($v, $c) = split m/[=]/, $data; + + if ($v eq 'url') { + $dll = $c; + } + elsif ($v eq 'version') { + if (Auto::VER.q{.}.Auto::SVER.q{.}.Auto::REV.Auto::RSTAGE ne $c) { + println('!!! NOTICE !!! Your copy of Auto is outdated. Current version: '.Auto::VER.q{.}.Auto::SVER.q{.}.Auto::REV.Auto::RSTAGE.' - Latest version: '.$c); + println('!!! NOTICE !!! You can get the latest Auto by downloading '.$dll); + } + else { + println('* Auto is up-to-date.'); + } + } + } + } +}