- # 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);