#!/usr/bin/perl -w =head1 NAME dh_smf - install SMF services into package build directories =cut use strict; use Debian::Debhelper::Dh_Lib; use File::Find; use XML::Simple; =head1 SYNOPSIS B [S>] [B<--name=>I] [B<-n>] [B<-R>] [B<-r>] =head1 DESCRIPTION B is a debhelper program that is responsible for installing SMF manifests and scripts with associated defaults files. It also automatically generates the F and F and F commands needed to manage SMF services. =head1 FILES =over 4 =item debian/I.smf/ If this directory exists, it is installed as lib/svc/ in the package build directory. =item debian/I.default If this exists, it is installed into etc/default/I in the package build directory. =back =head1 OPTIONS =over 4 =item B<-n>, B<--noscripts> Do not modify F/F/F scripts. =item B<-o>, B<--onlyscripts> Only modify F/F/F scripts, do not actually install any files. May be useful if the file is shipped and/or installed by upstream in a way that doesn't make it easy to let B find it. =item B<-R>, B<--restart-after-upgrade> Do not stop the SMF service until after the package upgrade has been completed. This is different than the default behavior, which stops the service in the F, and starts it again in the F. This can be useful for daemons that should not have a possibly long downtime during upgrade. But you should make sure that the daemon will not get confused by the package being upgraded while it's running before using this option. =item B<-r>, B<--no-restart-on-upgrade> Do not stop the SMF service on upgrade. =item B<--no-start> Do not start the service on install or upgrade. Maybe useful if installing display managers like lightdm or GDM. =back =head1 NOTES Note that this command is not idempotent. L should be called between invocations of this command. Otherwise, it may cause multiple instances of the same text to be added to maintainer scripts. =cut # Same as pkgfile in /usr/share/perl5/Debian/Debhelper/Dh_Lib.pm, # but -f => -d sub pkgdir { my $package = shift; my $filename = shift; if ( defined $dh{NAME} ) { $filename = "$dh{NAME}.$filename"; } # First, check for files ending in buildarch and buildos. my $match; foreach my $file ( glob("debian/$package.$filename.*") ) { next if !-d $file; next if $dh{IGNORE} && exists $dh{IGNORE}->{$file}; if ( $file eq "debian/$package.$filename." . buildarch() ) { $match = $file; # buildarch files are used in preference to buildos files. last; } elsif ( $file eq "debian/$package.$filename." . buildos() ) { $match = $file; } } return $match if defined $match; my @try = ("debian/$package.$filename"); if ( $package eq $dh{MAINPACKAGE} ) { push @try, "debian/$filename"; } foreach my $file (@try) { if ( -d $file && ( !$dh{IGNORE} || !exists $dh{IGNORE}->{$file} ) ) { return $file; } } return ""; } init( options => { "r" => \$dh{R_FLAG}, "no-restart-on-upgrade" => \$dh{R_FLAG}, "no-start" => \$dh{NO_START}, "R|restart-after-upgrade" => \$dh{RESTART_AFTER_UPGRADE}, } ); foreach my $package ( @{ $dh{DOPACKAGES} } ) { my $tmp = tmpdir($package); # Copy manifests and methods into package directory my $smf = pkgdir( $package, 'smf' ); if ( $smf ne '' && !$dh{'ONLYSCRIPTS'} ) { my $svcdir = "$tmp/lib/svc"; if ( !-d "$svcdir" ) { doit( "install", "-d", "$svcdir" ); } complex_doit("cp -a -v -f $smf/* $svcdir/"); } # Get a list of all manifests in package my @manifests = (); find( { wanted => sub { -f $_ && /^.*\.xml\z/s && push @manifests, $File::Find::name; }, no_chdir => 1, }, "$tmp/lib/svc/manifest" ); # TODO: validate XML? # Read all services from all manifests: foreach my $manifest (@manifests) { my $xml = XMLin( $manifest, ForceArray => [qw/instance dependency exec_method propval property_group/] ); } if ( !$dh{NOSCRIPTS} ) { my @pkg_manifests = map { s!\Q$tmp\E/*!/!; $_ } @manifests; autoscript( $package, 'postinst', 'postinst-smf', "s|#MANIFESTS#|@pkg_manifests|" ); } } =head1 SEE ALSO L, L, L, L This program is a part of debhelper. =head1 AUTHORS Joey Hess (dh_installinit) Steve Langasek Michael Stapelberg Igor Pashev =cut