When developing .deb packages, relying on lsb_release
for system information is common practice. However, some Debian installations - particularly older versions like Debian 6.x - may not include this utility by default. This occurs because the lsb-release
package isn't part of the minimal/base installation in certain Debian releases.
Before implementing workarounds, check if the package exists but isn't installed:
# Check package availability
apt-cache search lsb-release
# Install if available
sudo apt-get install lsb-release
For robust package compatibility, consider these alternative approaches:
1. Using /etc/os-release
#!/bin/bash
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "Distribution: $ID"
echo "Version: $VERSION_ID"
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
echo "Distribution: $DISTRIB_ID"
echo "Version: $DISTRIB_RELEASE"
else
echo "Unable to determine distribution"
fi
2. Parsing /etc/debian_version
#!/bin/bash
if [ -f /etc/debian_version ]; then
DEBIAN_VERSION=$(cat /etc/debian_version)
echo "Debian Version: $DEBIAN_VERSION"
fi
For your .deb package's pre-install script, consider this pattern:
get_distro_info() {
if command -v lsb_release >/dev/null 2>&1; then
lsb_release -ds
elif [ -f /etc/os-release ]; then
. /etc/os-release
echo "$PRETTY_NAME"
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
echo "$DISTRIB_DESCRIPTION"
else
echo "Unknown distribution"
fi
}
In your control
file, you can specify:
Depends: lsb-release (>= 1.4) | sed, grep, coreutils
This makes lsb-release recommended but not strictly required, with fallback to basic utilities.
Use Docker to test your package against different Debian versions:
docker run -it debian:6 bash -c "apt-get update && apt-get install -y lsb-release || echo 'Not available'"
1. Always test your package on minimal Debian installations
2. Document the lsb-release requirement clearly in your README
3. Consider including the detection script within your package
4. For long-term support, move towards using /etc/os-release
When developing .deb packages that rely on lsb_release
for system information, you might encounter scenarios where this command is missing on certain Debian installations. This isn't necessarily a broken build - some minimal Debian installations deliberately exclude the LSB (Linux Standard Base) package suite.
Debian 6.0 (Squeeze) and other versions sometimes ship without LSB tools in these cases:
- Minimal server installations
- Custom stripped-down builds
- Cloud or container-optimized images
- Systems where
lsb-core
wasn't explicitly installed
Instead of relying solely on lsb_release
, consider these fallback methods in your package scripts:
1. Checking /etc/os-release
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "Distribution: $NAME"
echo "Version: $VERSION_ID"
elif command -v lsb_release >/dev/null 2>&1; then
lsb_release -ds
else
echo "Unable to determine distribution" >&2
fi
2. Parsing /etc/debian_version
if [ -f /etc/debian_version ]; then
DEBIAN_VERSION=$(cat /etc/debian_version)
echo "Debian version: $DEBIAN_VERSION"
fi
Here's how to handle the dependency in your package's control file:
Package: your-package
Version: 1.0
Depends: lsb-release | libc6 (>= 2.3.4)
Include this check in your pre-installation script:
#!/bin/sh
set -e
if ! command -v lsb_release >/dev/null 2>&1; then
echo "Warning: lsb_release not found. Falling back to alternative methods." >&2
# Add your fallback logic here
fi
If absolutely necessary, you can add this to your postinst script:
if ! dpkg -l lsb-release >/dev/null 2>&1; then
apt-get update && apt-get install -y --no-install-recommends lsb-release
fi
Remember to document these fallback mechanisms in your package's README and man pages to set proper user expectations.