-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-rebar3.sh
More file actions
executable file
·168 lines (89 loc) · 3.39 KB
/
Copy pathinstall-rebar3.sh
File metadata and controls
executable file
·168 lines (89 loc) · 3.39 KB
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
#!/bin/sh
# Installs from sources by default:
use_prebuilt=1
prebuilt_opt="--prebuilt"
software_dir="${HOME}/Software"
rebar3_target="${software_dir}/rebar3"
usage="Usage: $(basename $0) [-h|--help] [-p|${prebuilt_opt}]: installs properly a recent version of rebar3, by default from its sources (then requires 'git' to be available), according to our conventions (notably the installation is to be done in ${rebar3_target}/ - a directory that can be added to the PATH).
Updating a prior rebar3 installation requires just to hide/remove any existing ${rebar3_target} before running this script.
If the '-p' or '${prebuilt_opt}' option is specified, downloads and installs a prebuilt version of rebar3 instead (then requires 'wget' to be available)."
# See https://www.rebar3.org/docs/getting-started
# Note: quite often, the version obtained from sources was broken and/or had
# issues with at least some proxies, so maybe with a prebuilt binary it will be
# better.
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "${usage}"
exit 0
fi
if [ "$1" = "-p" ] || [ "$1" = "${prebuilt_opt}" ]; then
use_prebuilt=0
echo "A prebuilt version of rebar3 will be installed."
shift
#else
#echo "(rebar3 will be installed from sources)"
fi
if [ ! $# -eq 0 ]; then
echo " Error, too many arguments.
${usage}" 1>&2
exit 5
fi
if [ $use_prebuilt -eq 0 ]; then
dir_name="rebar3-prebuilt"
rebar_target_dir="${software_dir}/${dir_name}"
if [ -d "${rebar_target_dir}" ]; then
echo " Error, a '${rebar_target_dir}' target directory already exists, please remove it first." 1>&2
exit 10
fi
prebuilt_rebar3_url="https://s3.amazonaws.com/rebar3/rebar3"
echo " Installing a prebuilt version of rebar3, from ${prebuilt_rebar3_url}."
mkdir -p "${rebar_target_dir}"
cd "${rebar_target_dir}"
wget="$(which wget 2>/dev/null)"
if [ ! -x "${wget}" ]; then
echo " Error, wget is not available." 1>&2
exit 20
fi
if "${wget}" --quiet ${prebuilt_rebar3_url}; then
chmod +x ./rebar3
else
echo " Failed to download a prebuilt version of rebar3 from ${prebuilt_rebar3_url}." 1>&2
exit 15
fi
else
dir_name="rebar3-from-sources"
rebar_target_dir="${software_dir}/${dir_name}"
if [ -d "${rebar_target_dir}" ]; then
echo " Error, a '${rebar_target_dir}' target directory already exists, please remove it first." 1>&2
exit 20
fi
clone_url="https://github.com/erlang/rebar3.git"
echo " Installing rebar3 from sources (${clone_url})."
mkdir -p "${software_dir}"
cd "${software_dir}"
git="$(which git 2>/dev/null)"
if [ ! -x "${git}" ]; then
echo " Error, git is not available." 1>&2
exit 21
fi
#echo "Cloning..."
if ! "${git}" clone ${clone_url} "${dir_name}"; then
echo " Installation from sources failed (clone)." 1>&2
exit 50
fi
if ! cd "${dir_name}"; then
echo " Installation from sources failed (cd)." 1>&2
exit 51
fi
echo "Bootstrapping..."
if ! ./bootstrap; then
echo " Installation from sources failed (bootstrap)." 1>&2
exit 52
fi
fi
cd ..
# To prevent the next link to be created in any prior rebar3 directory:
if [ -L "rebar3" ]; then
/bin/rm -f rebar3
fi
ln -sf --no-target-directory "${dir_name}" rebar3
echo " Installation success; please ensure that the '${rebar3_target}' directory is in your PATH for good, and that it is not eclipsed (e.g. by a /usr/local/bin/rebar3); this just installed version is: $(${rebar3_target}/rebar3 -v)."