-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
244 lines (223 loc) · 5.63 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
#!/bin/sh
set -eo pipefail
# Docs: https://github.com/lf-lang/installation
# Author: [email protected]
# License: BSD-2
tools=("cli" "epoch")
selected=()
timestamp=$(date '+%Y%m%d%H%M%S')
if [[ $(uname -m) == 'arm64' ]]; then
arch='aarch64'
else
arch='x86_64'
fi
if [[ "$OSTYPE" == "linux"* ]]; then
os="Linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
os="MacOS"
else
echo "Error: Unsupported operating system: $OSTYPE" >&2
exit 1
fi
install() (
case $1 in
cli)
mkdir -p $share/cli
cp -rf $dir/* $share/cli
ln -sf $share/cli/bin/lfc $bin/lfc
ln -sf $share/cli/bin/lfd $bin/lfd
ln -sf $share/cli/bin/lff $bin/lff
echo " - Installed: $(ls -m $dir/bin/)"
;;
epoch)
if [[ "$os" == "MacOS" ]]; then
cp -rf $dir /Applications/
xattr -cr /Applications/Epoch.app
rm -rf $prefix/bin/epoch
touch $bin/epoch
chmod +x $bin/epoch
echo '#!/bin/bash' > $bin/epoch
echo 'open /Applications/Epoch.app --args $@' >> $bin/epoch
else
cp -rf $dir $share/
ln -sf $share/epoch/epoch $bin/epoch
fi
echo " - Installed: epoch"
;;
esac
)
cleanup() (
case $1 in
cli|epoch)
rm -rf $dir
;;
esac
)
download() (
echo " - Downloading and unpacking into $dir"
mkdir -p $tmp
if [[ "$url" =~ .*tar\.gz$ ]];then
curl -L --progress-bar $url | tar xfz - -C $tmp
elif [[ "$url" =~ .*zip$ ]];then
file="$tmp/lf-install-$timestamp.zip"
curl -L --progress-bar $url -o $file
unzip -qq -d $tmp $file
rm -rf $file
else
echo "Unsuccessful. Unrecognized file format."
fi
)
# Parse arguments
for i in "$@"
do
case $i in
-v|--version)
echo "install.sh $version"
exit 0
;;
-p=*|--prefix=*)
prefix=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
-t=*|--temporary=*)
tmp=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
all)
selected=("${tools[@]}")
;;
cli)
selected+=("cli")
;;
epoch)
selected+=("epoch")
;;
nightly)
if [[ -z $kind ]]; then
kind="nightly"
else
echo "Error: You can only use one qualifier; choose 'stable' or 'nightly'" >&2
exit 1
fi
;;
stable)
if [[ -z $kind ]]; then
kind="latest"
else
echo "Error: You can only use one qualifier; choose 'stable' or 'nightly'"
exit 1
fi
;;
v[0-9]*.[0-9]*.[0-9]*|[0-9]*.[0-9]*.[0-9]*)
if [[ -n $kind ]]; then
echo "Error: Either use a version number or a qualifier ('stable' or 'nightly'), not both" >&2
exit 1
fi
version=${i#v}
supported="^(0\.([5-9][0-9]*|[1-9][0-9]+)\.[0-9]+)|(([1-9][0-9]*)\.[0-9]+\.[0-9]+)$"
if ! [[ $version =~ $supported ]]; then
echo "Error: Only versions 0.5.0 and up can be installed using this script" >&2
exit 1
fi
;;
*)
echo "Error: Unknown option: $i"
exit 1
;;
esac
done
# Either use the supplied version, nightly, or latest.
if [[ -n $version ]]; then
suffix="tags/v${version}"
else
if [[ "$kind" == "nightly" ]]; then
suffix="tags/nightly"
else
suffix="latest"
fi
fi
# Use ~/.local default prefix
if [[ -z $prefix ]]; then
prefix=~/.local
fi
# Use /tmp as the default temporary storage
if [[ -z $tmp ]]; then
tmp="/tmp/lingua-franca"
else
tmp="${tmp%/}/lingua-franca"
fi
share="$prefix/share/lingua-franca"
bin="$prefix/bin"
# Require a tool to be selected
if [ ${#selected[@]} -eq 0 ]; then
echo "Error: Please specify a tool to install. To install all tools, use 'all'." >&2
exit 1
fi
# Create installation directories if necessary
if [ ! -d $bin ]; then
echo "> Creating directory $bin"
mkdir -p $bin;
fi
if [ ! -d $share ]; then
echo "> Creating directory $share"
mkdir -p $share;
fi
# Install the selected tools
for tool in "${selected[@]}"; do
case $tool in
cli)
description="CLI tools"
rel="https://api.github.com/repos/lf-lang/lingua-franca/releases/$suffix"
echo "> Fetching data from $rel ..."
resp=$(curl --retry 5 --retry-delay 2 --retry-max-time 30 -L -s -f -H "Accept: application/vnd.github+json" "$rel")
resp_ok=$?
if [ $resp_ok -ne 0 ]; then
echo "Error: Failed to fetch data from $rel" >&2
exit 1
fi
kvp=$(echo "$resp" | grep "download_url" | grep "$os-$arch.tar.gz")
arr=($kvp)
url="${arr[1]//\"/}"
file=$(echo $url | grep -o '[^/]*\.tar.gz')
dir=$tmp/"${file%.tar.gz}"
;;
epoch)
description="Epoch IDE"
if [[ "$os" == "Linux" ]]; then
os_abbr="linux"
elif [[ "$os" == "MacOS" ]]; then
os_abbr="mac"
fi
rel="https://api.github.com/repos/lf-lang/epoch/releases/$suffix"
echo "> Fetching data from $rel ..."
resp=$(curl --retry 5 --retry-delay 2 --retry-max-time 30 -L -s -f -H "Accept: application/vnd.github+json" "$rel")
resp_ok=$?
if [ $resp_ok -ne 0 ]; then
echo "Error: Failed to fetch data from $rel" >&2
exit 1
fi
kvp=$(echo "$resp" | grep "download_url" | grep "$arch" | grep "$os_abbr")
arr=($kvp)
url="${arr[1]//\"/}"
if [[ "$os" == "MacOS" ]]; then
dir="$tmp/epoch.app"
else
dir="$tmp/epoch"
fi
;;
*)
echo "> Unable to install $tool."
continue
;;
esac
echo "> Installing the ${kind:-$version} release for $os-$arch of $description..."
# Download
cleanup $tool
echo " * Downloading from $url"
download $tool
# Install and remove tmp files
echo " * Installing from $tmp into $prefix"
install $tool
echo " * Removing temporary files"
cleanup $tool
done
echo "> Done. Please ensure that $bin is on your PATH."
echo ""