Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 121ce30
  • /
  • debian
  • /
  • dh_nginx
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:8e6ce3b8007973b11dbf5775e9bf112a05373a08
directory badge
swh:1:dir:7649c89a366831bc2895b43063c609f0e71616ae

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
dh_nginx
#! /usr/bin/perl

# dh_nginx - Nginx configuration helper
# Copyright (C) 2016 Christos Trochalakis <ctrochalakis@debian.org>
#
# This program is licensed under the terms of the GNU General
# Public License veserion 2+
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

use strict;
use File::Find;
use Debian::Debhelper::Dh_Lib;


=head1 NAME

dh_nginx - register configuration snippets to the nginx web server

=cut

sub nginx_depends
{
	return 'nginx-common (= ${source:Version})'
}

sub nginx_api_installdir
{
	return "/usr/lib/nginx/modules/";
}

sub nginx_modules_conf_installdir
{
	return "usr/share/nginx/modules-available/"
}

=head1 SYNOPSIS

B<dh_nginx> [S<I<debhelper options>>] [B<-n>|B<--noscripts>]

=head1 DESCRIPTION

B<dh_nginx> is a debhelper program that is responsible for correctly installing
Nginx configuration snippets and setting postinst, prerm and dependencies in
Nginx web server modules and web applications.

It supports the following configuration types

=over 4

=item *
Nginx modules

=head1 INVOCATION

  %:
     dh $@ --with nginx

=head1 FILES

=over 4

=item debian/I<package>.nginx

=item debian/nginx

=back

Lists files to be registered with the Nginx HTTP server. The file is
interpreted as line separated list of installation stanzas, where each entry
consists of whitespace separated values conforming to the file semantics below.

=head2 FILE SEMANTICS

Each line consists of a triple

I<type> I<file> [I<arguments>]

where the values are interpreted as follows:


=head3 I<type>

Denotes the type of file to be installed. Recognized values are B<mod> for
Nginx modules.

=head3 I<file>

Is interpreted as existing file name within the source package. No path
expansion is effectuated. Just like L<dh_install(1)>, B<dh_nginx> can not
rename files.

=head3 I<arguments>

Is inrerpreted as optional arguments if any, currently not used.

=head2 MODULES

Modules are handled specially and are determined by the B<mod> type. Modules must
have a I<.conf> suffix. In that case the file is interpreted as module load
file and is installed to I</etc/nginx/modules-available>. If the file is ending
with a I<.so> suffix it is interpreted as actual module shared object and is
installed to the Nginx module directory, an optional numeric priority can be
set as the last argument to handle module dependencies.

=head1 OPTIONS

=over 4

=item B<-e>, B<--noenable>

Install maintainer scripts accordingly, but do not enable the scripts or
configuration by default.

=item B<-n>, B<--noscripts>

Do not modify F<postinst>/F<postrm>/F<prerm> maintainer scripts.


=back

=head1 NOTES

Note that this command is not idempotent. L<dh_prep(1)> should be called
between invocations of this command. Otherwise, it may cause multiple
instances of the same text to be added to maintainer scripts.

=head1 AUTHOR

This manual and L<dh_nginx> was written by Christos Trochalakis.
dh_nginx is heavily influnced by dh_apache2 written by Arno Toell
<debian@toell.net>.

=cut


##
## main code starts here
##

init(options => {
	"e|noenable" => \$dh{NOENABLE},
});

foreach my $package ((@{$dh{DOPACKAGES}}))
{
	my %PACKAGE_TYPE = (
		has_a_module => [],
	);

	my $file = pkgfile($package, "nginx");
	my $tmp  = tmpdir($package);

	my @files_to_register = filedoublearray($file, ".") if $file;
	foreach my $line (@files_to_register)
	{
		my $type = lc(shift @{$line}) if $line->[0];
		my $source = shift @{$line} if $line->[0];
		my @arguments = @{$line};
		my $destination;

		$type = "modules" if $type eq "mod";
		my $installdir = $tmp . "/" . nginx_modules_conf_installdir();

		verbose_print("$type -- $source -- @arguments\n\n");

		if ($type eq "modules")
		{
			my $basesource = basename($source);

			if ($type eq "modules")
			{
				if ($basesource =~ m/\.conf$/)
				{
					my $enablename = $basesource;
					my $prio = $#arguments >= 0 ? $arguments[0] : 50;
					$destination = "$prio-$basesource";
					push @{$PACKAGE_TYPE{'has_a_module'}}, "$enablename:$destination";
					verbose_print("Installing module configuration $enablename into $installdir prio:$prio\n");
				}
				elsif ($basesource =~ m/\.so$/)
			{
					my $modinstalldir = $tmp . "/" . nginx_api_installdir();
					verbose_print("Installing module binary $source into $modinstalldir\n");
					if (! -d $modinstalldir)
					{
						complex_doit("mkdir","-p", $modinstalldir);
						complex_doit("chmod","755","$modinstalldir");
					}
					complex_doit("cp", $source, $modinstalldir);
					next;
				}

				# TODO
				error("module: \"$basesource\" needs .conf, .so or suffix") if $basesource !~ m/\.(conf|so)/;
			}

			if (! -d $installdir)
			{
				complex_doit("mkdir","-p",$installdir);
				complex_doit("chmod","755","$installdir");
			}
			complex_doit("cp",$source,$installdir);
			complex_doit("chmod","644","$installdir/$basesource");

		}
		else
		{
			error("Unknown parameter: $type\n");
		}

	}

        my @postinst_autoscripts;

        if ($#{$PACKAGE_TYPE{'has_a_module'}} >= 0)
        {
                if ($package !~ m/libnginx-mod-\w+?/)
                {
                        warning("Package $package appears to be an Nginx module. It should comply to the package naming scheme libnginx-mod-<modulename>\n");
                }
                addsubstvar($package, "misc:Depends", nginx_depends());

                my $modules = "";
                foreach my $module (@{$PACKAGE_TYPE{'has_a_module'}})
                {
                        $modules .= "$module ";
                }

                push @postinst_autoscripts, ["module", $modules];
        }

	if (! $dh{NOSCRIPTS})
	{
		foreach my $ref (@postinst_autoscripts)
		{
			for my $script_type (qw/postinst prerm postrm/)
			{
				if ($script_type eq "postinst" &&  $dh{NOENABLE})
				{
					next
				}

				my %replacements = (
					NAMES  => $ref->[1],
				);

				my $sed_command = "";
				foreach my $key (sort keys %replacements)
				{
					my $val = $replacements{$key};
					# Use a control char as separator for sed, to
					# reduce escaping issues. Everything else is
					# passed verbatim, i.e. it must not contain any
					# shell or sed special characters.
					my $sep = "\x17";
					$sed_command .= "s" . $sep . "#$key#" .
							      $sep . $val .
							      $sep . "g; ";
				}

				autoscript($package, "$script_type", "$script_type-nginx", $sed_command);
			}
		}
	}
}

# vim: syntax=perl sw=8 sts=8 sr noet

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API