Repository navigation
Expand file tree
/
Copy pathcheck_apps.pl
More file actions
executable file
·171 lines (144 loc) · 4 KB
/
Copy pathcheck_apps.pl
File metadata and controls
executable file
·171 lines (144 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/perl
#
# check_apps: Check installed applications
#
# Usage:
# daily_backup.pl <options>
#
# Options:
# -help : Print usage
# -debug : debugging on
# -label : label for output
# -list : check list
#
#=============================================================================
# Get the needed PERL supplied library modules.
#=============================================================================
use Getopt::Long;
use Getopt::Std;
use Time::Local;
#
# Get the program basename.
#
($prog = $0) =~ s|.*/||;
#
# Unbuffer standard output
#
$| = 1;
# set flushing
$OUTPUT_AUTOFLUSH = 1;
#
# Set file permissions
#
umask 002;
# Initialize command line arguments
$opt_debug = "";
$opt_params = "";
$opt_label = "";
$usage =
"\nUsage: $prog <options>\n" .
"Options:\n" .
" -help :Print usage\n" .
" -dir :app dir (required)\n" .
" -label :label for messages\n" .
" -list :app check list (required)\n" .
" -debug :debugging on\n" .
"\n";
# Get the arguments from the command line
$results = &GetOptions('help',
'dir:s',
'label:s',
'list:s',
'debug');
if ($opt_help) {
print $usage;
exit 0;
}
if (!$opt_list) {
print "\nERROR - you must specify the app list\n";
print $usage;
exit 0;
}
if (!$opt_dir) {
print "\nERROR - you must specify the app dir\n";
print $usage;
exit 0;
}
# read in the list of installed apps, from the app directory
opendir(DIRHANDLE, $opt_dir) || die "Cannot open dir: $opt_dir: $!";
$count = 0;
foreach $name (sort readdir(DIRHANDLE)) {
if (!($name =~ m/^\./)) {
@installed_apps[$count] = $name;
$count++;
}
}
closedir(DIRHANDLE);
if ($opt_debug) {
printf STDERR "=============== INSTALLED APPS ===============\n";
foreach $app (@installed_apps) {
print STDERR "$app\n";
}
printf STDERR "==============================================\n";
}
# read in list of required apps, from check list
open(CHECKLIST, "< $opt_list") || die("can't open $opt_list: $!");
$count = 0;
while(($line = <CHECKLIST>)) {
chop($line);
if (!($line =~ m/^\#/)) {
($appname, $comments) = split(/#/, $line, 2);
$appname =~ s/ //g;
$comments =~ s/^ //;
@required_apps[$count] = $appname;
$app_comments{$appname} = $comments;
$count++;
}
}
close(CHECKLIST);
if ($opt_debug) {
printf STDERR "================ REQUIRED APPS ===============\n";
foreach $app (@required_apps) {
print STDERR "$app\n";
}
printf STDERR "==============================================\n";
}
# find apps which are not installed
$nmiss = 0;
foreach $req_app (@required_apps) {
$found = 0;
foreach $inst_app (@installed_apps) {
if ($inst_app eq $req_app) {
$found = 1;
break;
}
}
if (!$found) {
@missing_apps[$nmiss] = $req_app;
$nmiss++;
}
}
# if apps are missing, print out error message
if ($nmiss > 0) {
printf STDERR "==================>> ERROR <<===================\n";
printf STDERR "$opt_label\n";
printf STDERR "=====>> INCOMPLETE $opt_label APPS INSTALLATION <<====\n\n";
printf STDERR " $nmiss missing applications:\n\n";
foreach $mapp (@missing_apps) {
printf STDERR " $opt_label application \'$mapp\' missing\n";
$comments = $app_comments{$mapp};
printf STDERR " NOTE: $comments\n";
$findstr = `find apps -name $mapp`;
@lines = split(/\n/, $findstr);
printf STDERR " Check in dir:\n";
foreach $line (@lines) {
printf STDERR " $line\n";
}
}
exit 1;
} else {
printf STDERR "==================>> SUCCESS <<====================\n";
printf STDERR "$opt_label\n";
printf STDERR "====>> ALL $opt_label APPS SUCCESSFULLY INSTALLED <<====\n";
exit 0;
}