File: lighty-enable-mod

package info (click to toggle)
lighttpd 1.4.13-4etch12
  • links: PTS
  • area: main
  • in suites: etch
  • size: 4,480 kB
  • ctags: 3,537
  • sloc: ansic: 37,630; sh: 8,915; perl: 2,215; yacc: 584; makefile: 374; php: 9
file content (108 lines) | stat: -rw-r--r-- 2,268 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w
#
#	Copyright (c) 2006 Krzysztof Krzyzaniak
#
#	Contains changes from:
#		- Tobias Gruetzmacher <tobias@portfolio16.de>
#
#	You may distribute under the terms of either the GNU General Public
#	License[1] or the Artistic License[2].
#
#	[1] http://www.gnu.org/licenses/gpl.html
#	[2] http://www.perl.com/pub/a/language/misc/Artistic.html
#

use strict;
use Term::ReadLine;
use File::Basename;
use File::Glob ':glob';
use File::stat;

#--- some initializations
my $confdir = "/etc/lighttpd/";
my %available = ();
my %enabled = ();
my @todo = ();

my %moduledeps = ();

my $enabling = 1;


#--- first check if we enabling or disabling
if ($0 =~ /disable-mod$/) {
	#--- disabling mode
	$enabling = 0;
}


#--- list of available modules
my @files = bsd_glob($confdir.'conf-available/*.conf');
print "Available modules: ";
foreach my $file (@files) {		
	if (basename($file) =~ /^\d+\-([\w\-]+)\.conf$/) {		
		$available{$1} = $file;
		print qq{$1 };
	}			
}
print "\n";

#--- list of already enabled modules
@files = bsd_glob($confdir.'conf-enabled/*.conf');
print "Already enabled modules: ";
foreach my $file (@files) {
	if (basename($file) =~ /^\d+\-([\w\-]+)\.conf$/) {		
		$enabled{$1} = $file;
		print qq{$1 };		
	}
}
print "\n";

unless (defined($ARGV[0])) {
	my $prompt =  $enabling ? 'Enable module: ' : 'Disable module: ';
	my $term = new Term::ReadLine $prompt;
	my $OUT = $term->OUT || \*STDOUT;
	my $var = lc($term->readline($prompt));
	@todo = split(/ /, $var);
}
else {
	@todo = @ARGV;
}


#--- activate (link) or deactivate (remove) module
foreach my $do (@todo) {
	
	my $target = sprintf("%s/conf-enabled/%s", $confdir,basename($available{$do}));
	if ($enabling) {
		print qq{Enabling $do: };
		
		my $st = stat($target);
		unless ( -f $target ) {
			if (symlink($available{$do}, $target)) {
				print "ok\n";
			}
			else {
				print "failure: $!\n";
			}
		}
		else {
			print "already enabled\n";
		}

		#--- check dependencies
		for my $module (@{$moduledeps{$do}})
		{
			unless ( -f $target && -l $target )
			{
				print qq{Module $do depends on module $module which is not activated.\n};
			}
		}
	}
	else {
		print qq{Disabling $do\n};
		unlink($target);
	}
}

print "Run /etc/init.d/lighttpd force-reload to enable changes\n";