8 |
rodolico |
1 |
#! /usr/bin/perl -w
|
|
|
2 |
|
9 |
rodolico |
3 |
my $TESTING = 1;
|
|
|
4 |
|
8 |
rodolico |
5 |
my %installationTypes = (
|
|
|
6 |
'ipfire' => {
|
|
|
7 |
'post process' => \&ipfire
|
|
|
8 |
}
|
|
|
9 |
);
|
|
|
10 |
|
|
|
11 |
my %installation = (
|
|
|
12 |
'1. Configuration Directory' => '/etc/camp',
|
|
|
13 |
'2. Modules Directory' => 'modules',
|
|
|
14 |
'3. Scripts Directory' => 'scripts',
|
|
|
15 |
'4. Executable Directory' => '/usr/bin'
|
|
|
16 |
);
|
|
|
17 |
|
|
|
18 |
my %configuration;
|
|
|
19 |
|
|
|
20 |
my %packageActions = (
|
|
|
21 |
'modules' => {
|
|
|
22 |
'type' => 'directory',
|
|
|
23 |
'target' => '2. Modules Directory',
|
|
|
24 |
'owner' => 'root:root',
|
|
|
25 |
'dir perms' => '0755',
|
|
|
26 |
'file perms' => '0755'
|
|
|
27 |
},
|
|
|
28 |
'scripts' => {
|
|
|
29 |
'type' => 'directory',
|
|
|
30 |
'target' => '3. Scripts Directory',
|
|
|
31 |
'owner' => 'root:root',
|
|
|
32 |
'dir perms' => '0755',
|
|
|
33 |
'file perms' => '0755'
|
|
|
34 |
},
|
|
|
35 |
'notes' => {
|
|
|
36 |
'type' => 'file',
|
|
|
37 |
'target' => '1. Configuration Directory',
|
|
|
38 |
'owner' => 'root:root',
|
|
|
39 |
'dir perms' => '0755',
|
|
|
40 |
'file perms' => '0644'
|
|
|
41 |
},
|
9 |
rodolico |
42 |
'sysinfo_client' => {
|
8 |
rodolico |
43 |
'type' => 'file',
|
|
|
44 |
'target' => '4. Executable Directory',
|
|
|
45 |
'owner' => 'root:root',
|
|
|
46 |
'dir perms' => '0755',
|
9 |
rodolico |
47 |
'file perms' => '0755',
|
|
|
48 |
'cron' => 1
|
8 |
rodolico |
49 |
},
|
|
|
50 |
'sysinfo.conf.template' => {
|
|
|
51 |
'type' => 'file',
|
|
|
52 |
'target' => '1. Configuration Directory',
|
|
|
53 |
'owner' => 'root:root',
|
|
|
54 |
'dir perms' => '0755',
|
|
|
55 |
'file perms' => '0644'
|
|
|
56 |
}
|
|
|
57 |
);
|
|
|
58 |
my $installationType;
|
|
|
59 |
my $cronLocation;
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
sub getInstallationType {
|
|
|
63 |
my @OSTypes = ( 'ipfire','debian' );
|
|
|
64 |
my $OS = `uname -a`;
|
|
|
65 |
foreach $osType ( @OSTypes ) {
|
|
|
66 |
return $osType if $OS =~ m/$osType/i;
|
|
|
67 |
}
|
|
|
68 |
return '';
|
|
|
69 |
} # getInstallationType
|
|
|
70 |
|
|
|
71 |
sub findCron {
|
|
|
72 |
while ( $location = shift ) {
|
|
|
73 |
return $location if -d $location;
|
|
|
74 |
}
|
|
|
75 |
return '';
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
sub customizeInstall {
|
|
|
79 |
my ( $installation, $cronLocation ) = @_;
|
|
|
80 |
# Allow user to customize the installation paths
|
|
|
81 |
foreach my $answer ( sort keys %$installation ) {
|
|
|
82 |
if ( $answer eq '2. Modules Directory' or $answer eq '3. Scripts Directory' ) {
|
|
|
83 |
$$installation{$answer} = $$installation{'1. Configuration Directory'} . '/' . $$installation{$answer};
|
|
|
84 |
}
|
|
|
85 |
print "$answer [$$installation{$answer}]: ";
|
|
|
86 |
my $temp = <>;
|
|
|
87 |
chomp $temp;
|
|
|
88 |
$$installation{$answer} = $temp if $temp;
|
|
|
89 |
}
|
|
|
90 |
print "Link executable into which location [$$cronLocation]: ";
|
|
|
91 |
my $temp = <>;
|
|
|
92 |
chomp $temp;
|
|
|
93 |
$$cronLocation = $temp if $temp;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
sub makeDirectory {
|
|
|
97 |
my ( $directory, $owner, $permissions ) = @_;
|
9 |
rodolico |
98 |
return if -d $directory;
|
|
|
99 |
# make_path is very good and efficient, if File is installed, so we try it
|
|
|
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";
|
|
|
106 |
print "chmod $permissions $directory\n";
|
|
|
107 |
return;
|
|
|
108 |
}
|
|
|
109 |
`mkdir -p $directory`;
|
|
|
110 |
`chown $owner $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";
|
|
|
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 |
}
|
8 |
rodolico |
122 |
}
|
|
|
123 |
|
|
|
124 |
sub doInstall {
|
|
|
125 |
my ( $installation, $cronLocation, $packageActions ) = @_;
|
|
|
126 |
foreach my $item ( keys %$packageActions ) {
|
9 |
rodolico |
127 |
&makeDirectory(
|
|
|
128 |
$$installation{$$packageActions{$item}{'target'}},
|
|
|
129 |
$$packageActions{$item}{'owner'},
|
|
|
130 |
$$packageActions{$item}{'dir perms'}
|
|
|
131 |
);
|
|
|
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?
|
|
|
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"`;
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
} # foreach
|
8 |
rodolico |
154 |
}
|
|
|
155 |
|
|
|
156 |
sub readConfiguration {
|
|
|
157 |
my ( $configuration,$confFileName ) = @_;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
sub ipFire {
|
|
|
161 |
my @BACKUP_DIRS = ('/opt/sysinfo', '/etc/sysinfo');
|
|
|
162 |
my @INSTALL_COMMANDS = (
|
|
|
163 |
'cp -av opt /',
|
|
|
164 |
'cp -av etc /',
|
|
|
165 |
'ln -s /opt/sysinfo/sysinfo /etc/fcron.daily/sysinfo.cron'
|
|
|
166 |
);
|
|
|
167 |
# now, check for backup directories not in include.user
|
|
|
168 |
open BACKUP, '</var/ipfire/backup/include.user';
|
|
|
169 |
while ( $line = <BACKUP> ) {
|
|
|
170 |
chomp $line;
|
|
|
171 |
for (my $i = 0; $i < @BACKUP_DIRS; $i++ ) {
|
|
|
172 |
if ( $BACKUP_DIRS[$i] eq $line ) {
|
|
|
173 |
$BACKUP_DIRS[$i] = '';
|
|
|
174 |
last;
|
|
|
175 |
} # if
|
|
|
176 |
}# for
|
|
|
177 |
} # while
|
|
|
178 |
close BACKUP;
|
|
|
179 |
|
|
|
180 |
# if any remain, append them to include.user
|
|
|
181 |
open BACKUP, '>>/var/ipfire/backup/include.user';
|
|
|
182 |
foreach my $backupDir ( @BACKUP_DIRS ) {
|
|
|
183 |
print BACKUP "$backupDir\n" if $backupDir;
|
|
|
184 |
}
|
|
|
185 |
close BACKUP;
|
|
|
186 |
|
|
|
187 |
# set all modules with ipfire in the name to run
|
|
|
188 |
opendir $moduleDir, $MODULES_DIR;
|
|
|
189 |
my @modules = grep { /ipfire/ } readdir $moduleDir;
|
|
|
190 |
closedir $moduleDir;
|
|
|
191 |
foreach my $module (@modules) {
|
|
|
192 |
`chmod 755 $MODULES_DIR/$module`;
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
#####################################################################
|
|
|
197 |
# Main Program
|
|
|
198 |
#####################################################################
|
|
|
199 |
|
|
|
200 |
# if installationType or cronLocation not set, find them
|
|
|
201 |
$installationType = &getInstallationType() unless $installationType;
|
|
|
202 |
$cronLocation = &findCron( '/etc/cron.daily', '/etc/fcron.daily' ) unless $cronLocation;
|
|
|
203 |
# allow use to change installation paths
|
|
|
204 |
&customizeInstall( \%installation,\$cronLocation, \%packageActions );
|
|
|
205 |
|
|
|
206 |
print "Script will be run from: $cronLocation\n";
|
|
|
207 |
print "The operaitng system is: $installationType\n";
|
|
|
208 |
foreach my $answer ( sort keys %installation ) {
|
|
|
209 |
print "$answer = $installation{$answer}\n";
|
|
|
210 |
}
|
|
|
211 |
print 'Continue? [Y/n]: ';
|
|
|
212 |
$answer = <>;
|
|
|
213 |
chomp $answer;
|
|
|
214 |
$answer = $answer ? uc $answer : 'Y';
|
|
|
215 |
exit unless $answer eq 'Y';
|
|
|
216 |
print "Continuing the installation\n";
|
|
|
217 |
|
9 |
rodolico |
218 |
&doInstall( \%installation, $cronLocation, \%packageActions );
|
8 |
rodolico |
219 |
|
|
|
220 |
1;
|