diff --git a/scripts/common-functions.sh b/scripts/common-functions.sh new file mode 100755 index 0000000..82062c2 --- /dev/null +++ b/scripts/common-functions.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# Function that downloads an archive with the source code by the given url, +# extracts its files and exports a variable SOURCES_DIR_lib${LIBRARY_NAME} +function downloadArchive() { + LIBRARY_NAME=$1 + LIBRARY_VERSION=$2 + DOWNLOAD_URL=$3 + + echo "Ensuring sources of $LIBRARY_NAME $LIBRARY_VERSION" + LIBRARY_SOURCES=${LIBRARY_NAME}-${LIBRARY_VERSION} + + if [[ ! -d "$LIBRARY_SOURCES" ]]; then + curl -O ${DOWNLOAD_URL} + + ARCHIVE_NAME=${DOWNLOAD_URL##*/} + tar xf ${ARCHIVE_NAME} -C . + rm ${ARCHIVE_NAME} + fi + + export SOURCES_DIR_lib${LIBRARY_NAME}=$(pwd)/${LIBRARY_SOURCES} +} diff --git a/scripts/libdav1d/download.sh b/scripts/libdav1d/download.sh index ec0a7c5..acd83a8 100755 --- a/scripts/libdav1d/download.sh +++ b/scripts/libdav1d/download.sh @@ -1,19 +1,10 @@ #!/usr/bin/env bash -# Script to download Dav1d's source code - -# Exports SOURCES_DIR_libdav1d - path where actual sources are stored +source ${SCRIPTS_DIR}/common-functions.sh DAV1D_VERSION=0.6.0 -echo "Using libdav1d $DAV1D_VERSION" -DAV1D_SOURCES=dav1d-${DAV1D_VERSION} - -if [[ ! -d "$DAV1D_SOURCES" ]]; then - TARGET_FILE_NAME=dav1d-${DAV1D_VERSION}.tar.gz - - curl https://code.videolan.org/videolan/dav1d/-/archive/${DAV1D_VERSION}/dav1d-${DAV1D_VERSION}.tar.gz --output ${TARGET_FILE_NAME} - tar xf ${TARGET_FILE_NAME} -C . - rm ${TARGET_FILE_NAME} -fi -export SOURCES_DIR_libdav1d=$(pwd)/${DAV1D_SOURCES} +downloadArchive \ + "dav1d" \ + ${DAV1D_VERSION} \ + "https://code.videolan.org/videolan/dav1d/-/archive/${DAV1D_VERSION}/dav1d-${DAV1D_VERSION}.tar.gz"