3 # DSF-Helper, a Debhelper-inspired helper for Debian Sourceforge
5 # Roland Mas <lolando@debian.org>
6 # This code is copyright Roland Mas 2002
7 # You are welcome to use, modify and redistribute this file under the terms of
8 # the GNU General Public License version 2.
11 use vars qw! @known_files @file_list @package_list %chunks ! ;
12 use subs qw! &pkgfile &get_chunk ! ;
18 @known_files = qw/ config templates preinst postinst prerm postrm links init.d logrotate / ;
26 $package =~ s/^.[^-]*-// ;
28 if (-f "debian/dsf-in/$package.$filename.dsfh-in") {
29 return "debian/dsf-in/$package.$filename.dsfh-in";
32 if (-f "debian/dsf-in/$package.$filename") {
33 return "debian/dsf-in/$package.$filename";
43 my $function = shift ;
45 unless (defined $chunks{$varname}) {
46 # First time this variable is encountered, creating slot
47 # print "Creating data structure for var $varname.\n" ;
48 $chunks{$varname} = {} ;
51 unless (defined $chunks{$varname}{$function}) {
52 # First time this instance is accessed, loading data
53 # print "Loading data for var $varname and function $function.\n" ;
54 $chunks{$varname}{$function} = '' ;
55 my $fname = "debian/dsf-helper/$varname.$function" ;
57 print "File $fname file not found, aborting.\n" ;
63 $chunks{$varname}{$function} .= $_ ;
68 return $chunks{$varname}{$function} ;
73 @package_list = split /\n/, qx! dh_listpackages ! ;
74 my $package_name = qx! grep ^PACKAGE= debian/rules | cut -d= -f2 ! ;
75 $package_name =~ s/\n//;
76 my $old_package_name = qx! grep ^OLDPACKAGE= debian/rules | cut -d= -f2 ! ;
77 $old_package_name =~ s/\n//;
78 my $forge_name = qx! grep ^FORGENAME= debian/rules | cut -d= -f2 ! ;
79 $forge_name =~ s/\n//;
80 my $source_path = qx! grep ^source_path etc/config.ini-fhs | cut -d= -f2 | xargs echo -n ! ;
81 my $binary_path = qx! grep ^binary_path etc/config.ini-fhs | cut -d= -f2 | xargs echo -n ! ;
82 my $plugin_path = qx! grep ^plugins_path etc/config.ini-fhs | cut -d= -f2 | xargs echo -n ! ;
83 my $data_path = qx! grep ^data_path etc/config.ini-fhs | cut -d= -f2 | xargs echo -n ! ;
84 my $config_path = qx! grep ^config_path etc/config.ini-fhs | cut -d= -f2 | xargs echo -n ! ;
85 my $log_path = qx! grep ^log_path etc/config.ini-fhs | cut -d= -f2 | xargs echo -n ! ;
87 if ($ARGV[0] && $ARGV[0] eq "--clean") {
88 EXTLOOP: for my $ext (@known_files) {
89 PKGLOOP: for my $pkg (@package_list) {
90 my $srcfile = &pkgfile ($pkg, $ext) ;
91 next PKGLOOP unless $srcfile ;
92 #my $destfile = $srcfile ;
93 my $destfile = "debian/$pkg.$ext" ;
94 #$destfile =~ s/\.dsfh-in$// ;
96 print "Removing $destfile\n" ;
104 EXTLOOP: for my $ext (@known_files) {
105 #print "Extension: $ext\n" ;
106 PKGLOOP: for my $pkg (@package_list) {
107 #print " Package: $pkg\n" ;
108 my $srcfile = &pkgfile ($pkg, $ext) ;
109 #print " SrcPackage: $srcfile\n" ;
110 next PKGLOOP unless $srcfile ;
111 # my $destfile = $srcfile ;
112 # $destfile =~ s/\.dsfh-in$// ;
113 my $destfile = "debian/$pkg.$ext" ;
114 print "$srcfile -> $destfile\n" ;
116 open S, "< $srcfile" ;
119 while (my $l = <S>) {
121 while ($l =~ m!\#DSFHELPER:([-_a-zA-Z0-9/]+)\#!) {
123 my $chunk = get_chunk ($chunkname, $ext) ;
124 $l =~ s!\#DSFHELPER:$chunkname\#!$chunk! ;
129 if ($ext eq "templates") {
130 # Need to remove a few extra blank lines
131 $dest =~ s/^#.*\n//gm ;
133 $dest =~ s/\n\n+/\n\n/g ;
135 $dest =~ s/\@PACKAGE\@/$package_name/g ;
136 $dest =~ s/\@OLDPACKAGE\@/$old_package_name/g ;
137 $dest =~ s/\@FORGENAME\@/$forge_name/g ;
138 $dest =~ s:\@SOURCE_PATH\@:$source_path:g ;
139 $dest =~ s:\@BINARY_PATH\@:$binary_path:g ;
140 $dest =~ s:\@PLUGIN_PATH\@:$plugin_path:g ;
141 $dest =~ s:\@DATA_PATH\@:$data_path:g ;
142 $dest =~ s:\@CONFIG_PATH\@:$config_path:g ;
143 $dest =~ s:\@LOG_PATH\@:$log_path:g ;
145 open D, "> $destfile" ;
151 print "package_name: $package_name\n" ;
152 print "forge_name: $forge_name\n" ;