Subversion Repositories camp_sysinfo_client_3

Rev

Rev 8 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8 Rev 9
Line 1... Line 1...
1
#! /usr/bin/perl -w
1
#! /usr/bin/perl -w
2
 
2
 
-
 
3
my $TESTING = 1;
-
 
4
 
3
my %installationTypes = (
5
my %installationTypes = (
4
                           'ipfire' => {
6
                           'ipfire' => {
5
                               'post process' => \&ipfire
7
                               'post process' => \&ipfire
6
                            }
8
                            }
7
                      );
9
                      );
Line 35... Line 37...
35
                     'target'     => '1. Configuration Directory',
37
                     'target'     => '1. Configuration Directory',
36
                     'owner'      => 'root:root',
38
                     'owner'      => 'root:root',
37
                     'dir perms'  => '0755',
39
                     'dir perms'  => '0755',
38
                     'file perms' => '0644'
40
                     'file perms' => '0644'
39
                  },
41
                  },
40
                  'sysinfo' => {
42
                  'sysinfo_client' => {
41
                     'type'       => 'file',
43
                     'type'       => 'file',
42
                     'target'     => '4. Executable Directory',
44
                     'target'     => '4. Executable Directory',
43
                     'owner'      => 'root:root',
45
                     'owner'      => 'root:root',
44
                     'dir perms'  => '0755',
46
                     'dir perms'  => '0755',
45
                     'file perms' => '0755'
47
                     'file perms' => '0755',
-
 
48
                     'cron'       => 1
46
                  },
49
                  },
47
                  'sysinfo.conf.template' => {
50
                  'sysinfo.conf.template' => {
48
                     'type'       => 'file',
51
                     'type'       => 'file',
49
                     'target'     => '1. Configuration Directory',
52
                     'target'     => '1. Configuration Directory',
50
                     'owner'      => 'root:root',
53
                     'owner'      => 'root:root',
Line 90... Line 93...
90
   $$cronLocation = $temp if $temp;
93
   $$cronLocation = $temp if $temp;
91
}   
94
}   
92
 
95
 
93
sub makeDirectory {
96
sub makeDirectory {
94
   my ( $directory, $owner, $permissions ) = @_;
97
   my ( $directory, $owner, $permissions ) = @_;
95
   return 1 if -d $directory;
98
   return if -d $directory;
-
 
99
   # make_path is very good and efficient, if File is installed, so we try it
96
   use File::Path qw ( make_path );
100
   eval { use File::Path 'make_path'; };
-
 
101
   if ( $@ ) {
-
 
102
      if ( $TESTING ) {
-
 
103
         print "Using OS to create $directory\n";
-
 
104
         print "mkdir -p $directory\n";
-
 
105
         print "chown $owner $directory\n";
97
   make_path( $directory, { mode => $permissions, owner=>$owner } );
106
         print "chmod $permissions $directory\n";
-
 
107
         return;
-
 
108
      }
98
   `mkdir -p $directory`;
109
      `mkdir -p $directory`;
99
   `chown $owner $directory`;
110
      `chown $owner $directory`;
100
   `chmod $permissions $directory`;
111
      `chmod $permissions $directory`;
-
 
112
      die "Could not create directory [$directory]\n" unless -d $directory;
-
 
113
   } else { # we could not load library, so do it via the OS
-
 
114
      if ( $TESTING ) {
-
 
115
         print "Using make_path to create $directory\n";
-
 
116
         print "make_path( $directory, { mode => $permissions, owner=>$owner, error => my $err } )\n";
101
   return -d $directory;
117
         return;
-
 
118
      }
-
 
119
      make_path( $directory, { mode => $permissions, owner=>$owner, error => \my $err } );
-
 
120
      die "Could not create directory [$directory]\n" if @$err;
-
 
121
   }
102
}
122
}
103
 
123
 
104
sub doInstall {
124
sub doInstall {
105
   my ( $installation, $cronLocation, $packageActions ) = @_;
125
   my ( $installation, $cronLocation, $packageActions ) = @_;
106
   foreach my $item ( keys %$packageActions ) {
126
   foreach my $item ( keys %$packageActions ) {
-
 
127
      &makeDirectory( 
-
 
128
         $$installation{$$packageActions{$item}{'target'}}, 
-
 
129
         $$packageActions{$item}{'owner'}, 
-
 
130
         $$packageActions{$item}{'dir perms'} 
-
 
131
         );
107
      if &makeDirectory( $$installation{$$packageActions{$item}{'target'}}, $$packageActions{$item}{'owner'}, $$packageActions{$item}{'dir perms'} );
132
      my $targetDir = $$installation{$$packageActions{$item}{'target'}};
-
 
133
      my $perms = $$packageActions{$item}{'file perms'};
-
 
134
      my $owner = $$packageActions{$item}{'owner'};
-
 
135
      $item .= '/*' if  $$packageActions{$item}{'type'} eq 'directory';
-
 
136
      if ( $TESTING ) {
-
 
137
         print "mv $item $targetDir\n";
-
 
138
         print "chmod $perms \"$targetDir/$item\"\n";
-
 
139
         print "chown $owner \"$targetDir/$item\"\n";
-
 
140
         # is this one supposed to be run as cron?
108
      if ( $$installation{$item}{'type'} eq 'file' ) {
141
         if ( $$packageActions{$item}{'cron'} && $cronLocation ) {
-
 
142
            print "ln -s \"$targetDir/$item\" \"$cronLocation/$item\"\n";
-
 
143
         }
-
 
144
      } else {
-
 
145
         `mv $item $targetDir`;
-
 
146
         `chmod $perms "$targetDir/$item"`;
-
 
147
         `chown $owner "$targetDir/$item"`;
-
 
148
         # is this one supposed to be run as cron?
-
 
149
         if ( $$packageActions{$item}{'cron'} && $cronLocation ) {
-
 
150
            `ln -s "$targetDir/$item" "$cronLocation/$item"`;
109
         
151
         }
-
 
152
      }
-
 
153
   } # foreach
110
}
154
}
111
 
155
 
112
sub readConfiguration {
156
sub readConfiguration {
113
   my ( $configuration,$confFileName ) = @_;
157
   my ( $configuration,$confFileName ) = @_;
114
}   
158
}   
Line 169... Line 213...
169
chomp $answer;
213
chomp $answer;
170
$answer = $answer ? uc $answer : 'Y';
214
$answer = $answer ? uc $answer : 'Y';
171
exit unless $answer eq 'Y';
215
exit unless $answer eq 'Y';
172
print "Continuing the installation\n";
216
print "Continuing the installation\n";
173
 
217
 
174
&doInstall( \%installation, $cronLocation );
218
&doInstall( \%installation, $cronLocation, \%packageActions );
175
 
219
 
176
1;
220
1;