blib/script/default-install

filter: Statementstmt 13.0% 29 / 223 Branchbran 0.0% 0 / 198 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 28.5% 6 / 21 Podpod n/a totaltotal 7.5% 35 / 464 CC 87 SCAR 49.7
CC
87
Cov
7%
install_cron_scripts
462.0
install_central_config_file
132.0
install_user_config_file
132.0
CRAP 144.5
↑ Summary blib/lib/WWW/Link_Controller/ReadConf.pm »
1 #!/usr/local/bin/perl -w
2  
3 =head1 NAME
4  
5 default-install - Configure LinkController to run in a basic way.
6  
7 =head1 DESCRIPTION
8  
9 This is an attempt to build a default installation of link-controller
10 to make it plug in and play. This is designed for an installation
11 where the system adminstrator will run LinkController whilst users
12 will use the central database of links, but repair their own web
13 pages. This would be suitable for use by e.g. a web hosting company.
14 We want the following attributes.
15  
16 =over 4
17  
18 =item *
19  
20 reasonable security
21  
22 =item *
23  
24 near instant usability
25  
26 =item *
27  
28 easy control by root
29  
30 =item *
31  
32 accountability
33  
34 =item *
35  
36 No network traffic if nobody uses link controller.
37  
38 =back
39  
40 Currently the default installation is designed for the following
41 model..
42  
43 There is a B<linkcont> user and a group B<lcuser>. A program running
44 as the link-controller user collects link lists from each user on the
45 system who is in the group from the file
46  
47 ~$user/.link-control-links
48  
49 The script /etc/cron.daily/linkcontroller then runks link checking
50 every night based on those links. The link checking runs as the
51 linkcont user.
52  
53 We then log the activities of link controller to /var/log/link-controller
54  
55 =head1 OPTIONS
56  
57 =head2 --help
58  
59 This option gives a full summary of the options and their aliases and
60 short forms.
61  
62 =head2 --all
63  
64 This option is the same as
65 "B<--cron --config --user-config --directory --create-user>".
66 That is to say it does everything that is needed to get
67 B<LinkController> running. However it doesn't activate any users.
68 You should activate users to use LinkControlller with
69 B<--user> and/or B<--group>.
70  
71 =head2 --cron
72  
73 This option installs two cron scripts. One /etc/cron.daily which runs
74 B<LinkController> and one in /etc/cron.weekly which does a database
75 cleanup. This should mean that link controller is run automatically
76 each night, which hopefully is your network low usage time.
77  
78 =head2 --config
79  
80 Install the configuration files. This creates /etc/link-control.pl
81  
82 =head2 --base-dir
83  
84 This option can be used in during building a package (e.g. RPM) of
85 LinkController. It will put all of the files created under the
86 directory given. This doesn't however mean that the installation will
87 work in that location. It is assumed that the files will either be
88 linked or moved into their normal locations by some other means. In
89 the case of RPM this means using the B<--build-root> option at package
90 build time.
91  
92 =head2 --disable
93  
94 With the B<--disable> option link controller reverses the actions it
95 would have taken normally.
96  
97 B<N.B. --disable does not stop anyone from running linkcontroller
98 themselves>. It is just that link controller will not run from the
99 linkcont user. In order to safely disable the use of link controller,
100 either remove it completely and stop your users installing programs
101 (and editing or creating any executable files) or disconnect your
102 network connection!!
103  
104 =head2 --user and --group
105  
106 These options activate users by putting them into the C<linkcont>
107 group. The B<--group> option does this for all of the members in a
108 particular group.
109  
110 =head1 BUGS
111  
112 This mode of operation requires that the users home directory is
113 readable to the linkcont user. A crontab like mechanism should maybe
114 be considered?
115  
116 =head1 SEE ALSO
117  
118 L<copy-links-from-users>
119  
120 L<verify-link-control(1)>; L<extract-links(1)>; L<build-schedule>
121 L<link-report(1)>; L<fix-link(1)>; L<link-report.cgi(1)>; L<fix-link.cgi>
122 L<suggest(1)>; L<link-report.cgi(1)>; L<configure-link-control>
123  
124 The LinkController manual in the distribution in HTML, info, or
125 postscript formats, included in the distribution.
126  
127 http://scotclimb.org.uk/software/linkcont - the
128 LinkController homepage.
129  
130 =cut
131  
132 sub install_cron_scripts ();
133 sub remove_cron_scripts ();
134 sub install_central_config_file ();
135 sub remove_central_config_file ();
136 sub install_user_config_file ();
137 sub remove_user_config_file ();
138 sub create_user ();
139 sub delete_user ();
140 sub activate_users (@);
141 sub deactivate_users (@);
142 sub create_workingdir ();
143 sub delete_workingdir ();
144  
145 2 ▶use Getopt::Function qw(maketrue makevalue);
Subroutine BEGIN: called CC=1 SCAR=0.0
146 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
147 2 ▶use vars qw/$config $user_config $cron $linkcont_user $user $disable
Subroutine BEGIN: called CC=1 SCAR=0.0
148 2 $directory $all $base_dir $verbose/;
149 2 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
150  
151 2 @::ORIG_ARGS=@::ARGV;
152  
153 #for filenames the variable postfixed with _INSTALL is where the file will
154 #be finally be installed.
155  
156 2 $::LC_USERS_GROUP='lnctusr';
157 #N.B. the following three are also copied to pkg-data-rpm/pre.sh
158 2 $::LC_USER='linkcont';
159 2 $::LC_GROUP=$::LC_USER;
160 2 $::LC_DIR_INSTALL='/var/lib/linkcontroller';
161 2 $::LOG_FILE_INSTALL='/var/log/link-controller';
162  
163  
164 2 $base_dir="";
165 2 my %users = ();
166  
167  
168 sub group;
169  
170 {
171 2 my $opened=0;
172 $::opthandler = new Getopt::Function
173 [ "version V>version",
174 "usage h>usage help>usage",
175 "help-opt=s",
176 "verbose:i v>verbose",
177 "cron C>cron",
178 "config N>config",
179 "directory D>directory",
180 "linkcont-user L>linkcont-user",
181 "user=s U>user",
182 "all A>all",
183 "group=s g>group",
184 "disable d>disable",
185 "base-dir=s b>base-dir",
186 ], {
187 0 ▶ "user" => [ sub {$::user=1, $users{$::value}=1; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
188 "(de)activate users in the linkcontroller group",
189 "USERNAME"],
190 group => [
191 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
192 0 $::user=1;
193 0 my ($name,$passwd,$gid,$members) = getgrnam($::value);
194 0 ▶ die "Unknown group $::value" unless defined($gid);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gid 0 0 0
195 #FIXME arbitrary parameter (100) which is often wrong,
196 #e.g. on redhat where 500 would be correct!!
197 0 foreach my $user (my @more_users = split ($members)) {
198 0 $users{$user}=1;
199 }
200 },
201 "(de)activate all group members to the linkcont group.",
202 "GROUP",
203 ],
204 "base-dir" => [ \&makevalue,
205 "use DIRECTORY as the base for file creation",
206 "DIRECTORY" ],
207 cron => [ \&maketrue,
208 "install cron scripts to run LinkController regularly" ],
209 config => [ \&maketrue,
210 "install system config. file /etc/link-control.pl" ],
211 "user-config" => [ \&maketrue,
212 "install linkcont config. in ~linkcont/.link-control.pl" ],
213 directory => [ \&maketrue,
214 "make LinkController working directory" ],
215 "linkcont-user" => [ \&maketrue,
216 "create $::LC_USER user for file ownership" ],
217 0 ▶ all => [ sub { $::all=1; $::cron=1; $::config=1; $::directory=1;
Subroutine __ANON__: not called CC=1 SCAR=6.9
218 0 $::linkcont_user=1; $::user_config=1; },
219 2 "Same as --cron --config --directory --create-user" ],
220 disable => [ \&maketrue,
221 "uninstall/deactivate rather than installing/activating" ],
222 };
223 }
224 2 $::opthandler->std_opts;
225  
226 2 $::opthandler->check_opts;
227  
228 1 ▶sub usage() {
Subroutine usage: called CC=1 SCAR=0.0
229 1 print <<EOF;
230 default-install [options]
231  
232 EOF
233 1 $::opthandler->list_opts;
234 1 print <<EOF;
235  
236 Setup LinkController to work in the default way, activating it as a
237 service for everybody on the system to use.
238  
239 Default way:
240 default-install --all --user=[USERNAME]
241 EOF
242  
243 }
244  
245 1 ▶sub version() {
Subroutine version: called CC=1 SCAR=0.0
246 1 print <<'EOF';
247 default-install version
248 $Id: default-install.pl,v 1.9 2002/01/06 10:38:31 mikedlr Exp $
249 EOF
250 }
251  
252 0 $::LOG_FILE=$base_dir . $::LOG_FILE_INSTALL;
253 0 $::LC_DIR=$base_dir . $::LC_DIR_INSTALL;
254  
255 #log information may be privilaged. Some people might not want others
256 #to know what links they are checking.
257  
258 #$LOGPERM="700"; #FIXME : not used??
259  
260  
261 0 $::DAILY_FILE_INSTALL="/etc/cron.daily/link-controller";
262 0 $::DAILY_FILE =$base_dir . $::DAILY_FILE_INSTALL;
263 0 $::DAILY_SCRIPT = <<"EOF";
264 #!/bin/sh
265 exec >> $::LOG_FILE_INSTALL 2>&1
266 echo Starting Daily Link Checking `date`
267 TODAYFILE=`date '+links-%Y-%d-%m'`
268  
269 su - $::LC_USER -c \\
270 "copy-links-from-users --group $::LC_USER > $::LC_DIR_INSTALL/\$TODAYFILE"
271 su - $::LC_USER -c \\
272 "extract-links --in-url-list $::LC_DIR_INSTALL/\$TODAYFILE"
273 su - $::LC_USER -c "build-schedule --verbose"
274 su - $::LC_USER -c "test-link --verbose"
275 echo Finished Daily Link Checking `date`
276 EOF
277  
278 0 $::WEEKLY_FILE_INSTALL = "/etc/cron.weekly/link-controller";
279 0 $::WEEKLY_FILE =$base_dir . $::WEEKLY_FILE_INSTALL;
280 0 $::WEEKLY_SCRIPT = <<"EOF";
281 #!/bin/sh
282 #exec >> $::LOG_FILE_INSTALL 2>&1
283 #su linkcont -c clean-database
284 #no clean database is needed right now..
285 EOF
286  
287 0 $::CONFIG_FILE_INSTALL = "/etc/link-control.pl";
288 0 $::CONFIG_FILE =$base_dir . $::CONFIG_FILE_INSTALL;
289 0 $::CONFIG_SCRIPT = <<'EOF';
290 #linkcontroller default system wide configuration file.. See man
291 #page for WWW::Link_Controller::ReadConf for details.
292  
293 use vars qw($schedule $links $page_index $link_index $fixlink_cgi);
294  
295 #we don't put the user address here since one of your users might run this
296 #you shouldn't really run link-controller as root anyway..
297 #$::user_address="root@" . $hostname;
298  
299 $::schedule="/var/lib/linkcontroller/schedule.bdbm";
300 $::links="/var/lib/linkcontroller/links.bdbm";
301 $::page_index="/var/lib/linkcontroller/page_has_link.cdb";
302 $::link_index="/var/lib/linkcontroller/link_on_page.cdb" ;
303 $::infostrucs="/var/lib/linkcontroller/infostrucs" ;
304  
305 #$::fixlink_cgi=
306 # "http://$realhostname/cgi-bin/users/$realusername/fix-link.cgi";
307  
308 1;
309 EOF
310  
311 0 $::USER_CONFIG_FILE_INSTALL = "$::LC_DIR_INSTALL/.link-control.pl";
312 0 $::USER_CONFIG_FILE =$base_dir . $::USER_CONFIG_FILE_INSTALL;
313 0 $::USER_CONFIG_SCRIPT = <<'EOF';
314  
315 #default configuration file for link-controller user. Sets the email
316 #address to root@[this host] to guarantee that something that is likely
317 #to get a response is sent. You should probably change this.
318  
319 use vars qw($user_address $hostname);
320  
321 require "hostname.pl";
322 $hostname=hostname();
323  
324 #basic sanity checks on hostname...
325 #this rejects valid hostnames like
326 #a-.az
327 # and
328 #com (at least I think it's valid)
329 #if you have such a hostname just comment out the following
330 #two lines or send in a patch with your hostname..
331  
332 die "hostname $hostname seems unrealistic"
333 unless $hostname=~ m/[a-z].*[a-z0-9]\.[a-z].*[a-z0-9]/;
334  
335 #it would be a seriously good idea to change this mail address. When
336 #you start to put this out into people's server logs, you are bound to
337 #eventually start getting junkmail.. However we have to make sure that
338 #any compaints about the behaviour of your robot get back to you to an
339 #account you read and root seems to be the best hope..
340  
341 $::user_address="root@" . $hostname;
342  
343 1;
344 EOF
345  
346  
347 sub remove_cron_scripts();
348 sub delete_user();
349 sub install_cron_scripts();
350 sub create_user();
351  
352 0 ▶unless ($cron or $user or $config or $linkcont_user or $directory) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($main::cron or $main::user or $main::config or $main::linkcont_user or $main::directory) 0 0 0
Condition0%0/12
$main::cron or $main::user or $main::config or $main::linkcont_user or $main::directory
l!l&&r!l&&!r
000
$main::cron or $main::user or $main::config or $main::linkcont_user
l!l&&r!l&&!r
000
$main::cron or $main::user or $main::config
l!l&&r!l&&!r
000
$main::cron or $main::user
l!l&&r!l&&!r
000
MC/DC0%0/5
$main::cron or $main::user or $main::config or $main::linkcont_user or $main::directory
$main::cron $main::user $main::config $main::linkcont_user $main::directory
Truth table0%0/6
A or B or C or D or E
A= $main::cronB= $main::userC= $main::configD= $main::linkcont_userE= $main::directory
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
353 0 print STDERR <<EOF;
354 default-install: no options given. You must say what to do.
355  
356 use default-install --help for usage information.
357 EOF
358 exit
359 0 }
360  
361 #we write to the LOG file under base dir..
362  
363 0 ▶open (LOG, ">>$::LOG_FILE" ) or die "can't open log file script $!";
Branch: 1 branch
BranchTrueFalseTotal
open LOG, ">>$main::LOG_FILE" or die "can't open log file script $!" 0 0 0
364 0 my $date=`date`;
365 0 chomp $date;
366 0 print LOG $date, ": default-install run with args ", join (" ", @::ORIG_ARGS), "\n";
367 0 close LOG;
368  
369 0 ▶if ( $disable ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::disable) { } 0 0 0
370 0 ▶ remove_user_config_file() if $user_config;
Branch: 1 branch
BranchTrueFalseTotal
if $main::user_config 0 0 0
371 0 ▶ delete_user() if $linkcont_user;
Branch: 1 branch
BranchTrueFalseTotal
if $main::linkcont_user 0 0 0
372 0 ▶ remove_cron_scripts() if $cron;
Branch: 1 branch
BranchTrueFalseTotal
if $main::cron 0 0 0
373 0 ▶ remove_central_config_file() if $config;
Branch: 1 branch
BranchTrueFalseTotal
if $main::config 0 0 0
374 0 ▶ deactivate_users(keys(%users)) if $user;
Branch: 1 branch
BranchTrueFalseTotal
if $main::user 0 0 0
375 0 ▶ delete_workingdir() if $directory;
Branch: 1 branch
BranchTrueFalseTotal
if $main::directory 0 0 0
376 } else {
377 0 ▶ create_user() if $linkcont_user;
Branch: 1 branch
BranchTrueFalseTotal
if $main::linkcont_user 0 0 0
378 0 ▶ install_cron_scripts() if $cron;
Branch: 1 branch
BranchTrueFalseTotal
if $main::cron 0 0 0
379 0 ▶ install_central_config_file() if $config;
Branch: 1 branch
BranchTrueFalseTotal
if $main::config 0 0 0
380 0 ▶ activate_users(keys(%users)) if $user;
Branch: 1 branch
BranchTrueFalseTotal
if $main::user 0 0 0
381 0 ▶ create_workingdir() if $directory;
Branch: 1 branch
BranchTrueFalseTotal
if $main::directory 0 0 0
382 0 ▶ install_user_config_file() if $user_config;
Branch: 1 branch
BranchTrueFalseTotal
if $main::user_config 0 0 0
383 0 ▶ print STDERR "Remember to activate users separately\n" if $all and not $user;
Branch: 1 branch
BranchTrueFalseTotal
if $main::all and not $main::user 0 0 0
Condition0%0/3
$main::all and not $main::user
!ll&&!rl&&r
000
MC/DC0%0/2
$main::all and not $main::user
$main::all not $main::user
Truth table0%0/3
A and not(B)
A= $main::allB= not $main::user
ABresult
0X0
100
111
384 }
385  
386 0 ▶open (LOG, ">>$::LOG_FILE" ) or die "can't open log file script $!";
Branch: 1 branch
BranchTrueFalseTotal
open LOG, ">>$main::LOG_FILE" or die "can't open log file script $!" 0 0 0
387 0 $date=`date`;
388 0 chomp $date;
389 0 print LOG $date, ": default-install completed with args ", join (" ", @::ORIG_ARGS), "\n";
390 0 close LOG;
391  
392 0 print STDERR "default-install completed\n";
393  
394 0 exit 0;
395  
396 0 ▶sub install_cron_scripts () {
Subroutine install_cron_scripts: not called CC=21 SCAR=61.4
397 0 ▶ print STDERR "installing cron scripts\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
398 0 ▶ -e $::DAILY_FILE and warn "The file $::DAILY_FILE already exists";
Branch: 1 branch
BranchTrueFalseTotal
-e $main::DAILY_FILE and warn "The file $main::DAILY_FILE already exists" 0 0 0
399 0 ▶ -e $::WEEKLY_FILE and warn "The file $::WEEKLY_FILE already exists";
Branch: 1 branch
BranchTrueFalseTotal
-e $main::WEEKLY_FILE and warn "The file $main::WEEKLY_FILE already exists" 0 0 0
400 0 ▶ open (DAILY, ">$::DAILY_FILE" ) or die "can't open daily script $!";
Branch: 1 branch
BranchTrueFalseTotal
open DAILY, ">$main::DAILY_FILE" or die "can't open daily script $!" 0 0 0
401 eval {
402 0 ▶ print DAILY $::DAILY_SCRIPT or die "writing daily script failed $!";
Branch: 1 branch
BranchTrueFalseTotal
print DAILY $main::DAILY_SCRIPT or die "writing daily script failed $!" 0 0 0
403 0 ▶ close (DAILY) or die "close failed" ;
Branch: 1 branch
BranchTrueFalseTotal
close DAILY or die "close failed" 0 0 0
404 0 ▶ system ('chmod', '+x', $::DAILY_FILE ) and die "chmod failed";
Branch: 1 branch
BranchTrueFalseTotal
system "chmod", "+x", $main::DAILY_FILE and die "chmod failed" 0 0 0
405 0 ▶ $? & 127 and die "chmod recieved signal";
Branch: 1 branch
BranchTrueFalseTotal
$? & 127 and die "chmod recieved signal" 0 0 0
406 0 ▶ $? & 128 and die "chmod dumped core";
Branch: 1 branch
BranchTrueFalseTotal
$? & 128 and die "chmod dumped core" 0 0 0
407 0 1;
408 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { print DAILY $main::DAILY_SCRIPT or die "writing daily script failed $!"; close DAILY or die "close failed"; system "chmod", "+x", $main::DAILY_FILE and die "chmod failed"; $? & 127 and die "chmod recieved signal"; $? & 128 and die "chmod dumped core"; 1 } } or do { close DAILY; unlink $main::DAILY_FILE or warn "couldn't unlink $main::DAILY_FILE"; die $@ } 0 0 0
409 #close file in case we created it.
410 #it's too late to worry about the exit status
411 0 close(DAILY);
412 0 ▶ unlink $::DAILY_FILE or warn "couldn't unlink $::DAILY_FILE";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::DAILY_FILE or warn "couldn't unlink $main::DAILY_FILE" 0 0 0
413 0 die $@;
414 };
415 # ignored race condition here. It's possible to create the weekly
416 # file after our test of existence and then to have us delete it.
417 # This could happen e.g. if the program ran twice at the same time..
418 eval {
419 0 ▶ open (WEEKLY, ">$::WEEKLY_FILE" ) or die "lc daily no open";
Branch: 1 branch
BranchTrueFalseTotal
open WEEKLY, ">$main::WEEKLY_FILE" or die "lc daily no open" 0 0 0
420 0 ▶ print WEEKLY $::WEEKLY_SCRIPT or die "writing weekly script failed $!";
Branch: 1 branch
BranchTrueFalseTotal
print WEEKLY $main::WEEKLY_SCRIPT or die "writing weekly script failed $!" 0 0 0
421 0 ▶ close WEEKLY or die "closing weekly script failed $!";
Branch: 1 branch
BranchTrueFalseTotal
close WEEKLY or die "closing weekly script failed $!" 0 0 0
422 0 ▶ system ('chmod', '+x', $::WEEKLY_FILE ) and die "chmod failed";
Branch: 1 branch
BranchTrueFalseTotal
system "chmod", "+x", $main::WEEKLY_FILE and die "chmod failed" 0 0 0
423 0 ▶ $? & 127 and die "chmod recieved signal";
Branch: 1 branch
BranchTrueFalseTotal
$? & 127 and die "chmod recieved signal" 0 0 0
424 0 ▶ $? & 128 and die "chmod dumped core";
Branch: 1 branch
BranchTrueFalseTotal
$? & 128 and die "chmod dumped core" 0 0 0
425 0 1;
426 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { open WEEKLY, ">$main::WEEKLY_FILE" or die "lc daily no open"; print WEEKLY $main::WEEKLY_SCRIPT or die "writing weekly script failed $!"; close WEEKLY or die "closing weekly script failed $!"; system "chmod", "+x", $main::WEEKLY_FILE and die "chmod failed"; $? & 127 and die "chmod recieved signal"; $? & 128 and die "chmod dumped core"; 1 } } or do { close WEEKLY; unlink $main::DAILY_FILE or warn "couldn't unlink $main::DAILY_FILE after failure"; unlink $main::WEEKLY_FILE or warn "couldn't unlink $main::WEEKLY_FILE after failure"; die $@ } 0 0 0
427 #close file in case we created it.
428 #it's too late to worry about the exit status
429 0 close (WEEKLY);
430 0 ▶ unlink $::DAILY_FILE or
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::DAILY_FILE or warn "couldn't unlink $main::DAILY_FILE after failure" 0 0 0
431 warn "couldn't unlink $::DAILY_FILE after failure";
432 0 ▶ unlink $::WEEKLY_FILE or
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::WEEKLY_FILE or warn "couldn't unlink $main::WEEKLY_FILE after failure" 0 0 0
433 warn "couldn't unlink $::WEEKLY_FILE after failure";
434 0 die $@;
435 };
436 }
437  
438 0 ▶sub remove_cron_scripts () {
Subroutine remove_cron_scripts: not called CC=4 SCAR=30.0
439 0 ▶ print STDERR "removing cron scripts\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
440 0 ▶ unlink $::DAILY_FILE or warn "deleting daily script failed $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::DAILY_FILE or warn "deleting daily script failed $!" 0 0 0
441 0 ▶ unlink $::WEEKLY_FILE or warn "deleting weekly script failed $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::WEEKLY_FILE or warn "deleting weekly script failed $!" 0 0 0
442 }
443  
444 0 ▶sub install_central_config_file () {
Subroutine install_central_config_file: not called CC=11 SCAR=48.8
445 0 ▶ print STDERR "installing central configuration script\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
446 0 ▶ -e $::CONFIG_FILE and do {
Branch: 1 branch
BranchTrueFalseTotal
-e $main::CONFIG_FILE and do { warn "The file $main::CONFIG_FILE already exists; not overwriting"; return 0 } 0 0 0
447 0 warn "The file $::CONFIG_FILE already exists; not overwriting";
448 0 return 0;
449 };
450 0 ▶ open (CONFIG, ">$::CONFIG_FILE" ) or die "can't open config script $!";
Branch: 1 branch
BranchTrueFalseTotal
open CONFIG, ">$main::CONFIG_FILE" or die "can't open config script $!" 0 0 0
451 eval {
452 0 ▶ print CONFIG $::CONFIG_SCRIPT or die "writing config script failed $!";
Branch: 1 branch
BranchTrueFalseTotal
print CONFIG $main::CONFIG_SCRIPT or die "writing config script failed $!" 0 0 0
453 0 ▶ close (CONFIG) or die "close failed" ;
Branch: 1 branch
BranchTrueFalseTotal
close CONFIG or die "close failed" 0 0 0
454 0 ▶ system ('chmod', '+x', $::CONFIG_FILE ) and die "chmod failed";
Branch: 1 branch
BranchTrueFalseTotal
system "chmod", "+x", $main::CONFIG_FILE and die "chmod failed" 0 0 0
455 0 ▶ $? & 127 and die "chmod recieved signal";
Branch: 1 branch
BranchTrueFalseTotal
$? & 127 and die "chmod recieved signal" 0 0 0
456 0 ▶ $? & 128 and die "chmod dumped core";
Branch: 1 branch
BranchTrueFalseTotal
$? & 128 and die "chmod dumped core" 0 0 0
457 0 1;
458 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { print CONFIG $main::CONFIG_SCRIPT or die "writing config script failed $!"; close CONFIG or die "close failed"; system "chmod", "+x", $main::CONFIG_FILE and die "chmod failed"; $? & 127 and die "chmod recieved signal"; $? & 128 and die "chmod dumped core"; 1 } } or do { close CONFIG; unlink $main::CONFIG_FILE or warn "couldn't unlink $main::CONFIG_FILE"; die $@ } 0 0 0
459 #close file in case we created it.
460 #it's too late to worry about the exit status
461 0 close(CONFIG);
462 0 ▶ unlink $::CONFIG_FILE or warn "couldn't unlink $::CONFIG_FILE";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::CONFIG_FILE or warn "couldn't unlink $main::CONFIG_FILE" 0 0 0
463 0 die $@;
464 };
465 # ignored race condition here. It's possible to create the weekly
466 # file after our test of existence and then to have us delete it.
467 # This could happen e.g. if the program ran twice at the same time..
468 }
469  
470 0 ▶sub remove_central_config_file () {
Subroutine remove_central_config_file: not called CC=6 SCAR=37.4
471 0 ▶ if (-e $::CONFIG_FILE ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $main::CONFIG_FILE) 0 0 0
472 0 open (CONFIG, $::CONFIG_FILE);
473 0 my $config;
474 0 ▶ while (<CONFIG>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline CONFIG)) 0 0 0
475 0 $config .= $_;
476 }
477 0 ▶ unless ($config eq $::CONFIG_SCRIPT) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config eq $main::CONFIG_SCRIPT) 0 0 0
478 0 warn "$::CONFIG_FILE has been edited (or is old). Delete by hand";
479 0 return 0;
480 }
481 }
482  
483 0 ▶ print STDERR "removing central config script\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
484 0 ▶ unlink $::CONFIG_FILE or warn "deleting config script failed $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::CONFIG_FILE or warn "deleting config script failed $!" 0 0 0
485 }
486  
487 0 ▶sub install_user_config_file () {
Subroutine install_user_config_file: not called CC=11 SCAR=48.8
488 0 ▶ print STDERR "installing user configuration script\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
489 0 ▶ -e $::USER_CONFIG_FILE and do {
Branch: 1 branch
BranchTrueFalseTotal
-e $main::USER_CONFIG_FILE and do { warn "The file $main::USER_CONFIG_FILE already exists; not overwriting"; return 0 } 0 0 0
490 0 warn "The file $::USER_CONFIG_FILE already exists; not overwriting";
491 0 return 0;
492 };
493 0 ▶ open (CONFIG, ">$::USER_CONFIG_FILE" ) or die "can't open config script $!";
Branch: 1 branch
BranchTrueFalseTotal
open CONFIG, ">$main::USER_CONFIG_FILE" or die "can't open config script $!" 0 0 0
494 eval {
495 0 ▶ print CONFIG $::USER_CONFIG_SCRIPT or die "writing config script failed $!";
Branch: 1 branch
BranchTrueFalseTotal
print CONFIG $main::USER_CONFIG_SCRIPT or die "writing config script failed $!" 0 0 0
496 0 ▶ close (CONFIG) or die "close failed" ;
Branch: 1 branch
BranchTrueFalseTotal
close CONFIG or die "close failed" 0 0 0
497 0 ▶ system ('chmod', '+x', $::USER_CONFIG_FILE ) and die "chmod failed";
Branch: 1 branch
BranchTrueFalseTotal
system "chmod", "+x", $main::USER_CONFIG_FILE and die "chmod failed" 0 0 0
498 0 ▶ $? & 127 and die "chmod recieved signal";
Branch: 1 branch
BranchTrueFalseTotal
$? & 127 and die "chmod recieved signal" 0 0 0
499 0 ▶ $? & 128 and die "chmod dumped core";
Branch: 1 branch
BranchTrueFalseTotal
$? & 128 and die "chmod dumped core" 0 0 0
500 0 1;
501 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { print CONFIG $main::USER_CONFIG_SCRIPT or die "writing config script failed $!"; close CONFIG or die "close failed"; system "chmod", "+x", $main::USER_CONFIG_FILE and die "chmod failed"; $? & 127 and die "chmod recieved signal"; $? & 128 and die "chmod dumped core"; 1 } } or do { close CONFIG; unlink $main::USER_CONFIG_FILE or warn "couldn't unlink $main::USER_CONFIG_FILE"; die $@ } 0 0 0
502 #close file in case we created it.
503 #it's too late to worry about the exit status
504 0 close(CONFIG);
505 0 ▶ unlink $::USER_CONFIG_FILE or warn "couldn't unlink $::USER_CONFIG_FILE";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::USER_CONFIG_FILE or warn "couldn't unlink $main::USER_CONFIG_FILE" 0 0 0
506 0 die $@;
507 };
508 # ignored race condition here. It's possible to create the weekly
509 # file after our test of existence and then to have us delete it.
510 # This could happen e.g. if the program ran twice at the same time..
511 }
512  
513 0 ▶sub remove_user_config_file () {
Subroutine remove_user_config_file: not called CC=6 SCAR=37.4
514 0 ▶ if (-e $::USER_CONFIG_FILE ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $main::USER_CONFIG_FILE) 0 0 0
515 0 open (CONFIG, $::USER_CONFIG_FILE);
516 0 my $config;
517 0 ▶ while (<CONFIG>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline CONFIG)) 0 0 0
518 0 $config .= $_;
519 }
520 0 ▶ unless ($config eq $::USER_CONFIG_SCRIPT) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config eq $main::USER_CONFIG_SCRIPT) 0 0 0
521 0 warn "$::USER_CONFIG_FILE has been edited (or is old). Delete by hand";
522 0 return 0;
523 }
524 }
525  
526 0 ▶ print STDERR "removing user config script\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
527 0 ▶ unlink $::USER_CONFIG_FILE or warn "deleting user config script failed $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::USER_CONFIG_FILE or warn "deleting user config script failed $!" 0 0 0
528 }
529  
530 0 ▶sub create_user () {
Subroutine create_user: not called CC=8 SCAR=42.8
531 0 my $uid = getpwnam($::LC_USER);
532 0 ▶ if ( $uid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uid) 0 0 0
533 0 warn "Not creating user $::LC_USER; exists with UID $uid";
534 0 return 0;
535 }
536 0 my ($name,$passwd,$gid,$members) = getgrnam($::LC_GROUP);
537 0 ▶ unless ($gid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gid) 0 0 0
538 0 ▶ print STDERR "creating $::LC_GROUP group\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
539 0 system ( 'groupadd', '-r', $::LC_GROUP)
540 }
541  
542 0 ▶ print STDERR "creating $::LC_USER user\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
543 #FIXME check for existing user
544 system ( 'useradd', '-c', 'LinkController service', #comment
545 '-d', $::LC_DIR_INSTALL, #homedir
546 '-M', #we don't need a homedir 'cos we should work in /var
547 #'-o', #FIXME postgress shares UIDS. I don't understand why.
548 #'-u', '26', # they also specify a UID!!!
549 '-r', #create a system account
550 '-g', $::LC_GROUP,
551 '-s', '/bin/bash', #seems fine to me
552 0 ▶ $::LC_USER ) and do {
Branch: 1 branch
BranchTrueFalseTotal
system "useradd", "-c", "LinkController service", "-d", $main::LC_DIR_INSTALL, "-M", "-r", "-g", $main::LC_GROUP, "-s", "/bin/bash", $main::LC_USER and do { warn "couldn't create the $main::LC_USER user"; unlink $main::DAILY_FILE or warn "couldn't unlink $main::DAILY_FILE"; unlink $main::WEEKLY_FILE or warn "couldn't unlink $main::WEEKLY_FILE"; die "aborted due to errors" } 0 0 0
553 #FIXME.. we should probably only unlink if we just created!!??
554 0 warn "couldn't create the $::LC_USER user";
555 0 ▶ unlink $::DAILY_FILE or warn "couldn't unlink $::DAILY_FILE";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::DAILY_FILE or warn "couldn't unlink $main::DAILY_FILE" 0 0 0
556 0 ▶ unlink $::WEEKLY_FILE or warn "couldn't unlink $::WEEKLY_FILE";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::WEEKLY_FILE or warn "couldn't unlink $main::WEEKLY_FILE" 0 0 0
557 0 die "aborted due to errors";
558 };
559 }
560  
561  
562 0 ▶sub delete_user () {
Subroutine delete_user: not called CC=8 SCAR=42.8
563 0 ▶ print STDERR "deleting linkcont user\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
564 0 ▶ system ( 'userdel', $::LC_USER ) && do {
Branch: 1 branch
BranchTrueFalseTotal
system "userdel", $main::LC_USER and do { warn "couldn't delete the $main::LC_USER user"; return 0 } 0 0 0
565 0 warn "couldn't delete the $::LC_USER user";
566 0 return 0;
567 };
568  
569 0 ▶ print STDERR "deleting $::LC_GROUP group\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
570  
571 0 my ($name,$passwd,$gid,$members) = getgrnam($::LC_GROUP);
572 0 ▶ if ($gid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gid) 0 0 0
573 0 ▶ $members && do {
Branch: 1 branch
BranchTrueFalseTotal
$members and do { print STDERR "Group $main::LC_GROUP is not empty. Not deleting\n" if $main::verbose; return } 0 0 0
574 0 ▶ print STDERR "Group $::LC_GROUP is not empty. Not deleting\n"
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
575 if $verbose;
576 0 return ;
577 };
578 0 ▶ print STDERR "deleting $::LC_GROUP group\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
579 0 system ( 'groupdel', $::LC_GROUP)
580 }
581 }
582  
583 0 ▶sub activate_users (@) {
Subroutine activate_users: not called CC=5 SCAR=34.0
584 0 my @users=@_;
585 0 my ($name,$passwd,$gid,$members) = getgrnam($::LC_USERS_GROUP);
586 0 ▶ unless ($gid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gid) 0 0 0
587 0 ▶ print STDERR "creating $::LC_USERS_GROUP group\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
588 0 system ( 'groupadd', $::LC_USERS_GROUP );
589 }
590  
591 0 ▶ print STDERR "activating given users " , join( ' ', @users) ,"\n"
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
592 if $verbose;
593 0 foreach my $user (@users) {
594 0 my $groups=`id -Gn $user`;
595 0 chomp $groups;
596 0 $groups .= " $::LC_USERS_GROUP";
597 0 $groups =~ s/ /,/g;
598 0 system ("usermod", '-G', $groups, $user);
599 }
600 }
601  
602 0 ▶sub deactivate_users (@) {
Subroutine deactivate_users: not called CC=9 SCAR=45.0
603 0 ▶ print STDERR "deactivating given users\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $main::verbose 0 0 0
604 0 my @users=@_;
605 0 foreach $user(@users) {
606 #list current groups
607 0 my $groups=`id -Gn`;
608 0 ▶ die "no groups found for user $user" unless $groups;
Branch: 1 branch
BranchTrueFalseTotal
unless $groups 0 0 0
609 0 my @groups=split(/ /, $groups);
610 0 my @newgroups=();
611 #delete our group
612 0 foreach my $group(@groups) {
613 0 ▶ push @newgroups, $group unless $group eq $::LC_USERS_GROUP;
Branch: 1 branch
BranchTrueFalseTotal
unless $group eq $main::LC_USERS_GROUP 0 0 0
614 }
615 #apply
616 0 ▶ system ( 'usermod', '-G', join (',', @newgroups), $user ) || do {
Branch: 1 branch
BranchTrueFalseTotal
system "usermod", "-G", join(",", @newgroups), $main::user or do { warn "couldn't activate user $main::user"; unlink $main::DAILY_FILE or warn "couldn't unlink $main::DAILY_FILE"; unlink $main::WEEKLY_FILE or warn "couldn't unlink $main::WEEKLY_FILE"; die "aborted due to errors" } 0 0 0
617 0 warn "couldn't activate user $user";
618 0 ▶ unlink $::DAILY_FILE or warn "couldn't unlink $::DAILY_FILE";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::DAILY_FILE or warn "couldn't unlink $main::DAILY_FILE" 0 0 0
619 0 ▶ unlink $::WEEKLY_FILE or warn "couldn't unlink $::WEEKLY_FILE";
Branch: 1 branch
BranchTrueFalseTotal
unlink $main::WEEKLY_FILE or warn "couldn't unlink $main::WEEKLY_FILE" 0 0 0
620 0 die "aborted due to errors";
621 };
622 }
623 }
624  
625 0 ▶sub create_workingdir () {
Subroutine create_workingdir: not called CC=4 SCAR=30.0
626 0 ▶ if (-d $::LC_DIR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $main::LC_DIR) { } 0 0 0
627 0 warn "LinkController Working directory $::LC_DIR already present";
628 } else {
629 0 ▶ mkpath("$::LC_DIR") or warn "working directory creation failed";
Branch: 1 branch
BranchTrueFalseTotal
mkpath("$main::LC_DIR") or warn "working directory creation failed" 0 0 0
630 0 ▶ my ($login,$pass,$uid,$gid) = getpwnam($::LC_USER)
Branch: 1 branch
BranchTrueFalseTotal
() = getpwnam $main::LC_USER or die "$main::LC_USER user not in passwd file. Can't create directory." 0 0 0
631 or die "$::LC_USER user not in passwd file. Can't create directory.";
632 0 chown ($uid, $gid, $::LC_DIR);
633 }
634 }
635  
636 0 ▶sub delete_workingdir () {
Subroutine delete_workingdir: not called CC=3 SCAR=24.8
637 0 ▶ if (-d $::LC_DIR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $main::LC_DIR) { } 0 0 0
638 #fixme: delete even in the presence of certain dotfiles:
639 # .bashrc .xauth
640 0 ▶ rmdir($::LC_DIR) or warn "working directory ($::LC_DIR) deletion failed $!";
Branch: 1 branch
BranchTrueFalseTotal
rmdir $main::LC_DIR or warn "working directory ($main::LC_DIR) deletion failed $!" 0 0 0
641 } else {
642 0 warn "LinkController Working directory $::LC_DIR not present";
643 }
644 }
645  
646  
647  
648  
↑ Summary blib/lib/WWW/Link_Controller/ReadConf.pm »