Skip to content

Instantly share code, notes, and snippets.

@tianon
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tianon/c03ab15943b8a72d47b4 to your computer and use it in GitHub Desktop.
Save tianon/c03ab15943b8a72d47b4 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
deb="$(mktemp --tmpdir build-deps-XXXXXXXXXX.deb)"
trap "rm -f '$deb'" EXIT
"$(dirname "$(readlink -f "$BASH_SOURCE")")/make-build-deps.sh" "$deb"
dpkg --unpack "$deb"
depsPackage="$(dpkg-deb -f "$deb" Package)"
if ! apt-get install -f "$@"; then
dpkg --remove "$depsPackage"
echo >&2 "error: failed to 'apt-get install -f'"
exit 1
fi
if ! dpkg -s "$depsPackage" &> /dev/null; then
echo >&2 "error: failed to install 'build-deps' package"
exit 1
fi
#!/bin/bash
set -e
# https://sources.debian.net/src/devscripts/2.15.3/scripts/mk-build-deps.pl/
deb="$1"
if [ -z "$deb" ]; then
echo >&2 "usage: $0 target-deb"
echo >&2 " ie: $0 /path/to/some/output.deb"
exit 1
fi
read_control() {
local field="$1"
awk -F ': +' '
$0 == "" { exit }
/^#/ { next }
/^ +/ && field != "" { value = value $0; next }
field && field == "'"$field"'" {
gsub(/(, *)+/, ", ", value);
gsub(/^ +/, " ", value);
gsub(/^,? |,? $/, "", value);
print value;
exit;
}
$2 != "" { field = $1; value = $2 }
' debian/control
}
read_changelog() {
local field="$1"
if command -v dpkg-parsechangelog &> /dev/null; then
dpkg-parsechangelog -S "$field"
else
f=
case "$field" in
Source) f=1 ;;
Version) f=2 ;;
*) echo >&2 "warning: unknown field $field"; return ;;
esac
local value="$(head -n1 debian/changelog | cut -d' ' -f"$f")"
value="${value#(}"
value="${value%)}"
echo "$value"
fi
}
package="$(read_control 'Source')"
version="$(read_control 'Version')"
if [ -z "$version" ]; then
if [ -f debian/changelog -a "$(read_changelog 'Source')" = "$package" ]; then
version="$(read_changelog 'Version')"
else
version='1.0'
fi
fi
buildDepends="$(read_control 'Build-Depends'), $(read_control 'Build-Depends-Indep')"
buildDepends="${buildDepends%, }"
buildDepends="${buildDepends#, }"
buildConflicts="$(read_control 'Build-Conflicts'), $(read_control 'Build-Conflicts-Indep')"
buildConflicts="${buildConflicts%, }"
buildConflicts="${buildConflicts#, }"
arch='all'
if [[ "$buildDepends" =~ \[|\] ]]; then
arch="$(dpkg-architecture -qDEB_HOST_ARCH)"
fi
tmpDir="$(mktemp -d)"
trap "rm -rf '$tmpDir'" EXIT
ourPackage="${package}-build-deps"
mkdir -p "$tmpDir/$ourPackage/DEBIAN"
{
cat <<-EOF
Architecture: $arch
Depends: build-essential, $buildDepends
Maintainer: N/A
Package: $ourPackage
Priority: optional
Section: devel
Standards-Version: 3.9.6
Version: $version
EOF
[ -z "$buildConflicts" ] || echo "Conflicts: $buildConflicts"
echo "Description: build-dependencies for $package"
echo " Depencency package to build the '$package' package"
} | tee "$tmpDir/$ourPackage/DEBIAN/control"
echo
#deb="$tmpDir/$ourPackage.deb"
dpkg-deb --build "$tmpDir/$ourPackage" "$deb"
#dpkg-deb --info "$deb"
#dpkg-deb --contents "$deb"
# test it in debian:sid via Docker, just for kicks
#docker run -it --rm -v "$(readlink -f "$deb")":/temp.deb:ro debian:sid bash -c 'dpkg -i /temp.deb || { apt-get update && apt-get install -f; }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment