Blame | Last modification | View Log | RSS feed
#! /usr/bin/perl -w
my %installationTypes = (
'ipfire' => {
'post process' => \&ipfire
}
);
my %installation = (
'1. Configuration Directory' => '/etc/camp',
'2. Modules Directory' => 'modules',
'3. Scripts Directory' => 'scripts',
'4. Executable Directory' => '/usr/bin'
);
my %configuration;
my %packageActions = (
'modules' => {
'type' => 'directory',
'target' => '2. Modules Directory',
'owner' => 'root:root',
'dir perms' => '0755',
'file perms' => '0755'
},
'scripts' => {
'type' => 'directory',
'target' => '3. Scripts Directory',
'owner' => 'root:root',
'dir perms' => '0755',
'file perms' => '0755'
},
'notes' => {
'type' => 'file',
'target' => '1. Configuration Directory',
'owner' => 'root:root',
'dir perms' => '0755',
'file perms' => '0644'
},
'sysinfo' => {
'type' => 'file',
'target' => '4. Executable Directory',
'owner' => 'root:root',
'dir perms' => '0755',
'file perms' => '0755'
},
'sysinfo.conf.template' => {
'type' => 'file',
'target' => '1. Configuration Directory',
'owner' => 'root:root',
'dir perms' => '0755',
'file perms' => '0644'
}
);
my $installationType;
my $cronLocation;
sub getInstallationType {
my @OSTypes = ( 'ipfire','debian' );
my $OS = `uname -a`;
foreach $osType ( @OSTypes ) {
return $osType if $OS =~ m/$osType/i;
}
return '';
} # getInstallationType
sub findCron {
while ( $location = shift ) {
return $location if -d $location;
}
return '';
}
sub customizeInstall {
my ( $installation, $cronLocation ) = @_;
# Allow user to customize the installation paths
foreach my $answer ( sort keys %$installation ) {
if ( $answer eq '2. Modules Directory' or $answer eq '3. Scripts Directory' ) {
$$installation{$answer} = $$installation{'1. Configuration Directory'} . '/' . $$installation{$answer};
}
print "$answer [$$installation{$answer}]: ";
my $temp = <>;
chomp $temp;
$$installation{$answer} = $temp if $temp;
}
print "Link executable into which location [$$cronLocation]: ";
my $temp = <>;
chomp $temp;
$$cronLocation = $temp if $temp;
}
sub makeDirectory {
my ( $directory, $owner, $permissions ) = @_;
return 1 if -d $directory;
use File::Path qw ( make_path );
make_path( $directory, { mode => $permissions, owner=>$owner } );
`mkdir -p $directory`;
`chown $owner $directory`;
`chmod $permissions $directory`;
return -d $directory;
}
sub doInstall {
my ( $installation, $cronLocation, $packageActions ) = @_;
foreach my $item ( keys %$packageActions ) {
if &makeDirectory( $$installation{$$packageActions{$item}{'target'}}, $$packageActions{$item}{'owner'}, $$packageActions{$item}{'dir perms'} );
if ( $$installation{$item}{'type'} eq 'file' ) {
}
sub readConfiguration {
my ( $configuration,$confFileName ) = @_;
}
sub ipFire {
my @BACKUP_DIRS = ('/opt/sysinfo', '/etc/sysinfo');
my @INSTALL_COMMANDS = (
'cp -av opt /',
'cp -av etc /',
'ln -s /opt/sysinfo/sysinfo /etc/fcron.daily/sysinfo.cron'
);
# now, check for backup directories not in include.user
open BACKUP, '</var/ipfire/backup/include.user';
while ( $line = <BACKUP> ) {
chomp $line;
for (my $i = 0; $i < @BACKUP_DIRS; $i++ ) {
if ( $BACKUP_DIRS[$i] eq $line ) {
$BACKUP_DIRS[$i] = '';
last;
} # if
}# for
} # while
close BACKUP;
# if any remain, append them to include.user
open BACKUP, '>>/var/ipfire/backup/include.user';
foreach my $backupDir ( @BACKUP_DIRS ) {
print BACKUP "$backupDir\n" if $backupDir;
}
close BACKUP;
# set all modules with ipfire in the name to run
opendir $moduleDir, $MODULES_DIR;
my @modules = grep { /ipfire/ } readdir $moduleDir;
closedir $moduleDir;
foreach my $module (@modules) {
`chmod 755 $MODULES_DIR/$module`;
}
}
#####################################################################
# Main Program
#####################################################################
# if installationType or cronLocation not set, find them
$installationType = &getInstallationType() unless $installationType;
$cronLocation = &findCron( '/etc/cron.daily', '/etc/fcron.daily' ) unless $cronLocation;
# allow use to change installation paths
&customizeInstall( \%installation,\$cronLocation, \%packageActions );
print "Script will be run from: $cronLocation\n";
print "The operaitng system is: $installationType\n";
foreach my $answer ( sort keys %installation ) {
print "$answer = $installation{$answer}\n";
}
print 'Continue? [Y/n]: ';
$answer = <>;
chomp $answer;
$answer = $answer ? uc $answer : 'Y';
exit unless $answer eq 'Y';
print "Continuing the installation\n";
&doInstall( \%installation, $cronLocation );
1;