forked from symfony-cli/symfony-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash-installer
executable file
·222 lines (197 loc) · 6.05 KB
/
bash-installer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env bash
# Copyright (c) 2021-present Fabien Potencier <fabien@symfony.com>
#
# Symfony CLI installer: this file is part of Symfony CLI project.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -euo pipefail
CLI_CONFIG_DIR=".symfony5"
CLI_EXECUTABLE="symfony"
CLI_TMP_NAME="$CLI_EXECUTABLE-"$(date +"%s")
CLI_NAME="Symfony CLI"
CLI_DOWNLOAD_URL_PATTERN="https://github.com/symfony-cli/symfony-cli/releases/latest/download/symfony-cli_~platform~.tar.gz"
function output {
style_start=""
style_end=""
if [ "${2:-}" != "" ]; then
case $2 in
"success")
style_start="\033[0;32m"
style_end="\033[0m"
;;
"error")
style_start="\033[31;31m"
style_end="\033[0m"
;;
"info"|"warning")
style_start="\033[33m"
style_end="\033[39m"
;;
"heading")
style_start="\033[1;33m"
style_end="\033[22;39m"
;;
esac
fi
builtin echo -e "${style_start}${1}${style_end}"
}
output "${CLI_NAME} installer" "heading"
binary_dest="${HOME}/${CLI_CONFIG_DIR}/bin"
custom_dir="false"
# Getops does not support long option names
while [[ $# -gt 0 ]]; do
case $1 in
--install-dir=*)
binary_dest="${1#*=}"
custom_dir="true"
shift # past argument=value
;;
--install-dir)
binary_dest="${2:-}"
custom_dir="true"
shift # past argument
shift # past value
;;
*)
output "Unknown option $1" "error"
output "Usage: ${0} [--install-dir=dir]"
exit 1
;;
esac
done
# Run environment checks.
output "\nEnvironment check" "heading"
# Check that cURL or wget is installed.
downloader=""
if command -v curl >/dev/null 2>&1; then
downloader="curl"
output " [*] cURL is installed" "success"
elif command -v wget >/dev/null 2>&1; then
downloader="wget"
output " [*] wget is installed" "success"
else
output " [ ] ERROR: cURL or wget is required for installation." "error"
exit 1
fi
# Check that tar is installed.
if command -v tar >/dev/null 2>&1; then
output " [*] Tar is installed" "success"
else
output " [ ] ERROR: Tar is required for installation." "error"
exit 1
fi
# Check that Git is installed.
if command -v git >/dev/null 2>&1; then
output " [*] Git is installed" "success"
else
output " [ ] Warning: Git will be needed." "warning"
fi
kernel=$(uname -s 2>/dev/null || /usr/bin/uname -s)
case ${kernel} in
"Linux"|"linux")
kernel="linux"
;;
"Darwin"|"darwin")
kernel="darwin"
;;
*)
output "OS '${kernel}' not supported" "error"
exit 1
;;
esac
machine=$(uname -m 2>/dev/null || /usr/bin/uname -m)
case ${machine} in
arm|armv6*)
machine="armv6"
;;
armv7*)
# ARMv6 is upwards compatible with ARMv7
machine="armv6"
;;
aarch64*|armv8*|arm64)
machine="arm64"
;;
i[36]86)
machine="386"
if [ "darwin" = "${kernel}" ]; then
output " [ ] Your architecture (${machine}) is not supported anymore" "error"
exit 1
fi
;;
x86_64)
machine="amd64"
;;
*)
output " [ ] Your architecture (${machine}) is not currently supported" "error"
exit 1
;;
esac
output " [*] Your architecture (${machine}) is supported" "success"
if [ "darwin" = "${kernel}" ]; then
machine="all"
fi
platform="${kernel}_${machine}"
# The necessary checks have passed. Start downloading the right version.
output "\nDownload" "heading"
latest_url=${CLI_DOWNLOAD_URL_PATTERN/~platform~/${platform}}
output " Downloading ${latest_url}...";
case $downloader in
"curl")
curl --fail --location "${latest_url}" > "/tmp/${CLI_TMP_NAME}.tar.gz"
;;
"wget")
wget -q --show-progress "${latest_url}" -O "/tmp/${CLI_TMP_NAME}.tar.gz"
;;
esac
# shellcheck disable=SC2181
if [ $? != 0 ]; then
output " The download failed." "error"
exit 1
fi
output " Uncompress binary..."
tar -xz --directory "/tmp" -f "/tmp/${CLI_TMP_NAME}.tar.gz"
rm "/tmp/${CLI_TMP_NAME}.tar.gz"
if [ ! -d "${binary_dest}" ]; then
if ! mkdir -p "${binary_dest}"; then
binary_dest="."
fi
fi
if [ "${custom_dir}" == "true" ]; then
output " Installing the binary into ${binary_dest} ..."
else
output " Installing the binary into your home directory..."
fi
if mv "/tmp/${CLI_EXECUTABLE}" "${binary_dest}/${CLI_EXECUTABLE}"; then
output " The binary was saved to: ${binary_dest}/${CLI_EXECUTABLE}"
else
output " Failed to move the binary to ${binary_dest}." "error"
rm "/tmp/${CLI_EXECUTABLE}"
exit 1
fi
#output " Installing the shell auto-completion..."
#"${binary_dest}/${CLI_EXECUTABLE}" self:shell-setup --silent
#if [ $? != 0 ]; then
# output " Failed to install the shell auto-completion." "warning"
#fi
output "\nThe ${CLI_NAME} was installed successfully!" "success"
if [ "${custom_dir}" == "false" ]; then
output "\nUse it as a local file:" "info"
output " ${binary_dest}/${CLI_EXECUTABLE}"
output "\nOr add the following line to your shell configuration file:" "info"
output " export PATH=\"\$HOME/${CLI_CONFIG_DIR}/bin:\$PATH\""
output "\nOr install it globally on your system:" "info"
output " mv ${binary_dest}/${CLI_EXECUTABLE} /usr/local/bin/${CLI_EXECUTABLE}"
output "\nThen start a new shell and run '${CLI_EXECUTABLE}'" "info"
fi