/usr/sbin/update-rcconf-guide is in rcconf 3.1ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | #!/usr/bin/perl -w
# update-rcconf-guide
# Copyright (c) 2004-2009 kamop@debian.org
#
=head1 NAME
update-rcconf-guide - Create default guide file for rcconf
=head1 SYNOPSIS
B<update-rcconf-guide>
=head1 DESCRIPTION
B<Update-rcconf-guide> creates the default guide file which B<rcconf> uses.
B<Update-rcconf-guide> searches the package names corresponding to each
service file in /etc/init.d directory from dpkg info
files(/var/lib/dpkg/info/*.list) and get the description of these packages
using apt-cache. B<Update-rcconf-guide> uses Short-Description in priority
to the description if service files has Short-Description field.
B<Update-rcconf-guide> writes those results to /var/lib/rcconf/guide.default
file.
You can write your own guide in user guide file(/var/lib/rcconf/guide) by hand.
B<Rcconf> refers Guides in /var/lib/rcconf/guide before those in
/var/lib/rcconf/guide.default.
If you install some packages after executed B<update-rcconf-guide>,
you need to re-create this file using B<update-rcconf-guide> so as to refresh
guide.default that includes new guides for installed new services.
Notice: B<update-rcconf-guide> was not executed when you installed B<rcconf>
package.
=head1 FILE
=over 8
=item /var/lib/rcconf/guide.default
Guide File update-rcconf-guide generates.
=item /var/lib/rcconf/guide
Guide File user(Administrator) can define.
=back
=head1 SEE ALSO
rcconf(8)
=head1 AUTHOR
Atsushi KAMOSHIDA <kamop@debian.org>
=cut
use strict;
use FileHandle;
use DirHandle;
my @unselects = ("\^\\\.\$", "\^\\\.\\\.\$", "\^rc\$", "\^rcS\$", "\^README\$",
"\^skeleton\$", ".*\\\.dpkg-dist\$", ".*\\\.dpkg-old\$",
".*\\\.dpkg-bak\$", ".*\\\.sh\$");
my $APTCACHE_BIN = "/usr/bin/apt-cache";
my $GREP_BIN = "/bin/grep";
my $RCCONF_DIR = "/var/lib/rcconf";
my $GUIDE_FILE = $RCCONF_DIR."/guide.default";
my $INITD_DIR = "/etc/init.d";
if ( ! -d $RCCONF_DIR ) {
die "Can't file rcconf dir($RCCONF_DIR).\n";
}
print "Reading $INITD_DIR and getting package description ...\n";
my $initd_files_array = &read_initd_dir($INITD_DIR);
my $filepath_hash = &create_dpkg_installed_filepath("/var/lib/dpkg/info");
print "Writing package default guide to $GUIDE_FILE ...\n";
my $fh = FileHandle->new(">".$GUIDE_FILE);
if ( ! defined($fh) ) {
die "Can't open file: $GUIDE_FILE .\n";
}
my $path;
my $description_header;
foreach my $initd_file ( @{$initd_files_array} ) {
# print $initd_file."\n";
next if ( &check_unselect($initd_file, \@unselects) == 1 );
# print $initd_file."\n";
$path = $INITD_DIR."/".$initd_file;
next if ( ! exists($filepath_hash->{$path}) );
$description_header = &get_description_header($filepath_hash->{$path}, $path) // '';
if ( $description_header ne "" ) {
print $fh $initd_file." ".$description_header."\n";
}
}
undef $fh;
print "Done.\n";
exit;
#######################################################################
## MODULE: get_description_header
## DESC:
## IN:
## OUT:
## OP:
## STATUS:
## END:
sub get_description_header {
my ($package, $path) = @_;
##
if ( $package eq "" ) {
die "arg(package) is null.\n";
}
## First, try to get Short-Description
my $line = `$GREP_BIN '^\# Short-Description:' $path`;
if ( $line ne "" ) {
$line =~ /^\# Short-Description:\s*(.*)/;
return $1;
}
if ( $package eq "tinyproxy" ) {
printf "%s %s %s\n", $package, $path, $line;
exit 1;
}
$line = `$APTCACHE_BIN show $package | $GREP_BIN '^Description:'`;
$line =~ /^Description:\s*(.*)/;
return $1;
} ## get_description_header
#######################################################################
## MODULE: check_unselect
## DESC: Check if 'file' exists in unselects array.
## IN:
## OUT: results 0 := file is not in the array.
## 1 := file exists in the array.
## OP:
## STATUS:
## END:
sub check_unselect{
my ($file, $unselects) = @_;
##
return 1 if ( ! -x $INITD_DIR . "/" . $file );
my $unselect;
foreach $unselect ( @{$unselects} ) {
return 1 if ( $file =~ /$unselect/ );
}
return 0;
} ## check_unselect
#######################################################################
## MODULE: read_initd_dir
## DESC: Collect files in init.d/ directory.
## IN:
## OUT:
## OP:
## STATUS:
## END:
sub read_initd_dir{
my ($initd_dir) = @_;
##
if ( ( $initd_dir eq "" ) || ( ! -d $initd_dir ) ) {
die "No such directory: $initd_dir .\n";
}
my $dh = DirHandle->new($initd_dir);
if ( ! defined($dh) ) {
die "No such directory: $initd_dir .\n";
}
my $file;
my @dirs = ();
while ( defined($file = $dh->read()) ) {
push(@dirs, $file);
}
undef $dh;
return(\@dirs);
} ## read_initd_dir
#######################################################################
## MODULE: read_initd_dir
## DESC: Collect files in inet.d/ directory.
## IN:
## OUT:
## OP:
## STATUS:
## END:
sub create_dpkg_installed_filepath {
my ($info_dir) = @_;
##
if ( ( $info_dir eq "" ) || ( ! -d $info_dir ) ) {
die "No such directory: $info_dir .\n";
}
my $dh = DirHandle->new($info_dir);
if ( ! defined($dh) ) {
die "Can't open directory: $info_dir .\n";
}
my $file;
my $package;
my %filepath_hash = ();
while ( defined($file = $dh->read()) ) {
if ( $file =~ /(.*)\.list$/ ) {
$package = $1;
# print "$package $file\n";
&insert_filepath($info_dir."/".$file, \%filepath_hash, $package);
}
}
undef $dh;
return(\%filepath_hash);
} ## create_dpkg_installed_filepath
#######################################################################
## MODULE: insert_filepath
## DESC:
## IN:
## OUT:
## OP:
## STATUS:
## END:
sub insert_filepath {
my ($info_filelist_file, $filepath_hash, $package) = @_;
##
if ( ( $info_filelist_file eq "" ) || ( ! -f $info_filelist_file ) ) {
die "No such directory: $info_filelist_file.\n";
}
if ( ref($filepath_hash) ne "HASH" ) {
die "arg(filepath_hash) isn't HASH ref.\n";
}
if ( $package eq "" ) {
die "arg(package) is null.\n";
}
my $fh = FileHandle->new($info_filelist_file);
if ( ! defined($fh) ) {
die "Can't open $info_filelist_file.\n";
}
my $line;
while ( $line = <$fh> ) {
## If we check $line whether file or not, go very slowly.
chomp($line);
$filepath_hash->{$line} = $package;
}
undef $fh;
} ## insert_filepath
|