aboutsummaryrefslogtreecommitdiffstats
path: root/coin/provisioning/common/unix/InstallFromCompressedFileFromURL.sh
diff options
context:
space:
mode:
authorTony Sarajärvi <tony.sarajarvi@qt.io>2018-03-07 15:03:07 +0200
committerLiang Qi <liang.qi@qt.io>2018-04-18 18:15:04 +0000
commit9497487c77ed2544b20c6ee5829d9aeb763db057 (patch)
tree4c0cdc78489fd1d76644e71be25242408e4e7748 /coin/provisioning/common/unix/InstallFromCompressedFileFromURL.sh
parent6ef6267ab9e6ef2f7c74f81f9b73c3c68594ec82 (diff)
Remove try_catch codes from unix scripts
Change-Id: Iabadbf28c65132ae614048cb98e92f57e3786056 Reviewed-by: Heikki Halmet <heikki.halmet@qt.io> (cherry picked from commit 90261c1df5cb62a47b44d2d9b84c0753d6ebf9e4)
Diffstat (limited to 'coin/provisioning/common/unix/InstallFromCompressedFileFromURL.sh')
-rwxr-xr-xcoin/provisioning/common/unix/InstallFromCompressedFileFromURL.sh109
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"
}