Subversion Repositories camp_sysinfo_client_3

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 rodolico 1
#! /usr/bin/perl -w
2
 
3
my %installationTypes = (
4
                           'ipfire' => {
5
                               'post process' => \&ipfire
6
                            }
7
                      );
8
 
9
my %installation = (
10
                     '1. Configuration Directory' => '/etc/camp',
11
                     '2. Modules Directory' => 'modules',
12
                     '3. Scripts Directory' => 'scripts',
13
                     '4. Executable Directory' => '/usr/bin'
14
                   );
15
 
16
my %configuration;
17
 
18
my %packageActions = (
19
                  'modules' => {
20
                     'type'       => 'directory',
21
                     'target'     => '2. Modules Directory',
22
                     'owner'      => 'root:root',
23
                     'dir perms'  => '0755',
24
                     'file perms' => '0755'
25
                  },
26
                  'scripts' => {
27
                     'type'       => 'directory',
28
                     'target'     => '3. Scripts Directory',
29
                     'owner'      => 'root:root',
30
                     'dir perms'  => '0755',
31
                     'file perms' => '0755'
32
                  },
33
                  'notes' => {
34
                     'type'       => 'file',
35
                     'target'     => '1. Configuration Directory',
36
                     'owner'      => 'root:root',
37
                     'dir perms'  => '0755',
38
                     'file perms' => '0644'
39
                  },
40
                  'sysinfo' => {
41
                     'type'       => 'file',
42
                     'target'     => '4. Executable Directory',
43
                     'owner'      => 'root:root',
44
                     'dir perms'  => '0755',
45
                     'file perms' => '0755'
46
                  },
47
                  'sysinfo.conf.template' => {
48
                     'type'       => 'file',
49
                     'target'     => '1. Configuration Directory',
50
                     'owner'      => 'root:root',
51
                     'dir perms'  => '0755',
52
                     'file perms' => '0644'
53
                  }
54
               );
55
my $installationType;
56
my $cronLocation; 
57
 
58
 
59
sub getInstallationType {
60
   my @OSTypes = ( 'ipfire','debian' );
61
   my $OS = `uname -a`;
62
   foreach $osType ( @OSTypes ) {
63
      return $osType if $OS =~ m/$osType/i;
64
   }
65
   return '';
66
} # getInstallationType
67
 
68
sub findCron {
69
   while ( $location = shift ) {
70
      return $location if -d $location;
71
   }
72
   return '';
73
}
74
 
75
sub customizeInstall {
76
   my ( $installation, $cronLocation ) = @_;
77
   # Allow user to customize the installation paths
78
   foreach my $answer ( sort keys %$installation ) {
79
      if ( $answer eq '2. Modules Directory' or $answer eq '3. Scripts Directory' ) {
80
         $$installation{$answer} = $$installation{'1. Configuration Directory'} . '/' . $$installation{$answer};
81
      }
82
      print "$answer [$$installation{$answer}]: ";
83
      my $temp = <>;
84
      chomp $temp;
85
      $$installation{$answer} = $temp if $temp;
86
   }
87
   print "Link executable into which location [$$cronLocation]: ";
88
   my $temp = <>;
89
   chomp $temp;
90
   $$cronLocation = $temp if $temp;
91
}   
92
 
93
sub makeDirectory {
94
   my ( $directory, $owner, $permissions ) = @_;
95
   return 1 if -d $directory;
96
   use File::Path qw ( make_path );
97
   make_path( $directory, { mode => $permissions, owner=>$owner } );
98
   `mkdir -p $directory`;
99
   `chown $owner $directory`;
100
   `chmod $permissions $directory`;
101
   return -d $directory;
102
}
103
 
104
sub doInstall {
105
   my ( $installation, $cronLocation, $packageActions ) = @_;
106
   foreach my $item ( keys %$packageActions ) {
107
      if &makeDirectory( $$installation{$$packageActions{$item}{'target'}}, $$packageActions{$item}{'owner'}, $$packageActions{$item}{'dir perms'} );
108
      if ( $$installation{$item}{'type'} eq 'file' ) {
109
 
110
}
111
 
112
sub readConfiguration {
113
   my ( $configuration,$confFileName ) = @_;
114
}   
115
 
116
sub ipFire {
117
   my @BACKUP_DIRS = ('/opt/sysinfo', '/etc/sysinfo');
118
   my @INSTALL_COMMANDS = (
119
              'cp -av opt /',
120
              'cp -av etc /',
121
              'ln -s /opt/sysinfo/sysinfo /etc/fcron.daily/sysinfo.cron'
122
              );
123
   # now, check for backup directories not in include.user
124
   open BACKUP, '</var/ipfire/backup/include.user';
125
   while ( $line = <BACKUP> ) {
126
      chomp $line;
127
      for (my $i = 0; $i < @BACKUP_DIRS; $i++ ) {
128
         if ( $BACKUP_DIRS[$i] eq $line ) {
129
            $BACKUP_DIRS[$i] = '';
130
            last;
131
         } # if
132
      }# for
133
   } # while
134
   close BACKUP;
135
 
136
   # if any remain, append them to include.user
137
   open BACKUP, '>>/var/ipfire/backup/include.user';
138
   foreach my $backupDir ( @BACKUP_DIRS ) {
139
      print BACKUP "$backupDir\n" if $backupDir;
140
   }
141
   close BACKUP;
142
 
143
   # set all modules with ipfire in the name to run
144
   opendir $moduleDir, $MODULES_DIR;
145
   my @modules = grep { /ipfire/ } readdir $moduleDir;
146
   closedir $moduleDir;
147
   foreach my $module (@modules) {
148
      `chmod 755 $MODULES_DIR/$module`;
149
   }
150
}
151
 
152
#####################################################################
153
# Main Program
154
#####################################################################
155
 
156
# if installationType or cronLocation not set, find them
157
$installationType = &getInstallationType() unless $installationType;
158
$cronLocation = &findCron( '/etc/cron.daily', '/etc/fcron.daily' ) unless $cronLocation;
159
# allow use to change installation paths
160
&customizeInstall( \%installation,\$cronLocation, \%packageActions );
161
 
162
print "Script will be run from: $cronLocation\n";
163
print "The operaitng system is: $installationType\n";
164
foreach my $answer ( sort keys %installation ) {
165
   print "$answer = $installation{$answer}\n";
166
}
167
print 'Continue? [Y/n]: ';
168
$answer = <>;
169
chomp $answer;
170
$answer = $answer ? uc $answer : 'Y';
171
exit unless $answer eq 'Y';
172
print "Continuing the installation\n";
173
 
174
&doInstall( \%installation, $cronLocation );
175
 
176
1;