-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load-api.sh
executable file
·46 lines (37 loc) · 1.13 KB
/
load-api.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
#!/bin/bash
# Needs CURL to be installed
function get_content() { #$1: type, $2: default value
file="lenra-api.$1.txt"
if [ -f "$file" ]; then
echo "$(cat $file | grep -Ev '^#|^\s*$' | sed 's/\s+//g')"
elif [ "$2" == "" ]; then
exit 1
else
echo "$2"
fi
}
api_version=$(get_content 'version')
api_files=$(get_content 'files' '*')
function main() {
mkdir -p api
# get the API version from the API dir
current_api_version=$(cat api/api-version.txt || echo "")
# if the versions don't match, then we need to load the new API
if [ "$api_version" != "$current_api_version" ]; then
echo "Loading API version $api_version"
# download the API archive
curl -Ls -o api/api.tar.gz "https://github.com/lenra-io/api/releases/download/v${api_version}/api.tar.gz"
# save the new API version
echo $api_version > api/api-version.txt
fi
cd api
# load the new API files
while IFS= read -r file; do
if [ ! -f "$file" ]; then
echo "Extracting $file from API version $api_version"
# extract the file from the archive
tar -xzf api.tar.gz $file
fi
done <<< "$api_files"
}
main