This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·65 lines (58 loc) · 1.96 KB
/
init.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
#!/usr/bin/env bash
#
# Init script to download latest released version of this repository
set -euo pipefail
repo_url='https://github.com/Datameer-Inc/platform-utils'
latest_url="${repo_url}/releases/latest"
root_dir="${PU_BASE_INSTALL_DIR:-/tmp}"
function die() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
exit 1
}
function info() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*"
}
function get_latest_release() {
if ! latest_release_url=$(curl -fsSLI -o /dev/null -w %{url_effective} "${latest_url}"); then
die "Problem getting ${latest_url}"
fi
if [[ $latest_release_url =~ releases/tag ]]; then
latest_release="${latest_release_url//*\//}"
else
latest_release='master'
fi
}
function download_and_extract() {
get_latest_release
release=${CUSTOM_RELEASE:-$latest_release}
[ -n $release ] || die "Couldn't find platform-utils release."
download_file="${release}.tar.gz"
download_url="${repo_url}/archive/${download_file}"
install_path="${root_dir}/platform-utils/${release}"
latest_path="${root_dir}/platform-utils/latest"
if [ -d "${install_path}" ]; then
info "Install path already exists. No need to install..."
elif [ -e "${install_path}" ]; then
die "Install path already exists but not a directory."
else
info "Deleting any previous installations at '$(dirname ${install_path})'"
rm -rf "$(dirname ${install_path})"
info "Downloading '${download_url}' to directory '${install_path}'"
mkdir -p "${install_path}"
curl -fsSL -o "${install_path}/${download_file}" "${download_url}"
cd "${install_path}"
info "Extracting '${download_file}'"
tar xzf "${download_file}" --strip 1
cd -
info "Setting symlink '${install_path}' -> '${latest_path}'"
rm -f "${latest_path}"
ln -sf "${install_path}" "${latest_path}"
fi
}
download_and_extract
tools_script="${latest_path}/process-tools.sh"
if [ ! -f "${tools_script}" ]; then
die "Could not find ${tools_script}"
else
"${tools_script}"
fi