Skip to content

Instantly share code, notes, and snippets.

@Cloudef
Created September 6, 2016 09:53
Show Gist options
  • Save Cloudef/c8727e013e0da6c5e1e2d85d5f61e60a to your computer and use it in GitHub Desktop.
Save Cloudef/c8727e013e0da6c5e1e2d85d5f61e60a to your computer and use it in GitHub Desktop.
Fake makepkg enough to build and install android-protobuf from PKGBUILD
#!/bin/bash
# Fake makepkg enough to build and install android-protobuf PKGBUILD
# Go into sanity mode
set -eEuo pipefail
# Heuristics, do your job if not true.
PROTOC="$(which protoc)"
MAKEFLAGS="$@"
# Setup common makepkg variables
startdir="$PWD/build"
srcdir="$startdir"
pkgdir="$PWD/install"
# msg is used by some PKGBUILDs
msg() { printf -- "==> $1\n" "${@:2}" 1>&2; }
# Source the recipe
source ./PKGBUILD
# Prepare the work env
mkdir -p "$startdir"
cd "$startdir"
# Fetch the sources by assuming everything is a
# curl friendly url and tar -xf extractable
for s in "${source[@]}"; do
prefix="${s%::*}"
[[ "$prefix" == "$s" ]] && prefix=
url="${s##*::}"
fname="${prefix:-${url##*/}}"
curl -L "$url" -o "$fname"
ext="${fname##*.}"
case "$ext" in
tar)
tar -xf "$fname"
;;
zip)
unzip -qf "$fname"
;;
esac
done
# Build the thing
cd "$startdir"; prepare
cd "$startdir"; build
# Export to fakeroot
export ANDROID_NDK PROTOC MAKEFLAGS startdir srcdir pkgdir
export -f msg
# Package the thing inside fakeroot
cd "$startdir"; fakeroot -- bash << EOF
set -eEuo pipefail
source ../PKGBUILD
package
exit \$?
EOF
# Install to /usr/local and remove temporary $pkgdir
sudo cp -R "$pkgdir/"* /usr/local/
rm -r "$pkgdir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment