diff --git a/README.md b/README.md index ec04232..731bdcd 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Run the following from the heroku command line: heroku buildpacks:add --index 1 https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git ``` +You can set a custom download URL by setting the variable `FFMPEG_DOWNLOAD_URL`. + Note: This buildpack should be added before the main language buildpack (by using `--index 1`), since the application process types are calculated from the last buildpack in the list if no `Procfile` is specified. diff --git a/bin/compile b/bin/compile index a8961c0..e8f1cd3 100755 --- a/bin/compile +++ b/bin/compile @@ -1,24 +1,59 @@ -#!/bin/sh +#!/usr/bin/env bash +# bin/compile -indent() { - sed -u 's/^/ /' +header() { + echo "" || true + echo "-----> $*" || true } -echo "-----> Install ffmpeg" -BUILD_DIR=$1 -VENDOR_DIR="vendor" -DOWNLOAD_URL="https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz" +output() { + while IFS= read -r LINE; do + # do not indent headers that are being piped through the output + if [[ "$LINE" =~ ^-----\>.* ]]; then + echo "$LINE" || true + else + echo " $LINE" || true + fi + done +} -echo "DOWNLOAD_URL = " $DOWNLOAD_URL | indent +header "Installing ffmpeg" + +BUILD_DIR=${1:-} +VENDOR_DIR="vendor" +FFMPEG_ARCHIVE_NAME="ffmpeg.tar.xz" cd $BUILD_DIR mkdir -p $VENDOR_DIR cd $VENDOR_DIR mkdir -p ffmpeg cd ffmpeg -curl -L --silent $DOWNLOAD_URL | tar xJ --strip-components=1 -echo "exporting PATH" | indent +if [[ -z $FFMPEG_DOWNLOAD_URL ]]; then + echo "Variable FFMPEG_DOWNLOAD_URL isn't set, using default value" | output + FFMPEG_DOWNLOAD_URL="https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz" +fi + +echo "Downloading $FFMPEG_DOWNLOAD_URL" | output + +code=$(curl "$FFMPEG_DOWNLOAD_URL" -L --silent --fail --retry 5 --retry-max-time 15 -o ./$FFMPEG_ARCHIVE_NAME --write-out "%{http_code}") + +if [ "$code" != "200" ]; then + echo "Unable to download ffmpeg: $code" | output && exit 1 +fi + +echo "Unpacking the archive" | output + +tar xJf "./$FFMPEG_ARCHIVE_NAME" --strip-components=1 + +if [ "$?" != "0" ]; then + echo "Failed to unpack" | output && exit 1 +fi + +rm $FFMPEG_ARCHIVE_NAME + PROFILE_PATH="$BUILD_DIR/.profile.d/ffmpeg.sh" mkdir -p $(dirname $PROFILE_PATH) echo 'export PATH="$PATH:${HOME}/vendor/ffmpeg"' >> $PROFILE_PATH + +echo "Installation successful" | output \ No newline at end of file