#!/usr/bin/env perl # 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. use strict; use warnings; use English qw(-no_match_vars); use FindBin qw($Bin); our $Bin = $Bin; # Installation script. our $VERSION = 1.00; sub println { my ($out) = @_; if (!defined $out) { return; } print $out.$/; return 1; } sub ver { my @vs = split('\.', $]); my %ver = (); $ver{ver} = $vs[0]; $ver{sub} = substr($vs[1], 1, 2); $ver{rev} = substr($vs[1], 3, 3); return %ver; } sub modfind { my ($mod) = @_; print "Checking for $mod..... "; eval('require '.$mod.'; 1;') and println "OK" or println "Not Found" and exit; return 1; } # Check operating system. print "Checking operating system..... $OSNAME - "; if ($OSNAME =~ /dos/i) { print "DOS is not supported.\r\n"; } elsif ($OSNAME eq "MSWin32") { print "Microsoft Windows is not supported. Support is planned for the future.\r\n"; } elsif ($OSNAME eq "NetWare") { print "NetWare is not supported.\r\n"; } elsif ($OSNAME eq "linux") { print "OK\n"; } elsif ($OSNAME eq "os2") { print "IBM OS/2 is not supported.\r\n"; } elsif ($OSNAME =~ /mac/i or $OSNAME =~ /darwin/i) { print "OK\r"; } elsif ($OSNAME eq "freebsd") { print "OK\n"; } elsif ($OSNAME eq "openbsd") { print "OK\n"; } else { print "Unknown operating system. Contact support.\r\n"; } # Check Perl version. my %VER = ver(); print "Checking Perl version..... $VER{ver}.$VER{sub}.$VER{rev} - "; if ($VER{ver} >= 5 and $VER{sub} >= 10) { println "OK"; } else { println "Incompatible"; exit; } # Check for required CPAN modules. println "\0"; println "--- CPAN Modules ---"; modfind("Mouse"); modfind("Async"); modfind("Class::Unload"); # Create build. println "\0"; println "Building....."; if (!-d "$Bin/build") { system("mkdir $Bin/build"); } if (!-e "$Bin/build/time") { system("touch $Bin/build/time"); } if (!-e "$Bin/build/os") { system("touch $Bin/build/os"); } if (!-e "$Bin/build/perl") { system("touch $Bin/build/perl"); } if (!-e "$Bin/build/ver") { system("touch $Bin/build/ver"); } open(my $FTIME, q{>}, "$Bin/build/time") or println "Failed to install." and exit; print $FTIME time."\n" or println "Failed to install." and exit; close $FTIME or println "Failed to install." and exit; open(my $FOS, q{>}, "$Bin/build/os") or println "Failed to install." and exit; print $FOS $OSNAME."\n" or println "Failed to install." and exit; close $FOS or println "Failed to install." and exit; open(my $FPERL, q{>}, "$Bin/build/perl") or println "Failed to install." and exit; print $FPERL "$]\n" or println "Failed to install." and exit; close $FPERL or println "Failed to install." and exit; open(my $FVER, q{>}, "$Bin/build/ver") or println "Failed to install." and exit; print $FVER "3.0.0d\n" or println "Failed to install." and exit; close $FVER or println "Failed to install." and exit; # Success! println "Done. Auto successfully installed.";