-
Notifications
You must be signed in to change notification settings - Fork 28
/
sem-install
210 lines (196 loc) · 6.92 KB
/
sem-install
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
#!/bin/bash
install::package_url() {
DIST=$(uname)
[[ $(uname -m) =~ ^(aarch64|arm64)$ ]] && SEMAPHORE_ARCH="arm/" || SEMAPHORE_ARCH=""
case $DIST in
Linux)
echo "http://packages.semaphoreci.com/${SEMAPHORE_ARCH}$(lsb_release -cs)"
;;
Darwin)
[[ "${SEMAPHORE_ARCH}" == "arm/" ]] && echo "http://packages.semaphoreci.com/arm/mac" || echo "http://packagesmac.semaphoreci.com/mac"
;;
*)
echo "Unsupported distro $DIST"
exit 1
;;
esac
}
install::available() {
response=$(curl --write-out %{http_code} --head --silent --output /dev/null $(install::package_url)/${language}/${language_version}.tar.gz)
if [[ $response -ne 200 ]]; then
echo 1
else
echo 0
fi
}
install::download() {
curl --silent $(install::package_url)/${language}/${language_version}.tar.gz --output ${language_version}.tar.gz
}
install::install_node() {
NVM_NODEJS_ORG_MIRROR=http://nodejs.semaphoreci.com/dist nvm install ${language_version}
nvm use ${language_version} && npm install -g grunt-cli
result="$?"
sudo ln -fs "$(which node)" /usr/bin/nodejs
return $result
}
install::install_ruby() {
if [[ $(install::available) -eq 1 ]] ; then
rbenv install -s ${language_version}
rbenv global ${language_version}
gem update system
gem install bundler:2.0.1 --no-document
else
install::download
tar -zxf ${language_version}.tar.gz
rm -rf ${language_version}.tar.gz
mv ${language_version} ~/.rbenv/versions/
fi
rbenv rehash
return $?
}
install::install_erlang() {
if [[ $(install::available) -eq 1 ]] ; then
export KERL_BUILD_BACKEND=git
export OTP_GITHUB_URL='https://github.com/erlang/otp'
kerl update releases
kerl build "${language_version}" "${language_version}"
kerl install "${language_version}" ~/.kerl/installs/"${language_version}"
echo "${language_version} /home/semaphore/.kerl/installs/${language_version}">> ~/.kerl/otp_installations
else
install::download
tar -zxf ./"${language_version}".tar.gz && rm -rf ./"${language_version}".tar.gz
mv ./"${language_version}" ~/.kerl/installs/
echo "${language_version} /home/semaphore/.kerl/installs/${language_version}">> ~/.kerl/otp_installations
fi
return $?
}
install::install_elixir() {
response1=$(curl --write-out %{http_code} --head --silent --output /dev/null $(install::package_url)/${language}/elixirs_${language_version}.tar.gz)
response2=$(curl --write-out %{http_code} --head --silent --output /dev/null $(install::package_url)/${language}/archives_${language_version}.tar.gz)
case ${language_version} in
"1.6"*)
local erlang_version="20.3"
;;
"1.7"* | "1.8"* | "1.9"* | "1.10"*)
local erlang_version="22.3"
;;
"1.11"*)
local erlang_version="23.3"
;;
"1.12"*)
local erlang_version="24.3"
;;
"1.13"*)
local erlang_version="24.3"
;;
"1.14"*)
local erlang_version="25.3"
;;
"1.15"* | "1.16"*)
local erlang_version="26.2"
;;
"1.17"*)
local erlang_version="27.0"
;;
*)
echo "Installation of '${language}' version '${language_version}' is not yet supported"
return 1;
;;
esac
if [[ $(kerl list installations) != *"${erlang_version}"* ]]; then
language_before=${language}
language_version_before=${language_version}
language="erlang"
language_version=${erlang_version}
install::install_erlang
language=${language_before}
language_version=${language_version_before}
fi
if [[ $response1 -ne 200 ]] || [[ $response2 -ne 200 ]]; then
. ~/.kerl/installs/${erlang_version}/activate
kiex install ${language_version}
kiex use ${language_version}
mix local.hex --force
else
curl --silent $(install::package_url)/${language}/elixirs_${language_version}.tar.gz --output elixirs_${language_version}.tar.gz
curl --silent $(install::package_url)/${language}/archives_${language_version}.tar.gz --output archives_${language_version}.tar.gz
tar -zxf elixirs_${language_version}.tar.gz && rm -rf elixirs_${language_version}.tar.gz
tar -zxf archives_${language_version}.tar.gz && rm -rf archives_${language_version}.tar.gz
mv ./elixirs/*${language_version}* ~/.kiex/elixirs/
mv ./elixirs/.*${language_version}* ~/.kiex/elixirs/
mv ./archives/*${language_version} ~/.kiex/mix/archives/
rm -rf ./archives && rm -rf ./elixirs
fi
return $?
}
install::install_php() {
if [[ $(install::available) -eq 1 ]] ; then
phpbrew known -u
phpbrew -q install -j 4 ${language_version} +default +dbs +openssl -- --with-curl=/usr/local
phpbrew switch ${language_version}
echo "date.timezone = UTC" >> ~/.phpbrew/php/php-${language_version}/etc/php.ini
phpbrew ext install imap -- --with-kerberos --with-imap-ssl
phpbrew ext install gd -- --enable-gd-native-ttf --with-freetype-dir=/usr/lib/x86_64-linux-gnu
phpbrew ext install imagick
phpbrew ext install intl
wget https://getcomposer.org/composer-stable.phar -O ~/.phpbrew/php/php-${language_version}/bin/composer.phar
echo '#!/usr/bin/env bash' >> ~/.phpbrew/php/php-${language_version}/bin/composer
echo "~/.phpbrew/php/php-${language_version}/bin/php ~/.phpbrew/php/php-${language_version}/bin/composer.phar \$@" >> ~/.phpbrew/php/php-${language_version}/bin/composer
chmod +x ~/.phpbrew/php/php-${language_version}/bin/composer
else
install::download
tar -zxf ${language_version}.tar.gz
rm -rf ${language_version}.tar.gz
mv php-${language_version} ~/.phpbrew/php/
if [ ! -d "~/.phpbrew/build/php-{$language_version}" ]; then
output=$(phpbrew download ${language_version} | tail -n1|awk -F'/' '{print $NF}')
if [ ! -f ~/.phpbrew/distfiles/php-${language_version}.tar.bz2 ] || [[ "$(du -sh ~/.phpbrew/distfiles/php-${language_version}.tar.bz2 | cut -f1)" == "0" ]] ; then
mkdir -p ~/.phpbrew/distfiles
wget -q http://packages.semaphoreci.com/php-sources/php-${language_version}.tar.bz2 -O ~/.phpbrew/distfiles/php-${language_version}.tar.bz2
fi
if [ -f ~/.phpbrew/distfiles/php-${language_version}.tar.bz2 ]; then
tar -xjf ~/.phpbrew/distfiles/php-${language_version}.tar.bz2 -C ~/.phpbrew/build/
fi
fi
fi
return $?
}
install::usage() {
echo -e "
Usage:
sem-install [LANGUAGE] [VERSION]"
}
install::err() {
echo -e "\n! [$(version::date)]: $@" >&2
return 1
}
sem-install() {
if ! [[ $# -eq 2 ]]; then
install::usage
install::err "Unsupported number of arguments provided!"
return $?
fi
language=$1
language_version=$2
case $language in
elixir)
install::install_elixir
;;
erlang)
install::install_erlang
;;
php)
install::install_php
;;
ruby)
install::install_ruby
;;
node)
install::install_node
;;
*)
install:err "Installation of '${language}' is not yet supported"
return 1;
;;
esac
}