Temporarily remove iOS due to code signing issues
[mirror/qt/qt5.git] / coin / provisioning / common / InstallAppFromCompressedFileFromURL.sh
1 #!/bin/bash
2
3 #############################################################################
4 ##
5 ## Copyright (C) 2017 The Qt Company Ltd.
6 ## Contact: http://www.qt.io/licensing/
7 ##
8 ## This file is part of the provisioning scripts of the Qt Toolkit.
9 ##
10 ## $QT_BEGIN_LICENSE:LGPL21$
11 ## Commercial License Usage
12 ## Licensees holding valid commercial Qt licenses may use this file in
13 ## accordance with the commercial license agreement provided with the
14 ## Software or, alternatively, in accordance with the terms contained in
15 ## a written agreement between you and The Qt Company. For licensing terms
16 ## and conditions see http://www.qt.io/terms-conditions. For further
17 ## information use the contact form at http://www.qt.io/contact-us.
18 ##
19 ## GNU Lesser General Public License Usage
20 ## Alternatively, this file may be used under the terms of the GNU Lesser
21 ## General Public License version 2.1 or version 3 as published by the Free
22 ## Software Foundation and appearing in the file LICENSE.LGPLv21 and
23 ## LICENSE.LGPLv3 included in the packaging of this file. Please review the
24 ## following information to ensure the GNU Lesser General Public License
25 ## requirements will be met: https://www.gnu.org/licenses/lgpl.html and
26 ## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
27 ##
28 ## As a special exception, The Qt Company gives you certain additional
29 ## rights. These rights are described in The Qt Company LGPL Exception
30 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
31 ##
32 ## $QT_END_LICENSE$
33 ##
34 #############################################################################
35
36 # This script receives URLs to a compressed file. It then downloads it,
37 # uncompresses it and installs it by default
38 # to /Applications/. This can be overridden by a target parameter.
39
40 # shellcheck source=try_catch.sh
41 source "${BASH_SOURCE%/*}/try_catch.sh"
42 # shellcheck source=DownloadURL.sh
43 source "${BASH_SOURCE%/*}/DownloadURL.sh"
44
45 ExceptionDownload=99
46 ExceptionCreateTmpFile=100
47 ExceptionCreateTmpDirectory=101
48 ExceptionUncompress=102
49 ExceptionMoveApp=103
50 ExceptionDeleteTmpFile=104
51 ExceptionRemoveTmpDirectory=105
52 ExceptionUnknownFormat=106
53
54
55 function InstallAppFromCompressedFileFromURL {
56     url=$1
57     url_alt=$2
58     expectedSha1=$3
59     appPrefix=$4
60     target=$5
61
62     if [ "" == "$target" ]; then
63         target="/Applications/"
64     fi
65
66     try
67     (
68         basefilename=${url##*/}
69         extension=${basefilename##*.}
70         filename=${basefilename%.*}
71         if [ "$extension" == "gz" ] && [ "${filename##*.}" == "tar" ]; then
72             extension="tar.gz"
73         fi
74
75         echo "Extension for file: $extension"
76         echo "Creating temporary file and directory"
77         targetFile=$(mktemp "$TMPDIR$(uuidgen).$extension") || throw $ExceptionCreateTmpFile
78         # macOS 10.10 mktemp does require prefix
79         if [[ $OSTYPE == "darwin14" ]]; then
80             targetDirectory=$(mktemp -d -t '10.10') || throw $ExceptionCreateTmpDirectory
81         else
82             targetDirectory=$(mktemp -d) || throw $ExceptionCreateTmpDirectory
83         fi
84         (DownloadURL "$url" "$url_alt" "$expectedSha1" "$targetFile") || throw $ExceptionDownload
85         echo "Uncompress $targetFile"
86         case $extension in
87             "tar.gz")
88                 tar -xzf "$targetFile" --directory "$targetDirectory" || throw $ExceptionUncompress
89             ;;
90             "zip")
91                 unzip "$targetFile" -d "$targetDirectory" || throw $ExceptionUncompress
92             ;;
93             *)
94                 throw $ExceptionUnknownFormat
95             ;;
96         esac
97         echo "Moving app to '$target'"
98         sudo mv "$targetDirectory/$appPrefix/"* "$target" || throw $ExceptionMoveApp
99         echo "Removing file '$targetFile'"
100         rm "$targetFile" || throw $ExceptionDeleteTmpFile
101         echo "Removing directory '$targetDirectory'"
102         rm -rf "$targetDirectory" || throw $ExceptionRemoveTmpDirectory
103     )
104
105     catch || {
106         case $ex_code in
107             $ExceptionDownload)
108                 exit 1;
109             ;;
110             $ExceptionCreateTmpFile)
111                 echo "Failed to create temporary file"
112                 exit 1;
113             ;;
114             $ExceptionUncompress)
115                 echo "Failed extracting compressed file."
116                 exit 1;
117             ;;
118             $ExceptionMoveApp)
119                 echo "Failed moving app to '$target'."
120                 exit 1;
121             ;;
122             $ExceptionDeleteTmpFile)
123                 echo "Failed deleting temporary file."
124                 exit 1;
125             ;;
126             $ExceptionRemoveTmpDirectory)
127                 echo "Failed deleting temporary file."
128                 exit 1;
129             ;;
130             $ExceptionUnknownFormat)
131                 echo "Unknown file format."
132                 exit 1;
133             ;;
134         esac
135     }
136 }