From dc74a67ae5e1e13b8fb815236dd8efdfce962ba0 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sat, 4 Jun 2016 16:22:47 +0300 Subject: Initial commit --- dh_runit | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 dh_runit (limited to 'dh_runit') diff --git a/dh_runit b/dh_runit new file mode 100755 index 0000000..dec7c5a --- /dev/null +++ b/dh_runit @@ -0,0 +1,96 @@ +#!/usr/bin/perl -w + +=head1 NAME + +dh_runit - install/enable runit runscripts + +=cut + +use strict; +use Debian::Debhelper::Dh_Lib; +use File::Find; +use Path::Tiny; +use File::stat; + +=head1 SYNOPSIS + +B [S>] [B<--no-enable>] + +=head1 DESCRIPTION + +B is a debhelper program that is responsible for +installing and enabling I runscripts. If file named +F.runit> exists, then different actions +are performed, depending on its format. + +For runit, every unit of supervision, simply speaking program, is +represented by directory under F, containing at least F +executable file. Every enabled program is represented by symbolic link +under F pointing to some directory under F. + +If F.runit> is not executable, but contains shebang +(#!) in first line, it is installed as F/run> and +enabled. + +Alternatively, F.runit> is a list of lines, where +every line is either starts with hash symbol and considered comment, +or contains two or three space-separated words. + + # In this case file is installed as 'run' script. Directory name under + # /etc/sv is derived from file basename + enable path/to/file/to/be/installed/as/run/script + + # Same, but install directory as whole. It is your responsibility + # to ensure is contains everything required. + enable path/to/directory + + # Same as above, but do not create symlink under /etc/service + disable path/to/directory + + # Also, you can explicitly specify name of directory under /etc/sv + enable path/to/directory my-preferred-name + +=head1 OPTIONS + +=over 4 + +=item B<--no-enable> + +Do not enable any runscripts. Useful, when F.runit> +is the only runscript, in which case you have no other ways to +specify, that it should not be enabled. + +=back + +=cut + +init(option => { 'no-enable' => \$dh{NO_ENABLE} }); + +PKG: foreach my $pkg (@{$dh{DOPACKAGES}}) { + next if is_udeb($pkg); + + my $tmp = tmpdir($pkg); + my $sv_dir = "$tmp/etc/sv"; + my $runit = pkgfile($pkg, 'runit'); + next unless $runit; + + doit('install', '-d', $sv_dir); + + for my $line (path($runit)->lines) { + next if ($line =~ /^#/); # skip comments + next if ($line =~ /^\s*$/); # skip empty lines + (my $enable, my $path, my $name) = split /\s/, $line; + $name = $name || basename($path); + + error("can't read `$path'") unless -r $path; + + if ( -f $path) { + doit('install', 'd', '-m755', $path, "$sv_dir/$name/run"); + } elsif ( -d $path) { + doit('cp', '-r', $path, "$sv_dir/$name"); + } + if ($enable -eq 'enable' && !$DH{NO_ENABLE}) { + } + } +} + -- cgit v1.2.3