1#!/bin/bash
2# Generates Debian source and binary packages of modp_b64.
3
4if [ -z "$1" ]; then
5        echo "Usage: gen-src-pkg.sh <output-dir>"
6        exit 1
7fi
8
9outdir="$1"
10pkgdir=modp-b64-0.0.1
11origtar=modp-b64_0.0.1.orig.tar.gz
12scriptdir="$( cd "$( dirname "$0" )" && pwd )"
13branch=release-R110-15278.B
14
15tmpdir=$(mktemp -d)
16echo Generating source package in "${tmpdir}".
17
18# Download platform2 source.
19cd "${tmpdir}"
20git clone --branch "${branch}" https://chromium.googlesource.com/chromiumos/platform2 || exit 1
21mkdir "${pkgdir}"
22cd "${pkgdir}"
23# Trim platform2, only common-mk is needed.
24cp -a ../platform2/{common-mk,.gn} .
25
26# Download modp_b64 source.
27git clone --branch "${branch}" https://chromium.googlesource.com/aosp/platform/external/modp_b64 || exit 1
28cd modp_b64
29rm -rf .git
30
31# Clean up temporary platform2 checkout.
32cd ../..
33rm -rf platform2
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# If building for docker, use the right install script.
44if [ ! -z "${MODP_DOCKER}" ]; then
45  mv "${tmpdir}/${pkgdir}/debian/modp-b64.install.docker" \
46     "${tmpdir}/${pkgdir}/debian/modp-b64.install"
47else
48  rm -f "${tmpdir}/${pkgdir}/debian/modp-b64.install.docker"
49fi
50
51
52# Build source package and binary package.
53cd "${tmpdir}/${pkgdir}"
54dpkg-buildpackage --no-sign || exit 1
55
56# Copy the results to output dir.
57cd "${tmpdir}"
58mkdir -p "${outdir}/src"
59cp *.dsc *.orig.tar.gz *.debian.tar.xz "${outdir}/src"
60cp *.deb "${outdir}"
61cd /
62
63echo Removing temporary directory "${tmpdir}".
64rm -rf "${tmpdir}"
65
66echo Done. Check out Debian source package in "${outdir}".
67