77
88 $ ./install.sh [--crystal=<crystal-version>] [--channel=stable|unstable|nightly]
99
10- - crystal-version: latest, 0.35, 0.34.0, 0.33.0, etc. (Default: latest)
10+ - crystal-version: latest, 1.0.0 etc. (Default: latest)
1111 - channel: stable, unstable, nightly. (Default: stable)
1212
1313REQUIREMENTS
3636
3737set -eu
3838
39- DISTRO_TYPE= " "
39+ DISTRO_REPO= ${DISTRO_REPO :- }
4040CRYSTAL_VERSION=" latest"
4141CHANNEL=" stable"
4242
@@ -48,31 +48,62 @@ _warn() {
4848 echo >&2 " WARNING: $* "
4949}
5050
51- _match_etc_issue () {
52- local _distro_type=" $1 "
53- shift
54- grep -qis " $* " /etc/issue && DISTRO_TYPE=" $_distro_type "
55- }
56-
57- # The DISTRO_TYPE detection script is based on https://github.com/icy/pacapt
58- _discover_distro_type () {
59- _match_etc_issue " deb" " Debian" && return
60- _match_etc_issue " deb" " Ubuntu" && return
61- _match_etc_issue " rpm" " CentOS" && return
62- _match_etc_issue " rpm" " Fedora" && return
63-
64- [[ -z " $DISTRO_TYPE " ]] || return
65-
66- if hash apt-get 2> /dev/null; then
67- DISTRO_TYPE=" deb"
68- elif hash yum 2> /dev/null; then
69- DISTRO_TYPE=" rpm"
70- else
51+ _check_version_id () {
52+ if [[ -z " ${VERSION_ID} " ]]; then
53+ cat /etc/os-release
7154 _error " Unable to identify distribution. Please, report to https://forum.crystal-lang.org/c/help-support/11"
7255 exit 1
7356 fi
7457}
7558
59+ _discover_distro_repo () {
60+ source /etc/os-release
61+ case " $ID " in
62+ debian)
63+ if [[ -z " ${VERSION_ID: +} " ]]; then
64+ VERSION_ID=" Unstable"
65+ elif [[ " $VERSION_ID " == " 9" ]]; then
66+ VERSION_ID=" $VERSION_ID .0"
67+ fi
68+ _check_version_id
69+
70+ DISTRO_REPO=" Debian_${VERSION_ID} "
71+ ;;
72+ ubuntu)
73+ _check_version_id
74+ DISTRO_REPO=" xUbuntu_${VERSION_ID} "
75+ ;;
76+ fedora)
77+ _check_version_id
78+ if [[ " ${VERSION} " == * " Prerelease" * ]]; then
79+ DISTRO_REPO=" Fedora_Rawhide"
80+ else
81+ DISTRO_REPO=" Fedora_${VERSION_ID} "
82+ fi
83+ ;;
84+ centos)
85+ _check_version_id
86+ DISTRO_REPO=" CentOS_${VERSION_ID} "
87+ ;;
88+ rhel)
89+ _check_version_id
90+ DISTRO_REPO=" RHEL_${VERSION_ID} "
91+ ;;
92+ opensuse-tumbleweed)
93+ DISTRO_REPO=" openSUSE_Tumbleweed"
94+ ;;
95+ opensuse-leap)
96+ _check_version_id
97+ DISTRO_REPO=" openSUSE_Leap_${VERSION_ID} "
98+ ;;
99+ * )
100+ _error " Unable to identify distribution. You may specify one with environment variable DISTRO_REPO"
101+ _error " Please, report to https://forum.crystal-lang.org/c/help-support/11"
102+ exit 1
103+ ;;
104+ esac
105+ }
106+
76107if [[ $EUID -ne 0 ]]; then
77108 _error " This script must be run as root"
78109 exit 1
@@ -102,46 +133,46 @@ case $i in
102133esac
103134done
104135
105- _discover_distro_type
106-
107- # Add repo
108- case $DISTRO_TYPE in
109- deb)
110- # Add repo metadata signign key (shared bintray signing key)
111- apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61
112- echo " deb https://dl.bintray.com/crystal/deb all $CHANNEL " | tee /etc/apt/sources.list.d/crystal.list
113- apt-get update
114- ;;
115-
116- rpm)
117- DISTRO=" all"
118- [[ $( rpm -E %{rhel}) == " 6" ]] && DISTRO=" el6"
136+ if [[ -z " ${DISTRO_REPO} " ]]; then
137+ _discover_distro_repo
138+ fi
119139
120- cat > /etc/yum.repos.d/crystal.repo << END
121- [crystal]
122- name=Crystal
123- baseurl=https://dl.bintray.com/crystal/rpm/$DISTRO /x86_64/$CHANNEL
124- gpgcheck=0
125- repo_gpgcheck=1
126- gpgkey=http://bintray.com/user/downloadSubjectPublicKey?username=bintray
127- END
128- ;;
129- esac
140+ _install_apt () {
141+ # Add repo signign key
142+ curl -fsSL https://download.opensuse.org/repositories/devel:languages:crystal/${DISTRO_REPO} /Release.key | gpg --dearmor | tee /etc/apt/trusted.gpg.d/devel_languages_crystal.gpg > /dev/null
143+ echo " deb http://download.opensuse.org/repositories/devel:/languages:/crystal/${DISTRO_REPO} / /" | tee /etc/apt/sources.list.d/crystal.list
144+ apt-get update
130145
131- # Install Crystal
132- case " $DISTRO_TYPE -$CRYSTAL_VERSION " in
133- deb-latest)
146+ if [[ " $CRYSTAL_VERSION " == " latest" ]]; then
134147 apt-get install -y crystal
135- ;;
136- deb-* )
148+ else
137149 # Appending * allows --crystal=x.y and resolution of package-iteration https://askubuntu.com/a/824926/1101493
138150 apt-get install -y crystal=" $CRYSTAL_VERSION *"
139- ;;
151+ fi
152+ }
140153
141- rpm-latest)
154+ _install_rpm_key () {
155+ rpm --verbose --import https://build.opensuse.org/projects/devel:languages:crystal/public_key
156+ }
157+
158+ _install_yum () {
159+ _install_rpm_key
160+
161+ [[ command wget ]] || yum install -y wget
162+
163+ cat > /etc/yum.repos.d/crystal.repo << EOF
164+ [crystal]
165+ name=Crystal (${DISTRO_REPO} )
166+ type=rpm-md
167+ baseurl=https://download.opensuse.org/repositories/devel:/languages:/crystal/${DISTRO_REPO} /
168+ gpgcheck=1
169+ gpgkey=https://download.opensuse.org/repositories/devel:/languages:/crystal/${DISTRO_REPO} /repodata/repomd.xml.key
170+ enabled=1
171+ EOF
172+
173+ if [[ " $CRYSTAL_VERSION " == " latest" ]]; then
142174 yum install -y crystal
143- ;;
144- rpm-* )
175+ else
145176 command -v repoquery > /dev/null || yum install -y yum-utils
146177 CRYSTAL_PACKAGE=$( repoquery crystal-$CRYSTAL_VERSION * | tail -n1)
147178 if [ -z " $CRYSTAL_PACKAGE " ]
@@ -150,7 +181,62 @@ case "$DISTRO_TYPE-$CRYSTAL_VERSION" in
150181 else
151182 yum install -y $CRYSTAL_PACKAGE
152183 fi
153- ;;
184+ fi
185+ }
154186
155- esac
187+ _install_dnf () {
188+ _install_rpm_key
189+
190+ dnf config-manager --add-repo https://download.opensuse.org/repositories/devel:languages:crystal/$DISTRO_REPO /devel:languages:crystal.repo
191+
192+ if [[ " $CRYSTAL_VERSION " == " latest" ]]; then
193+ dnf install -y crystal
194+ else
195+ command -v repoquery > /dev/null || dnf install -y dnf-utils
196+ CRYSTAL_PACKAGE=$( repoquery crystal-$CRYSTAL_VERSION * | tail -n1)
197+ if [ -z " $CRYSTAL_PACKAGE " ]
198+ then
199+ _error " Unable to find a package for crystal $CRYSTAL_VERSION "
200+ else
201+ dnf install -y $CRYSTAL_PACKAGE
202+ fi
203+ fi
204+ }
205+
206+ _install_zypper () {
207+ _install_rpm_key
208+ zypper --non-interactive addrepo https://download.opensuse.org/repositories/devel:languages:crystal/$DISTRO_REPO /devel:languages:crystal.repo
209+ zypper --non-interactive refresh
156210
211+ if [[ " $CRYSTAL_VERSION " == " latest" ]]; then
212+ zypper --non-interactive install crystal
213+ else
214+ zypper --non-interactive install crystal=" $CRYSTAL_VERSION *"
215+ fi
216+ }
217+
218+ # Add repo
219+ case $DISTRO_REPO in
220+ Debian* )
221+ _install_apt
222+ ;;
223+ xUbuntu* )
224+ _install_apt
225+ ;;
226+ Fedora* )
227+ _install_yum
228+ ;;
229+ RHEL* )
230+ _install_yum
231+ ;;
232+ CentOS* )
233+ _install_yum
234+ ;;
235+ openSUSE* )
236+ _install_zypper
237+ ;;
238+ * )
239+ _error " Unable to install for $DISTRO_REPO . Please, report to https://forum.crystal-lang.org/c/help-support/11"
240+ exit 1
241+ ;;
242+ esac
0 commit comments