forked from crystal-lang/crystal-website
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·288 lines (245 loc) · 6.78 KB
/
install.sh
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env bash
_help() {
cat <<END
USAGE
$ ./install.sh [--version=<crystal-version>] [--channel=stable|unstable|nightly]
- crystal-version: "latest", or a minor release version like 1.0 or 1.1 (Default: latest)
- channel: "stable", "unstable", "nightly" (Default: stable)
REQUIREMENTS
- Run as root
- The following packages need to be installed already:
- gnupg ca-certificates apt-transport-https (on Debian/Ubuntu)
NOTES
The following files may be updated:
- /etc/apt/sources.list.d/crystal.list (on Debian/Ubuntu)
- /etc/yum.repos.d/crystal.repo (on CentOS/Fedora)
The following packages may be installed:
- wget (on Debian/Ubuntu when missing)
- curl (on openSUSE when missing)
- yum-utils (on CentOS/Fedora when using --version=x.y.z)
This script source and issue-tracker can be found at:
- https://github.com/crystal-lang/distribution-scripts/tree/master/packages/scripts/install.sh
END
}
set -eu
OBS_PROJECT=${OBS_PROJECT:-"devel:languages:crystal"}
DISTRO_REPO=${DISTRO_REPO:-}
CRYSTAL_VERSION=${CRYSTAL_VERSION:-"latest"}
CHANNEL="stable"
_error() {
echo >&2 "ERROR: $*"
}
_warn() {
echo >&2 "WARNING: $*"
}
_check_version_id() {
if [[ -z "${VERSION_ID}" ]]; then
_error "Unable to identify distribution repository for ${ID}. Please, report to https://forum.crystal-lang.org/c/help-support/11"
exit 1
fi
}
_discover_distro_repo() {
if [[ -r /etc/os-release ]]; then
source /etc/os-release
elif [[ -r /usr/lib/os-release ]]; then
source /usr/lib/os-release
else
_error "Unable to identify distribution. Please, report to https://forum.crystal-lang.org/c/help-support/11"
exit 1
fi
case "$ID" in
debian)
if [[ -z "${VERSION_ID:+}" ]]; then
VERSION_ID="Unstable"
elif [[ "$VERSION_ID" == "9" ]]; then
VERSION_ID="$VERSION_ID.0"
fi
_check_version_id
DISTRO_REPO="Debian_${VERSION_ID}"
;;
ubuntu)
_check_version_id
DISTRO_REPO="xUbuntu_${VERSION_ID}"
;;
fedora)
_check_version_id
if [[ "${VERSION}" == *"Prerelease"* ]]; then
DISTRO_REPO="Fedora_Rawhide"
else
DISTRO_REPO="Fedora_${VERSION_ID}"
fi
;;
centos)
_check_version_id
DISTRO_REPO="CentOS_${VERSION_ID}"
;;
rhel)
_check_version_id
DISTRO_REPO="RHEL_${VERSION_ID}"
;;
opensuse-tumbleweed)
DISTRO_REPO="openSUSE_Tumbleweed"
;;
opensuse-leap)
_check_version_id
DISTRO_REPO="openSUSE_Leap_${VERSION_ID}"
;;
"")
_error "Unable to identify distribution. You may specify one with environment variable DISTRO_REPO"
_error "Please, report to https://forum.crystal-lang.org/c/help-support/11"
exit 1
;;
*)
# If there's no dedicated repository for the distro, try to figure out
# if the distro is apt or rpm based and use a default repository.
_discover_distro_type
case "$DISTRO_TYPE" in
deb)
DISTRO_REPO="Debian_Unstable"
;;
rpm)
DISTRO_REPO="RHEL_7"
;;
*)
_error "Unable to identify distribution type ($ID). You may specify a repository with the environment variable DISTRO_REPO"
_error "Please, report to https://forum.crystal-lang.org/c/help-support/11"
exit 1
;;
esac
esac
}
_discover_distro_type() {
DISTRO_TYPE=""
[[ $(command -v apt-get) ]] && DISTRO_TYPE="deb" && return
[[ $(command -v yum) ]] && DISTRO_TYPE="rpm" && return
}
if [[ $EUID -ne 0 ]]; then
_error "This script must be run as root"
exit 1
fi
# Parse --version=<VERSION> and --channel=<CHANNEL> arguments
for i in "$@"
do
case $i in
--crystal=*)
CRYSTAL_VERSION="${i#*=}"
shift
echo "The argument --crystal= has been deprecated, please use --version= instead." >&2
;;
--version=*)
CRYSTAL_VERSION="${i#*=}"
shift
;;
--channel=*)
CHANNEL="${i#*=}"
_warn "Currently, only stable channel is available"
shift
;;
--help)
_help
exit 0
shift
;;
*)
_warn "Invalid option $i"
;;
esac
done
case $CHANNEL in
stable)
;;
nightly | unstable)
OBS_PROJECT="${OBS_PROJECT}:${CHANNEL}"
;;
*)
_error "Unsupported channel $CHANNEL"
exit 1
;;
esac
if [[ -z "${DISTRO_REPO}" ]]; then
_discover_distro_repo
fi
_install_apt() {
if [[ -z $(command -v wget &> /dev/null) ]] || [[ -z $(command -v gpg &> /dev/null) ]]; then
[[ -f /etc/apt/sources.list.d/crystal.list ]] && rm -f /etc/apt/sources.list.d/crystal.list
apt-get update
apt-get install -y wget gpg
fi
# Add repo signign key
wget -qO- https://download.opensuse.org/repositories/${OBS_PROJECT}/${DISTRO_REPO}/Release.key | gpg --dearmor | tee /etc/apt/trusted.gpg.d/devel_languages_crystal.gpg > /dev/null
echo "deb http://download.opensuse.org/repositories/${OBS_PROJECT}/${DISTRO_REPO}/ /" | tee /etc/apt/sources.list.d/crystal.list
apt-get update
if [[ "$CRYSTAL_VERSION" == "latest" ]]; then
apt-get install -y crystal
else
apt-get install -y "crystal${CRYSTAL_VERSION}"
fi
}
_install_rpm_key() {
rpm --verbose --import https://build.opensuse.org/projects/${OBS_PROJECT}/public_key
}
_install_yum() {
_install_rpm_key
cat > /etc/yum.repos.d/crystal.repo <<EOF
[crystal]
name=Crystal (${DISTRO_REPO})
type=rpm-md
baseurl=https://download.opensuse.org/repositories/${OBS_PROJECT}/${DISTRO_REPO}/
gpgcheck=1
gpgkey=https://download.opensuse.org/repositories/${OBS_PROJECT}/${DISTRO_REPO}/repodata/repomd.xml.key
enabled=1
EOF
if [[ "$CRYSTAL_VERSION" == "latest" ]]; then
yum install -y crystal
else
yum install -y "crystal${CRYSTAL_VERSION}"
fi
}
_install_dnf() {
_install_rpm_key
dnf config-manager --add-repo https://download.opensuse.org/repositories/${OBS_PROJECT}/$DISTRO_REPO/${OBS_PROJECT}.repo
if [[ "$CRYSTAL_VERSION" == "latest" ]]; then
dnf install -y crystal
else
dnf install -y "crystal${CRYSTAL_VERSION}"
fi
}
_install_zypper() {
if [[ -z $(command -v curl &> /dev/null) ]]; then
zypper refresh
zypper install -y curl
fi
_install_rpm_key
zypper --non-interactive addrepo https://download.opensuse.org/repositories/${OBS_PROJECT}/$DISTRO_REPO/${OBS_PROJECT}.repo
zypper --non-interactive refresh
if [[ "$CRYSTAL_VERSION" == "latest" ]]; then
zypper --non-interactive install crystal
else
zypper --non-interactive install "crystal${CRYSTAL_VERSION}"
fi
}
# Add repo
case $DISTRO_REPO in
Debian*)
_install_apt
;;
xUbuntu*)
_install_apt
;;
Fedora*)
_install_yum
;;
RHEL*)
_install_yum
;;
CentOS*)
_install_yum
;;
openSUSE*)
_install_zypper
;;
*)
_error "Unable to install for $DISTRO_REPO. Please, report to https://forum.crystal-lang.org/c/help-support/11"
exit 1
;;
esac