#!/usr/bin/env perl

use warnings;
use strict;  

our $VERSION = '1.0';

# special purpose for IPFire routers. NOT a stand alone, used as
# a part of install.pl
sub systemSpecificInstall {
   
   if ( -d '/opt/sysinfo'
      && &yesno ('It looks like sysinfo version 2 is installed, should I remove it' ) ) {
      if ( &yesno( 'Back up old configuration? ') ) {
         `tar -czvf /root/sysinfo.2.config.tgz /etc/sysinfo`;
         print "Old configuration copied to /root/sysinfo.2.config.tgz\n";
      }
      `rm -fR /opt/sysinfo`;
      `rm -f /etc/fcron.daily/sysinfo.cron`;
      `cp -av /var/ipfire/backup/include.user /var/ipfire/backup/include.user.bak`;
      `grep -v sysinfo /var/ipfire/backup/include.user.bak > /var/ipfire/backup/include.user`;
   }
   
   
   my @BACKUP_DIRS = ( '/etc/camp' );
   `ln -s /opt/camp/sysinfo-client/sysinfo-client /etc/fcron.daily/sysinfo.cron`
      if &yesno( 'Add link to fcron.daily' );
   # 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 or unix in the name to run
   my $moduleDir = $moduleDirs[0];
   opendir $moduleDir, $moduleDir;
   my @modules = grep { /^((ipfire)|(unix))/ } readdir $moduleDir;
   closedir $moduleDir;
   foreach my $module ( @modules) {
      `chmod 0700 $moduleDir/$module`;
   }
   print "All IPFire specific modules have been enabled\n";
}

1;
