Skip to content

Instantly share code, notes, and snippets.

@darealshinji
Last active April 18, 2016 16:12
Show Gist options
  • Save darealshinji/8222720 to your computer and use it in GitHub Desktop.
Save darealshinji/8222720 to your computer and use it in GitHub Desktop.
A simple alternative to apt-build for Debian-based systems.
#!/bin/sh
#
# Usage: sudo apt-get-build <package>
ROOTUID="0"
if [ "$(id -u)" -ne "$ROOTUID" ] ; then
echo "This script must be executed with root/sudo privileges!"
exit 1
fi
if [ ! -f /usr/bin/apt-rdepends ] ; then
echo "apt-rdepends is not installed!"
while true; do
read -p "Do you wish to install apt-rdepends? [y/N] " yn
case $yn in
[Yy]* ) apt-get install apt-rdepends; break;;
[Nn]* ) exit;;
* ) break;;
esac
done
fi
if [ "$1" = "" ] ; then
echo "Enter a package name."
exit 1
fi
while true; do
read -p "Do you wish to install ${1}? [Y/n] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) break;;
esac
done
echo "--------Prepare installation"
rndm=$(shuf -i0-999999 -n1)
blddpnds=$(apt-rdepends --build-depends -p --follow=DEPENDS ${1} 2> /dev/null | egrep 'NotInstalled' | \
sed -e 's/Build-Depends\://; s/\[[^][]*\]//; s/([^()]*)//; s/ //g' | tr "\n" ' ')
mkdir /tmp/${1}_${rndm} &&
cd /tmp/${1}_${rndm} &&
echo "--------Install build-dependencies"
apt-get -y build-dep ${1} &&
echo "--------Download and compile package"
apt-get -y -b source ${1} &&
echo "--------Delete *-dev packages"
rm *-dev_*.deb *-dbg_*.deb &&
echo "--------Install package"
dpkg -i *.deb &&
cd /tmp/ &&
rm -rf ${1}_${rndm} &&
echo "--------Remove build-dependencies"
apt-get -y autoremove --purge $blddpnds && apt-get -y autoremove --purge
echo "--------Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment