diff options
Diffstat (limited to 'coin/provisioning/common/unix/InstallFromCompressedFileFromURL.sh')
-rwxr-xr-x | coin/provisioning/common/unix/InstallFromCompressedFileFromURL.sh | 109 |
1 files changed, 32 insertions, 77 deletions
diff --git a/coin/provisioning/common/unix/InstallFromCompressedFileFromURL.sh b/coin/provisioning/common/unix/InstallFromCompressedFileFromURL.sh index fb77b714..b616efb9 100755 --- a/coin/provisioning/common/unix/InstallFromCompressedFileFromURL.sh +++ b/coin/provisioning/common/unix/InstallFromCompressedFileFromURL.sh @@ -33,21 +33,11 @@ ## ############################################################################# -# shellcheck source=try_catch.sh -source "${BASH_SOURCE%/*}/try_catch.sh" +set -ex + # shellcheck source=DownloadURL.sh source "${BASH_SOURCE%/*}/DownloadURL.sh" -ExceptionDownload=99 -ExceptionCreateTmpFile=100 -ExceptionCreateTmpDirectory=101 -ExceptionUncompress=102 -ExceptionMoveApp=103 -ExceptionDeleteTmpFile=104 -ExceptionRemoveTmpDirectory=105 -ExceptionUnknownFormat=106 - - function InstallFromCompressedFileFromURL { url=$1 url_alt=$2 @@ -55,70 +45,35 @@ function InstallFromCompressedFileFromURL { installDirectory=$4 appPrefix=$5 - try - ( - basefilename=${url##*/} - extension=${basefilename##*.} - filename=${basefilename%.*} - if [ "$extension" == "gz" ] && [ "${filename##*.}" == "tar" ]; then - extension="tar.gz" - fi - echo "Extension for file: $extension" - echo "Creating temporary file and directory" - targetFile=$(mktemp "$TMPDIR$(uuidgen)XXXXX.$extension") || throw $ExceptionCreateTmpFile - targetDirectory=$(mktemp -d) || throw $ExceptionCreateTmpDirectory - (DownloadURL "$url" "$url_alt" "$expectedSha1" "$targetFile") || throw $ExceptionDownload - echo "Uncompress $targetFile" - case $extension in - "tar.gz") - tar -xzf "$targetFile" --directory "$targetDirectory" || throw $ExceptionUncompress - ;; - "zip") - unzip "$targetFile" -d "$targetDirectory" || throw $ExceptionUncompress - ;; - *) - throw $ExceptionUnknownFormat - ;; - esac - echo "Moving app to $installDirectory" - sudo mkdir -p "$installDirectory" - sudo mv "$targetDirectory/$appPrefix/"* "$installDirectory" || throw $ExceptionMoveApp - echo "Removing file '$targetFile'" - rm "$targetFile" || throw $ExceptionDeleteTmpFile - echo "Removing directory '$targetDirectory'" - rm -rf "$targetDirectory" || throw $ExceptionRemoveTmpDirectory - ) - - catch || { - case $ex_code in - $ExceptionDownload) - exit 1; - ;; - $ExceptionCreateTmpFile) - echo "Failed to create temporary file" - exit 1; - ;; - $ExceptionUncompress) - echo "Failed extracting compressed file." - exit 1; - ;; - $ExceptionMoveApp) - echo "Failed moving app to target location." - exit 1; - ;; - $ExceptionDeleteTmpFile) - echo "Failed deleting temporary file." - exit 1; - ;; - $ExceptionRemoveTmpDirectory) - echo "Failed deleting temporary file." - exit 1; - ;; - $ExceptionUnknownFormat) - echo "Unknown file format." - exit 1; - ;; - esac - } + basefilename=${url##*/} + extension=${basefilename##*.} + filename=${basefilename%.*} + if [ "$extension" == "gz" ] && [ "${filename##*.}" == "tar" ]; then + extension="tar.gz" + fi + echo "Extension for file: $extension" + echo "Creating temporary file and directory" + targetFile=$(mktemp "$TMPDIR$(uuidgen)XXXXX.$extension") + targetDirectory=$(mktemp -d) + DownloadURL "$url" "$url_alt" "$expectedSha1" "$targetFile" + echo "Uncompress $targetFile" + case $extension in + "tar.gz") + tar -xzf "$targetFile" --directory "$targetDirectory" + ;; + "zip") + unzip "$targetFile" -d "$targetDirectory" + ;; + *) + exit 1 + ;; + esac + echo "Moving app to $installDirectory" + sudo mkdir -p "$installDirectory" + sudo mv "$targetDirectory/$appPrefix/"* "$installDirectory" + echo "Removing file '$targetFile'" + rm "$targetFile" + echo "Removing directory '$targetDirectory'" + rm -rf "$targetDirectory" } |