File: dh-exec-install-rename

package info (click to toggle)
dh-exec 0.31
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 324 kB
  • sloc: ansic: 530; perl: 178; makefile: 126; sh: 67
file content (78 lines) | stat: -rwxr-xr-x 2,668 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/perl -wnp
##
## This script looks for SOURCE => DEST lines in its input, and copies SOURCE to
## a temporary directory under debian/tmp, with the desired DEST name. It will
## create directories appropriately. If called as dh-exec-install-move, will
## move files instead of copying, and also accept the => DEST form.
##
## It is done this way, so that we leave the boring work to
## dh_install, and all of its options will continue to work. And we
## put this under debian/tmp, because that gets cleaned up by dh_prep.
BEGIN {
    use File::Spec;
    use File::Basename qw/basename/;
    use File::Temp qw/tempdir/;
    use File::Copy qw/cp move/;
    use File::Path qw/make_path/;

    make_path("debian/tmp");
    our $tempdir = tempdir ("debian/tmp/dh-exec.XXXXXXXX");
    our $append_destpath = TRUE;
    if ($ENV{DH_EXEC_SOURCE} =~ /manpages$/) {
        $append_destpath = FALSE;
    }

    our $noop = 1;
    our $move = 0;
    $move = 1 if ($0 =~ /dh-exec-install-move$/);
}

if (defined ($ENV{"DH_CONFIG_ACT_ON_PACKAGES"}) &&
    defined ($ENV{"DH_EXEC_SOURCE"})) {
    my @packages = split(/,/, $ENV{"DH_CONFIG_ACT_ON_PACKAGES"});
    my (undef, undef, $currpkg) = File::Spec->splitpath ($ENV{"DH_EXEC_SOURCE"});
    $currpkg = basename ($currpkg, (".install", ".manpages"));

    $noop = 0 if ($currpkg eq "install" || $currpkg eq "manpages");

    foreach my $pkg (@packages) {
        $noop = 0 if ($pkg eq $currpkg);
    }
} else {
    $noop = 0;
}

if (/([^\s]*)\s+=>\s+([^\s]*)/ || /^=>\s+([^\s]*)/) {
    my ($src, $dst, $move_this);
    if (defined ($2)) {
        ($src, $dst, $move_this) = ($1, $2, $move);
    } else {
        ($src, $dst, $move_this) = ($1, $1, 1);
    }
    my (undef, $srcpath, undef) = File::Spec->splitpath ($src);
    my (undef, $dstpath, $dstfile) = File::Spec->splitpath ($dst);
    my $debpath = File::Spec->catdir ($tempdir, $dstpath);

    if ($noop) {
        $_ = $src;
        $_ .= "\n";
    } else {
        make_path($debpath);

        if ($move_this) {
            move ($src, File::Spec->catfile ($debpath, $dstfile)) or
		move (File::Spec->catfile ("debian/tmp", $src),
		      File::Spec->catfile ($debpath, $dstfile)) or
                die "Failed to move '$src': $!";
        } else {
            cp ($src, File::Spec->catfile ($debpath, $dstfile)) or
                move (File::Spec->catfile ("debian/tmp", $src),
                      File::Spec->catfile ($debpath, $dstfile)) or
                      die "Failed to copy '$src': $!";
        }
        $_ = File::Spec->catfile ($debpath, $dstfile);
        $_ .= " " . $dstpath if ($append_destpath eq TRUE);
        $_ .= "\n";
    }

}