#/bin/sh set -e usage() { cat << EOF usage: install_vmod URL [SHA512SUM] environment variables: SKIP_CHECK: if non-empty, tests are not run before installing deps: - varnish development files - curl - pkg-config - nproc - make - gcc - automake - libtoolize - whatever dependencies the vmod needs EOF exit $1 } maybe_help() { if [ "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ]; then usage exit fi } check_bin() { if ! command "$@" >/dev/null 2>&1; then echo "please install $1" exit 1 fi } check_bin curl --version check_bin tar --version if ! pkg-config varnishapi; then echo "pkg-config couldn't find varnishapi (did you install the varnish dev file/package?)" exit 1 fi if [ $# != 1 -a $# != 2 ]; then usage 1 fi maybe_help "$1" maybe_help "$2" if [ -n "$1" ]; then URL="$1" else echo no TARBALL specified exit 1 fi SHA512SUM="$2" set -x rm -rf /tmp/module_to_build mkdir /tmp/module_to_build if [ -e "$URL" ]; then cp "$URL" /tmp/module_to_build/src.tar.gz else curl -fLo /tmp/module_to_build/src.tar.gz "$URL" fi cd /tmp/module_to_build if [ -n "$SHA512SUM" ]; then echo "$SHA512SUM src.tar.gz" | sha512sum -c - fi tar xavf src.tar.gz --strip 1 if [ -e Cargo.toml ]; then check_bin cargo cargo build --release else check_bin automake --version check_bin gcc --version check_bin libtoolize --version check_bin make --version check_bin nproc check_bin pkg-config --version check_bin rst2man --version if [ ! -x configure ]; then if [ -e autogen.sh ]; then ./autogen.sh ./configure elif [ -e bootstrap ]; then ./bootstrap # bootstrap may or may not have called configure if [ ! -e Makefile ]; then ./configure fi fi else ./configure fi fi if [ -z "$SKIP_CHECK" ]; then if [ -e Cargo.toml ]; then cargo test --release else make -j"$(nproc)" VERBOSE=1 check fi fi if [ -e Cargo.toml ]; then PKG="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')" VMODDIR="$(pkg-config --variable=vmoddir varnishapi)" cp target/release/lib$PKG.so "$VMODDIR" else make -j"$(nproc)" VERBOSE=1 install fi rm -rf /tmp/module_to_build