[Pkg-sysvinit-commits] r1632 - sysvinit/trunk/debian/sysv-rc
Petter Reinholdtsen
pere at alioth.debian.org
Mon Aug 24 18:24:22 UTC 2009
Author: pere
Date: 2009-08-24 18:24:21 +0000 (Mon, 24 Aug 2009)
New Revision: 1632
Modified:
sysvinit/trunk/debian/sysv-rc/saveconfig
Log:
New mode, -s to save the individual script settings into a directory.
Modified: sysvinit/trunk/debian/sysv-rc/saveconfig
===================================================================
--- sysvinit/trunk/debian/sysv-rc/saveconfig 2009-08-24 05:33:33 UTC (rev 1631)
+++ sysvinit/trunk/debian/sysv-rc/saveconfig 2009-08-24 18:24:21 UTC (rev 1632)
@@ -7,8 +7,27 @@
# "update-rc.d" command line.
#
# Author: Miquel van Smoorenburg <miquels at cistron.nl>
+# Adjusted by Petter Reinholdtsen
#
+sub usage {
+ print STDERR "error: ", @_, "\n" if @_;
+ print STDERR <<EOF;
+saveconfig [-h] [-s <archivedir>]
+ -s save each scripts setting in directory <archivedir>
+ -h show usage inforation
+EOF
+}
+
+my $archivedir = "";
+
+while($#ARGV >= 0 && ($_ = $ARGV[0]) =~ /^-/) {
+ shift @ARGV;
+ if (/^-s$/) { $archivedir = shift; usage("Missing -s argument"), exit 1 unless $archivedir; next }
+ if (/^-h|--help$/) { &usage; }
+ &usage("unknown option");
+}
+
chdir "/etc/init.d";
sub scan {
@@ -47,19 +66,31 @@
}
}
}
-
- print "update-rc.d $s " if ($start || $stop);
- if ($start > 0) {
- print "start ";
- foreach my $x (sort keys %start) {
- print "$x ", $start{$x}, ". ";
+ my $entry;
+ if ($start || $stop) {
+ $entry = "update-rc.d $s ";
+ if ($start > 0) {
+ $entry .= "start ";
+ foreach my $x (sort keys %start) {
+ $entry .= "$x " . $start{$x} . ". ";
+ }
}
- }
- if ($stop > 0) {
- print "stop ";
- foreach my $x (sort keys %stop) {
- print "$x ", $stop{$x}, ". ";
+ if ($stop > 0) {
+ $entry .= "stop ";
+ foreach my $x (sort keys %stop) {
+ $entry .= "$x " . $stop{$x} . ". ";
+ }
}
+ $entry .= "\n";
+ if ($archivedir) {
+ my $file = "$archivedir/$s";
+ open(FILE, ">", "${file}.new") ||
+ die "Unable to write to $file";
+ print FILE $entry;
+ close(FILE);
+ rename "${file}.new", "$file";
+ } else {
+ print $entry;
+ }
}
- print "\n" if ($start || $stop);
}
More information about the Pkg-sysvinit-commits
mailing list