| Line 45... |
Line 45... |
| 45 |
'owner' => 'root:root',
|
45 |
'owner' => 'root:root',
|
| 46 |
'dir perms' => '0755',
|
46 |
'dir perms' => '0755',
|
| 47 |
'file perms' => '0755',
|
47 |
'file perms' => '0755',
|
| 48 |
'cron' => 1
|
48 |
'cron' => 1
|
| 49 |
},
|
49 |
},
|
| - |
|
50 |
'install.pl' => {
|
| - |
|
51 |
'type' => 'file',
|
| - |
|
52 |
'target' => '1. Configuration Directory',
|
| - |
|
53 |
'owner' => 'root:root',
|
| - |
|
54 |
'dir perms' => '0755',
|
| - |
|
55 |
'file perms' => '0755',
|
| - |
|
56 |
'cron' => 1
|
| - |
|
57 |
},
|
| 50 |
'sysinfo.conf.template' => {
|
58 |
'sysinfo.conf.template' => {
|
| 51 |
'type' => 'file',
|
59 |
'type' => 'file',
|
| 52 |
'target' => '1. Configuration Directory',
|
60 |
'target' => '1. Configuration Directory',
|
| 53 |
'owner' => 'root:root',
|
61 |
'owner' => 'root:root',
|
| 54 |
'dir perms' => '0755',
|
62 |
'dir perms' => '0755',
|
| 55 |
'file perms' => '0644'
|
63 |
'file perms' => '0644'
|
| 56 |
}
|
64 |
}
|
| 57 |
);
|
65 |
);
|
| 58 |
my $installationType;
|
66 |
my $installationType;
|
| 59 |
my $cronLocation;
|
67 |
my $cronLocation;
|
| - |
|
68 |
my $installMode;
|
| - |
|
69 |
|
| - |
|
70 |
# prompt the user for a response, then allow them to enter it
|
| - |
|
71 |
# the first response is considered the default and is printed
|
| - |
|
72 |
# in all caps if more than one exists
|
| - |
|
73 |
# first answer is used if they simply press the Enter
|
| - |
|
74 |
# key. The response is returned all lower case if more than one
|
| - |
|
75 |
# exists.
|
| - |
|
76 |
# it is assumed
|
| - |
|
77 |
sub getAnswer {
|
| - |
|
78 |
my ( $prompt, @answers ) = @_;
|
| - |
|
79 |
my $onlyOneAnswer = scalar( @answers ) == 1;
|
| - |
|
80 |
print $prompt . '[';
|
| - |
|
81 |
$answers[0] = uc $answers[0] unless $onlyOneAnswer;
|
| - |
|
82 |
print join( '/', @answers ) . ']: ';
|
| - |
|
83 |
$thisAnswer = <>;
|
| - |
|
84 |
chomp $thisAnswer;
|
| - |
|
85 |
$thisAnswer = $answers[0] unless $thisAnswer;
|
| - |
|
86 |
return $onlyOneAnswer ? lc $thisAnswer : $thisAnswer;
|
| - |
|
87 |
}
|
| 60 |
|
88 |
|
| - |
|
89 |
sub checkInstall {
|
| - |
|
90 |
my $installed = `which sysinfo-client`;
|
| - |
|
91 |
my $action;
|
| - |
|
92 |
chomp $installed;
|
| - |
|
93 |
my $oldconf = (-f '/etc/sysinfo/sysinfo.conf' ) ? '/etc/sysinfo/sysinfo.conf' : '';
|
| - |
|
94 |
if ( $installed ) {
|
| - |
|
95 |
$action = &getAnswer( 'Application appears to already be installed\nWhat do you want to do', ('configure','remove') );
|
| - |
|
96 |
} else {
|
| - |
|
97 |
my $useOldConf = &getAnswer( 'Doing a fresh install, and old sysinfo configuration exists, use it for defaults?',('y','n') ) if $oldconf;
|
| - |
|
98 |
$action = 'install';
|
| - |
|
99 |
$action .= ':' . $oldconf if $useOldConf eq 'y';
|
| - |
|
100 |
}
|
| - |
|
101 |
return $action;
|
| - |
|
102 |
}
|
| 61 |
|
103 |
|
| - |
|
104 |
# simply attempts to detect the operating system so we can do OS
|
| - |
|
105 |
# specific actions at the end.
|
| 62 |
sub getInstallationType {
|
106 |
sub getOperatingSystem {
|
| 63 |
my @OSTypes = ( 'ipfire','debian' );
|
107 |
my @OSTypes = ( 'ipfire','debian' );
|
| 64 |
my $OS = `uname -a`;
|
108 |
my $OS = `uname -a`;
|
| 65 |
foreach $osType ( @OSTypes ) {
|
109 |
foreach $osType ( @OSTypes ) {
|
| 66 |
return $osType if $OS =~ m/$osType/i;
|
110 |
return $osType if $OS =~ m/$osType/i;
|
| 67 |
}
|
111 |
}
|
| 68 |
return '';
|
112 |
return '';
|
| 69 |
} # getInstallationType
|
113 |
} # getOperatingSystem
|
| 70 |
|
114 |
|
| - |
|
115 |
# see if we can find a cron of some kind that will run the process
|
| - |
|
116 |
# daily
|
| 71 |
sub findCron {
|
117 |
sub findCron {
|
| 72 |
while ( $location = shift ) {
|
118 |
while ( $location = shift ) {
|
| 73 |
return $location if -d $location;
|
119 |
return $location if -d $location;
|
| 74 |
}
|
120 |
}
|
| 75 |
return '';
|
121 |
return '';
|
| Line 80... |
Line 126... |
| 80 |
# Allow user to customize the installation paths
|
126 |
# Allow user to customize the installation paths
|
| 81 |
foreach my $answer ( sort keys %$installation ) {
|
127 |
foreach my $answer ( sort keys %$installation ) {
|
| 82 |
if ( $answer eq '2. Modules Directory' or $answer eq '3. Scripts Directory' ) {
|
128 |
if ( $answer eq '2. Modules Directory' or $answer eq '3. Scripts Directory' ) {
|
| 83 |
$$installation{$answer} = $$installation{'1. Configuration Directory'} . '/' . $$installation{$answer};
|
129 |
$$installation{$answer} = $$installation{'1. Configuration Directory'} . '/' . $$installation{$answer};
|
| 84 |
}
|
130 |
}
|
| 85 |
print "$answer [$$installation{$answer}]: ";
|
131 |
$$installation{$answer} = &getAnswer( $answer, ( $$installation{$answer} ) );
|
| 86 |
my $temp = <>;
|
- |
|
| 87 |
chomp $temp;
|
- |
|
| 88 |
$$installation{$answer} = $temp if $temp;
|
- |
|
| 89 |
}
|
132 |
}
|
| 90 |
print "Link executable into which location [$$cronLocation]: ";
|
133 |
$$cronLocation = &getAnswer( 'Link executable into which location', ( $$cronLocation ) );
|
| 91 |
my $temp = <>;
|
- |
|
| 92 |
chomp $temp;
|
- |
|
| 93 |
$$cronLocation = $temp if $temp;
|
- |
|
| 94 |
}
|
134 |
}
|
| 95 |
|
135 |
|
| 96 |
sub makeDirectory {
|
136 |
sub makeDirectory {
|
| 97 |
my ( $directory, $owner, $permissions ) = @_;
|
137 |
my ( $directory, $owner, $permissions ) = @_;
|
| 98 |
return if -d $directory;
|
138 |
return if -d $directory;
|
| Line 111... |
Line 151... |
| 111 |
`chmod $permissions $directory`;
|
151 |
`chmod $permissions $directory`;
|
| 112 |
die "Could not create directory [$directory]\n" unless -d $directory;
|
152 |
die "Could not create directory [$directory]\n" unless -d $directory;
|
| 113 |
} else { # we could not load library, so do it via the OS
|
153 |
} else { # we could not load library, so do it via the OS
|
| 114 |
if ( $TESTING ) {
|
154 |
if ( $TESTING ) {
|
| 115 |
print "Using make_path to create $directory\n";
|
155 |
print "Using make_path to create $directory\n";
|
| 116 |
print "make_path( $directory, { mode => $permissions, owner=>$owner, error => my $err } )\n";
|
156 |
print "make_path( $directory, { mode => $permissions, owner=>$owner } )\n";
|
| 117 |
return;
|
157 |
return;
|
| 118 |
}
|
158 |
}
|
| 119 |
make_path( $directory, { mode => $permissions, owner=>$owner, error => \my $err } );
|
159 |
make_path( $directory, { mode => $permissions, owner=>$owner, error => \my $err } );
|
| 120 |
die "Could not create directory [$directory]\n" if @$err;
|
160 |
die "Could not create directory [$directory]\n" if @$err;
|
| 121 |
}
|
161 |
}
|
| Line 195... |
Line 235... |
| 195 |
|
235 |
|
| 196 |
#####################################################################
|
236 |
#####################################################################
|
| 197 |
# Main Program
|
237 |
# Main Program
|
| 198 |
#####################################################################
|
238 |
#####################################################################
|
| 199 |
|
239 |
|
| - |
|
240 |
$installMode = &checkInstall();
|
| 200 |
# if installationType or cronLocation not set, find them
|
241 |
# if installationType or cronLocation not set, find them
|
| 201 |
$installationType = &getInstallationType() unless $installationType;
|
242 |
$installationType = &getOperatingSystem() unless $installationType;
|
| 202 |
$cronLocation = &findCron( '/etc/cron.daily', '/etc/fcron.daily' ) unless $cronLocation;
|
243 |
$cronLocation = &findCron( '/etc/cron.daily', '/etc/fcron.daily' ) unless $cronLocation;
|
| 203 |
# allow use to change installation paths
|
244 |
# allow use to change installation paths
|
| 204 |
&customizeInstall( \%installation,\$cronLocation, \%packageActions );
|
245 |
&customizeInstall( \%installation,\$cronLocation, \%packageActions );
|
| 205 |
|
246 |
|
| - |
|
247 |
print "Install mode is: $installMode\n";
|
| 206 |
print "Script will be run from: $cronLocation\n";
|
248 |
print "Cron job will be run from: $cronLocation\n";
|
| 207 |
print "The operaitng system is: $installationType\n";
|
249 |
print "The operaitng system is: $installationType\n";
|
| 208 |
foreach my $answer ( sort keys %installation ) {
|
250 |
foreach my $answer ( sort keys %installation ) {
|
| 209 |
print "$answer = $installation{$answer}\n";
|
251 |
print "$answer = $installation{$answer}\n";
|
| 210 |
}
|
252 |
}
|
| 211 |
print 'Continue? [Y/n]: ';
|
253 |
print 'Continue? [Y/n]: ';
|