X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=packaging%2Fcommon%2Fsubstitute.pl;fp=packaging%2Fcommon%2Fsubstitute.pl;h=7cc7750c366a753d7613e221360a59ec0524420e;hb=691567b16c13087b31ee4c2b6d038e57872fae82;hp=680d4acacac509137acf66aa7f45604e9abd295f;hpb=cc7d7b45afc706099acf7ff2490ec5667d370651;p=debian%2Famanda diff --git a/packaging/common/substitute.pl b/packaging/common/substitute.pl index 680d4ac..7cc7750 100755 --- a/packaging/common/substitute.pl +++ b/packaging/common/substitute.pl @@ -17,9 +17,9 @@ if ( not -e "packaging/common/substitute.pl" ) { sub get_date { my $date; - # Set the date using date -r - open(my $DATE_PIPE, "-|", "/bin/date '+%a, %d %b %Y %T %z'"); - [ $? == 0 ] or die "could not read output of date '+%a, %d %b %Y %T %z'"; + # First parameter should be a date format string. + open(my $DATE_PIPE, "-|", "/bin/date $_[0]"); + [ $? == 0 ] or die "could not read output of date $_[0]"; chomp($date = <$DATE_PIPE>); close($DATE_PIPE); return $date; @@ -104,16 +104,18 @@ my %replacement_strings_deb = ( "%%DISTRO%%" => "", # Used in changelog "%%DEB_REL%%" => "", - "%%DATE%%" => "", - # Used in rules + "%%DATE%%" => "'+%a, %d %b %Y %T %z'", + # Used in server rules "%%PERL%%" => "", ); my %replacement_strings_rpm = ( + "%%DATE%%" => "'+%a %b %d %Y'", ); my %replacement_strings_sun = ( "%%ARCH%%" => "", + "%%DATE%%" => "'+%a, %d %b %Y %T %z'", ); my %replacement_strings; @@ -123,29 +125,32 @@ if ( $pkg_type eq "deb" ) { $replacement_strings{"%%PKG_REV%%"} = fix_pkg_rev($replacement_strings{"%%PKG_REV%%"}, "deb"); # Let's determine the distro: - # Ubuntu has /etc/lsb-release, debian does not - open(my $LSB_RELEASE, "<", "/etc/lsb-release") or - $replacement_strings{"%%DISTRO%%"} = "Debian"; - my $line; - if ( $replacement_strings{"%%DISTRO%%"} ne "Debian" ) { - $replacement_strings{"%%DISTRO%%"} = "Ubuntu"; - # We want the 2nd line - <$LSB_RELEASE>; - my @line = split /=/, <$LSB_RELEASE>; - chomp($line[1]); - $line[1] =~ s/\.//; - $replacement_strings{"%%DEB_REL%%"} = $line[1]; - close($LSB_RELEASE); - } else { - open(my $DEB_RELEASE, "<", "/etc/debian_version") or die "could not read \"/etc/debian_version\": $!"; - chomp($line = <$DEB_RELEASE>); - # Releases can have 3 fields. we want the first 2. - $line =~ s/(\d+)\.(\d+).*/$1$2/; - $replacement_strings{"%%DEB_REL%%"} = $line; - close($DEB_RELEASE); + my $release; + if ( -e "/usr/bin/lsb_release" ) { + # Yay! it's easy. + my $distro_id = `/usr/bin/lsb_release --id --short` or die "Could not run lsb_release!"; + chomp ($replacement_strings{"%%DISTRO%%"} = $distro_id); + + chomp($release = `/usr/bin/lsb_release --release --short`); + } + if ( $replacement_strings{"%%DISTRO%%"} eq "" ) { + # Let's hope it's debian. + open(my $DEB_RELEASE, "<", "/etc/debian_version") or die "Could not read \"/etc/debian_version\": $!"; + # Whew! + $replacement_strings{"%%DISTRO%%"} = "Debian"; + chomp($release = <$DEB_RELEASE>); + close($DEB_RELEASE); } - $replacement_strings{"%%DATE%%"} = get_date(); - # 32bit should use bitrock perl, while 64bit should use builtin. we + # Fix the release version string. + if ( $replacement_strings{"%%DISTRO%%"} eq "Ubuntu" ) { + $release =~ s/\.//; + } else { + # Releases can have 3 fields on Debian. we want the first 2. + $release =~ s/(\d+)\.(\d+).*/$1$2/; + } + $replacement_strings{"%%DEB_REL%%"} = $release; + $replacement_strings{"%%DATE%%"} = get_date($replacement_strings{"%%DATE%%"}); + # 32bit should use bitrock perl, while 64bit should use builtin. we # live on the edge and assume it's there. my $arch = get_arch(); if ( $arch eq "x86_64" ) { @@ -160,13 +165,14 @@ elsif ( $pkg_type eq "rpm" ){ %replacement_strings_common ); $replacement_strings{"%%PKG_REV%%"} = fix_pkg_rev($replacement_strings{"%%PKG_REV%%"}, "rpm"); + $replacement_strings{"%%DATE%%"} = get_date($replacement_strings{"%%DATE%%"}); } else { %replacement_strings = ( %replacement_strings_sun, %replacement_strings_common ); $replacement_strings{"%%PKG_REV%%"} = fix_pkg_rev($replacement_strings{"%%PKG_REV%%"}, "sun"); - $replacement_strings{"%%DATE%%"} = get_date(); + $replacement_strings{"%%DATE%%"} = get_date($replacement_strings{"%%DATE%%"}); my $arch = get_arch(); if ( $arch eq "sun4u" ) { $replacement_strings{"%%ARCH%%"} = "sparc";