File: dht

package info (click to toggle)
pkg-haskell-tools 0.12.5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 160 kB
  • sloc: haskell: 691; sh: 591; perl: 308; makefile: 10
file content (117 lines) | stat: -rwxr-xr-x 2,307 bytes parent folder | download
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
#!/usr/bin/perl

use v5.10.1;

use strict;

use File::Basename;
use FindBin  qw($Bin);;

our $DHT_SCRIPT_DIR;
$ENV{PERL5LIB} = ":$ENV{PERL5LIB}" if $ENV{PERL5LIB};
if ($Bin eq "/usr/bin") {
	$DHT_SCRIPT_DIR="/usr/lib/pkg-haskell-tools/bin";
	$ENV{PERL5LIB} = "/usr/lib/pkg-haskell-tools/lib" . ($ENV{PERL5LIB} || "");
} else {
	$DHT_SCRIPT_DIR = "$Bin/scripts";
	$ENV{PERL5LIB} = "$Bin/lib" . ($ENV{PERL5LIB}|| "");
	$ENV{PATH} = "$Bin:$ENV{PATH}";
}

$ENV{DHT_SCRIPT_DIR} = $DHT_SCRIPT_DIR;

our @DHT_SCRIPTS = ();
opendir(DIR, $DHT_SCRIPT_DIR) or die $!;
while (my $file = readdir(DIR)) {
	next if ($file =~ m/^\./);
	push @DHT_SCRIPTS, $file;
}
closedir(DIR);
@DHT_SCRIPTS = sort @DHT_SCRIPTS;


if (not @ARGV or $ARGV[0] eq "--help" or $ARGV[0] eq "-h" ) {
	my $prog = basename($0);
	print <<__END__;
Usage: $0 subcommand [args..]

This is the Debian Haskell Team multi purpose tool, combining various more or
less useful tools.

Supported subcommands:
__END__

	for my $script (@DHT_SCRIPTS) {
		# print first line of help
		open (HELP, '-|', "$DHT_SCRIPT_DIR/$script", "--help") or die $!;
		print "  " . (scalar(<HELP>) || "$script --help failed");
		close HELP;
	}

	print "\n";
	print "Run $prog subcommand --help for more information.\n";
	exit(0);
}

if (not @ARGV or $ARGV[0] eq "--manpage" ) {
	my $prog = basename($0);
	print <<__END__;
% DHT(1)
% Debian Haskell Group

# NAME

dht -- Debian Haskell Packaging Tools

# SYNOPSIS

$0 subcommand [args..]

# DESCRIPTION

This is the Debian Haskell Team multi purpose tool, combining various more or
less useful tools.

Supported subcommands:

__END__

	for my $script (@DHT_SCRIPTS) {
		# print first line of help
		open (HELP, '-|', "$DHT_SCRIPT_DIR/$script", "--help") or die $!;
		print " *  " . (scalar(<HELP>) || "$script --help failed");
		close HELP;
	}

	print <<__END__;

# Subcommands

__END__

	for my $script (@DHT_SCRIPTS) {
		print <<__END__;

## dht $script

__END__
		system ("$DHT_SCRIPT_DIR/$script", "--manpage");
	}

	exit (1);
}

if (not @ARGV or $ARGV[0] eq "--version" ) {
	print "$0 version UNKNOWN";
	exit(0);
}

my $cmd = shift @ARGV;
unless (grep {$_ eq $cmd} @DHT_SCRIPTS) {
	print "Subcommand $cmd not known.\n";
	print "Run $0 to see a list of supported commands.\n";
	exit(1)
}


exec "$DHT_SCRIPT_DIR/$cmd",@ARGV;