Created
August 5, 2016 01:05
-
-
Save RogerGee/f3b292a9c23e5b3510db3ea6715cdf73 to your computer and use it in GitHub Desktop.
A shell script to create Debian packages (works on symlinks)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script builds a DEBIAN package. I use it as a replacement for | |
# dpkg-deb because dpkg-deb doesn't follow symlinks. | |
# make 'tar' follow symlinks | |
export TAR_OPTIONS=-h | |
# get a temporary directory | |
TMPDIR="$TEMPDIR" | |
if [ -z $TMPDIR ]; | |
then | |
TMPDIR=/tmp | |
fi | |
D=$(mktemp -d --tmpdir=$TMPDIR) | |
# verify structure (as much as possible) | |
if [ ! -d DEBIAN ]; | |
then | |
echo "$0: expected DEBIAN subdirectory" | |
exit | |
fi | |
if [ ! -f DEBIAN/control ]; | |
then | |
echo "$0: no control file" | |
exit | |
fi | |
# create archives | |
tar czf $D/data.tar.gz [[:lower:]]* | |
cd DEBIAN | |
tar czf $D/control.tar.gz * | |
cd .. | |
echo 2.0 > $D/debian-binary | |
# build the package name from the control file | |
PACKAGE_NAME=$(grep 'Package' DEBIAN/control | cut -d' ' -f2) | |
PACKAGE_VERSION=$(grep 'Version' DEBIAN/control | cut -d' ' -f2) | |
PACKAGE_ARCH=$(grep 'Architecture:' DEBIAN/control | cut -d' ' -f2) | |
# build the actual package | |
DEBFILE=$PACKAGE_NAME\_$PACKAGE_VERSION\_$PACKAGE_ARCH.deb | |
ar r $DEBFILE $D/debian-binary $D/control.tar.gz $D/data.tar.gz | |
echo "$0: created package '$DEBFILE'" | |
# cleanup (safely) | |
rm -f $D/* | |
rmdir $D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment