PAC Manager Code
Brought to you by:
perseo22
#!/usr/bin/perl
###################################################################
# This file is part of PAC( Perl Auto Connector)
#
# Copyright (C) 2010 David Torrejon Vaquerizas
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###################################################################
$|++;
###################################################################
# START: Import Modules
BEGIN
{
use FindBin qw ( $RealBin $Bin $Script );
push( @INC, $RealBin . '/lib' );
}
# Standard
use strict;
use warnings;
use File::Copy;
# PAC modules
use PACMain;
# END: Import Modules
###################################################################
###################################################################
# START: Define GLOBAL variables
my $INIT_CFG_FILE = $RealBin . '/res/pac.yml';
my $CFG_DIR = $ENV{'HOME'} . '/.pac';
my $CFG_FILE = $CFG_DIR . '/pac.yml';
my $OLD_CFG_FILE = $ENV{'HOME'} . '/.pac.yml';
my $PAC;
# END: Define GLOBAL variables
###################################################################
###################################################################
# START: MAIN program
# Check for command line options
my $opt = shift // '';
# Check for the existance of the config directory
-d $CFG_DIR or mkdir( $CFG_DIR );
-d $CFG_DIR . '/screenshots' or mkdir( $CFG_DIR . '/screenshots' );
-d $CFG_DIR . '/session_logs' or mkdir( $CFG_DIR . '/session_logs' );
# Check for the existance of the config file
if ( ! -f $CFG_FILE )
{
print STDERR "Could not find config file '$CFG_FILE'.";
if ( ! -f $OLD_CFG_FILE )
{
print STDERR "This is our first time running! ;)";
copy( $INIT_CFG_FILE, $CFG_FILE ) or die "ERROR: Could not copy init cfg file '$INIT_CFG_FILE' to '$CFG_FILE': $!";
}
else
{
rename( $OLD_CFG_FILE, $CFG_FILE ) or die "ERROR: Could not move old cfg file '$OLD_CFG_FILE' to '$CFG_FILE': $!";
}
}
if ( ! ( $PAC = PACMain -> new ) )
{
print STDERR "PAC not starting. PAC already running?\n";
exit 0
}
else
{
$PAC -> start( $opt );
}
print "Exiting $Script...\n";
exit 0;
# END: MAIN program
###################################################################