summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/drakxservices
blob: b551055d6f2309e187d64961f650a5288c7eb9f2 (plain)
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
#!/usr/bin/perl

use lib qw(/usr/lib/libDrakX);

use common qw(:common :functional :file);
use interactive;
use log;

local $_ = join '', @ARGV;

/-h/ and die "usage: drakxservices\n";

$::isStandalone = 1;

my $in = vnew interactive('su');

my @l = grep { !/\.rpm/ } map { chop; $_ } `cd /etc/rc.d/init.d ; grep -l "chkconfig:" *`;
my @before = map { bool(@_ = glob("/etc/rc.d/rc*.d/S*$_"))  } @l;

my $after = $in->ask_many_from_list("drakxservices",
_("Choose which services should be automatically started at boot time"),
    \@l, \@before);

mapn { 
    my ($name, $before, $after) = @_;
    if ($before != $after) {
	if ($after) {
	    if (cat_("/etc/rc.d/init.d/$name") =~ /^chkconfig:\s+-/m) {
		system("chkconfig --add $name");
	    } else {
		`/sbin/runlevel` =~ /\s(\d+)/ or die "bad runlevel";
		$1 == 3 || $1 == 5 or log::l("strange runlevel: ``$1'' (neither 3 nor 5)");
		system("chkconfig --level $1 $name on");
	    }
	} else {
	    system("chkconfig --del $name");
	}
    }
} \@l, \@before, $after if $after;

$in->exit(0);