1#!/bin/bash 2# Generates Debian source and binary packages of android sysprop tool. 3 4if [ -z "$1" ]; then 5 echo "Usage: gen-src-pkg.sh <output-dir>" 6 exit 1 7fi 8 9outdir="$1" 10pkgdir=sysprop-0.0.1 11origtar=sysprop_0.0.1.orig.tar.gz 12scriptdir="$( cd "$( dirname "$0" )" && pwd )" 13branch=platform-tools-34.0.0 14 15tmpdir=$(mktemp -d) 16echo Generating source package in "${tmpdir}". 17 18cd "${tmpdir}" 19# Download libbase source. 20git clone --branch "${branch}" https://android.googlesource.com/platform/system/libbase || exit 1 21 22# Download sysprop source. 23git clone --branch "${branch}" https://android.googlesource.com/platform/system/tools/sysprop "${pkgdir}" || exit 1 24cd "${pkgdir}" 25rm -rf .git 26 27cp -ra ../libbase/include/android-base include 28echo "#include <iostream>" > include/android-base/logging.h 29echo "#define LOG(x) std::cerr" >> include/android-base/logging.h 30echo "#define PLOG(x) std::cerr" >> include/android-base/logging.h 31cp -ra ../libbase/{file,strings,stringprintf,posix_strerror_r}.cpp . 32 33cd .. 34 35# Debian requires creating .orig.tar.gz. 36tar czf "${origtar}" "${pkgdir}" 37 38# Debianize the source. 39cd "${pkgdir}" 40yes | debmake || exit 1 41cp -aT "${scriptdir}/debian/" "${tmpdir}/${pkgdir}/debian/" 42 43# Build source package and binary package. 44cd "${tmpdir}/${pkgdir}" 45dpkg-buildpackage --no-sign || exit 1 46 47# Copy the results to output dir. 48cd "${tmpdir}" 49mkdir -p "${outdir}/src" 50cp *.dsc *.orig.tar.gz *.debian.tar.xz "${outdir}/src" 51cp *.deb "${outdir}" 52cd / 53 54echo Removing temporary directory "${tmpdir}". 55rm -rf "${tmpdir}" 56 57echo Done. Check out Debian source package in "${outdir}". 58