diff options
author | Aaron Ball <nullspoon@oper.io> | 2018-02-25 23:57:03 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2018-02-25 23:59:59 -0700 |
commit | f42923bddae7aa98065850f709e4f3bbce870dd2 (patch) | |
tree | a6a7baaacfa4dd2473eba7e5436af35224b2e30a | |
parent | 3dbd6e6085e534db14ddadc1f2355da566151b8e (diff) | |
download | pkgself-f42923bddae7aa98065850f709e4f3bbce870dd2.tar.gz pkgself-f42923bddae7aa98065850f709e4f3bbce870dd2.tar.xz |
Refactor of download_src function
Simplified use of file variable, with a better explanation of when and
why it is used. We also now handle already-downloaded files, skipping
them.
Removed the source download loop from download_src function. Now the
function just downloads the one source uri and the loop occurs outside
this function. This enables its re-use outside of the main build
process.
-rwxr-xr-x | pkgself.sh | 64 |
1 files changed, 29 insertions, 35 deletions
@@ -22,48 +22,39 @@ export DECOMPRESS='xz -d -c' # Command to decompress data export COMPRESSEXT='xz' # File extension for compressed data download_src() { + local src="${1:-}" local file - [ ! -d .source ] && mkdir .source + [ ! -d '.source' ] && mkdir '.source' - for src in ${source[@]}; do - # Set the file path buffer for better error messages - # This will store local files verbatim, but remote files will be parsed out - # of their URIs - # If we don't store this value, we would need to recompute src basename a - # great many times. - file="${src}" - - # Download external files + # Set the file path buffer for better error messages + # This will store local files verbatim, but remote files will be parsed out + # of their URIs + # If we don't store this value, we would need to recompute src basename a + # great many times. + file="$(basename ${src})" + + # Download external files + if [ ! -f ".source/$(basename ${src})" ]; then if [ "${src:0:4}" == "http" ] || [ "${src:0:3}" == "ftp" ]; then - file="$(basename ${src})" - if [ ! -f ".source/${file}" ]; then - printf "Downloading %s\n" "${file}" - curl -k -L -q -# "${src}" -o ".source/${file}" - fi - elif [ "${src:0:1}" == "/" ] && [ -f "${src}" ]; then - file="$(basename ${src})" - if [ ! -f ".source/${file}" ]; then - printf "Copying local file '%s'\n" "${file}" - cp "${src}" ".source/${file}" - fi + printf "Downloading %s\n" "${file}" + curl -k -L -q -# "${src}" -o ".source/${file}" elif [ "${src:0:6}" == "ssh://" ]; then - file="$(basename ${src})" - if [ ! -f ".source/${file}" ]; then - printf "Downloading %s\n" "${file}" - scp -o LogLevel=Error "${src:6}" ".source/${file}" - fi + printf "Downloading %s\n" "${file}" + scp -o LogLevel=Error "${src:6}" ".source/${file}" fi + else + printf "Source file '%s' already downloaded.\n" "${file}" + fi - if [ -e ".source/${file}" ]; then - cp -r ".source/${file}" "${PKGSRC}/${file}" - elif [ -e "${file}" ]; then - cp -r "${file}" "${PKGSRC}/${file}" - else - printf "Error: Source '%s' does not exist\n" "${file}" - return 1 - fi - done + if [ -e ".source/${file}" ]; then + cp -r ".source/${file}" "${PKGSRC}/${file}" + elif [ -e "${src}" ]; then + cp -r "${src}" "${PKGSRC}/${file}" + else + printf "Error: Source '%s' does not exist\n" "${file}" + return 1 + fi } @@ -127,6 +118,9 @@ main() { cd "${pkgdir}" for src in ${source[@]}; do download_src "${src}" + if [ $? -gt 0 ]; then + return 1 + fi done cd "${PKGSRC}" |