This repository has been archived by the owner on Mar 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·124 lines (104 loc) · 2.93 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
#!/bin/bash
set -e
main() {
if [ -z "$OTP_VERSION" ]; then
echo "Please set at least OTP_VERSION environment variable!"
echo
echo "Usage: install.sh"
echo
echo "Supported environment variables:"
echo
echo " - OTP_VERSION"
echo " - ELIXIR_VERSION"
echo " - GLEAM_VERSION"
exit 1
fi
TMPDIR="${TMPDIR:=/tmp}/beamup-install"
mkdir -p $TMPDIR
cd $TMPDIR
install_otp $OTP_VERSION
if [ -n "${ELIXIR_VERSION}" ]; then
cd $TMPDIR
install_elixir ${ELIXIR_VERSION}
fi
if [ -n "${GLEAM_VERSION}" ]; then
cd $TMPDIR
install_gleam ${GLEAM_VERSION}
fi
echo
echo "Installation complete!"
echo
echo "Add this directory to your PATH:"
echo
echo " export PATH=$root/bin:\$PATH"
echo
}
install_otp() {
version=$1
release=otp-${version}-$(uname -sm | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
url=https://github.com/burrito-elixir/erlang-builder/releases/download/OTP-$version/$release.tar.gz
echo ">> downloading $url"
curl --fail -LO $url
tar xzf $release.tar.gz
root=$HOME/.local/share/beamup
otp_root=$root/installs/otp
echo ">> installing to $otp_root/$version"
rm -rf $otp_root/$version
mkdir -p $otp_root
mv $release $otp_root/$version
cd $otp_root/$version
./Install -sasl $PWD
url=https://s3.amazonaws.com/rebar3/rebar3
echo ">> downloading $url"
echo ">> installing rebar3 to $otp_root/$version"
curl --fail -L $url > $otp_root/$version/bin/rebar3
chmod +x $otp_root/$version/bin/rebar3
mkdir -p $root/bin
ln -fs $otp_root/$version/bin/* $root/bin
}
install_elixir() {
version=$1
url=https://github.com/elixir-lang/elixir/releases/download/v$version/Precompiled.zip
echo ">> downloading $url"
curl --fail -LO $url
unzip -q -d elixir-$version Precompiled.zip
root=$HOME/.local/share/beamup
elixir_root=$root/installs/elixir
echo ">> installing to $elixir_root/$version"
rm -rf $elixir_root/$version
mkdir -p $elixir_root
mv elixir-$version $elixir_root/$version
mkdir -p $root/bin
ln -fs $elixir_root/$version/bin/* $root/bin
}
install_gleam() {
version=$1
case $(uname -s) in
# TODO: $(uname -sm | tr '[:upper:]' '[:lower:]' | tr ' ' '-') or something should do the trick
# we need to fix https://github.com/gleam-lang/gleam/blob/v0.14.2/.github/workflows/release.yaml#L29
"Linux")
extra=linux-amd64
;;
"Darwin")
extra=macos
;;
*)
echo $(uname -s) is not supported
exit 1
;;
esac
release=gleam-v$version-$extra
url=https://github.com/gleam-lang/gleam/releases/download/v$version/$release.tar.gz
echo ">> downloading $url"
curl --fail -LO $url
tar xzf $release.tar.gz
root=$HOME/.local/share/beamup
gleam_root=$root/installs/gleam
echo ">> installing to $gleam_root/$version"
rm -rf $gleam_root/$version
mkdir -p $gleam_root/$version
mv gleam $gleam_root/$version
mkdir -p $root/bin
ln -fs $gleam_root/$version/gleam $root/bin/
}
main