diff --git a/grab_packages.sh b/grab_packages.sh index 6e8fe3e..9e158ba 100755 --- a/grab_packages.sh +++ b/grab_packages.sh @@ -3,6 +3,7 @@ CURRENT_DIR=$(realpath "$0") CURRENT_DIR=$(dirname "${CURRENT_DIR}") +. "${CURRENT_DIR}/scripts/download.sh" . "${CURRENT_DIR}/src/scripts/versions.sh" . "${CURRENT_DIR}/src/scripts/libraries.sh" @@ -10,11 +11,8 @@ function download_package() { local NAME=$1 local ITEM_LIST=(${PROJECT_DOWNLOADS[${NAME}]//;/ }) if [ ! -f "${CURRENT_DIR}/support/${ITEM_LIST[2]}/${ITEM_LIST[1]}" ]; then - rm -f "${CURRENT_DIR}/support/${ITEM_LIST[2]}/${ITEM_LIST[1]}" - - if ! wget --tries=5 --waitretry=5 ${ITEM_LIST[0]} -O "${CURRENT_DIR}/support/${ITEM_LIST[2]}/${ITEM_LIST[1]}"; then + if ! download_file "${ITEM_LIST[0]}" "${CURRENT_DIR}/support/${ITEM_LIST[2]}/${ITEM_LIST[1]}"; then echo "failed $NAME" - rm -f "${CURRENT_DIR}/support/${ITEM_LIST[2]}/${ITEM_LIST[1]}" exit 1 fi diff --git a/scripts/create_packages.sh b/scripts/create_packages.sh index 26426fd..e17fcfe 100755 --- a/scripts/create_packages.sh +++ b/scripts/create_packages.sh @@ -6,6 +6,7 @@ SCRIPTS_DIR=$(realpath ${SCRIPTS_DIR}) CURRENT_DIR=${SCRIPTS_DIR}/.. CURRENT_DIR=$(realpath "${CURRENT_DIR}") +. "${CURRENT_DIR}/scripts/download.sh" . "${CURRENT_DIR}/src/scripts/versions.sh" . "${CURRENT_DIR}/src/scripts/libraries.sh" @@ -34,12 +35,9 @@ function download_and_update_hash() { rm -r ${CURRENT_DIR}/support/${CLEANUP_LIST[0]} fi - rm -f "${CURRENT_DIR}/support/${ITEM_LIST[2]}/${ITEM_LIST[1]}" rm -f "${CURRENT_DIR}/support/${ITEM_LIST[2]}/${ITEM_LIST[1]}.sha256" - - if ! wget --tries=5 --waitretry=5 ${ITEM_LIST[0]} -O "${CURRENT_DIR}/support/${ITEM_LIST[2]}/${ITEM_LIST[1]}"; then + if ! download_file "${ITEM_LIST[0]}" "${CURRENT_DIR}/support/${ITEM_LIST[2]}/${ITEM_LIST[1]}"; then echo "failed $NAME" - rm -f "${CURRENT_DIR}/support/${ITEM_LIST[2]}/${ITEM_LIST[1]}" exit 1 fi pushd "${CURRENT_DIR}/support/${ITEM_LIST[2]}" diff --git a/scripts/download.sh b/scripts/download.sh new file mode 100755 index 0000000..c425f73 --- /dev/null +++ b/scripts/download.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +WGET_OPTS="--tries=5 --waitretry=5" + +function remove_file() { + if [ -f "$1" ]; then + rm -f "$1" + fi +} + +function download_file() { + remove_file "$2" + if wget ${WGET_OPTS} "$1" -O "$2"; then + return 0 + fi + + remove_file "$2" + return 1 +}