-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallah.sh
66 lines (58 loc) · 1.64 KB
/
wallah.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
wallah::num_dot () {
tr -d -C 0123456789.
}
get_node_version_from_package_json() {
if [[ ! -f "../package.json" ]]; then
return
fi
echo $("${wallah_bin}/get_json_value" "../package.json" "engines.node") | num_dot 2>/dev/null
}
wallah::download() {
local url="$1"
local archive="$2"
local cache_dir="${HOME}/.wallah/cache"
local cached_archive="${cache_dir}/${archive}"
if [[ ! -f "${cached_archive}" ]]; then
mkdir -p "${cache_dir}"
curl --silent --output "${cached_archive}" "${url}"
fi
echo "${cached_archive}"
}
wallah::parse_node_args() {
for arg in $@; do
if [[ "${arg}" =~ ^(x64|x86) ]]; then
wallah_node_cpu="${arg}"
continue;
fi
if [[ "${arg}" =~ ^(linux|darwin|sunos)$ ]]; then
wallah_node_platform="${arg}"
continue;
fi
# I am aware this semver regex is imperfect
if [[ "${arg}" =~ ^v?([0-9]+\.){2}[0-9]+ ]]; then
wallah_node_version=$(echo ${arg} | tr -d v)
continue;
fi
# If the arg doesn't look like anything else, assume first one
# is the wallah_node_root
if [[ -z "${wallah_node_root}" ]]; then
wallah_node_root="${arg}"
fi
done
##### Compute default values as necessary #####
if [[ -z "${wallah_node_cpu}" ]]; then
wallah_node_cpu=x64
if [[ "$(uname -p)" = "i686" ]]; then
wallah_node_cpu=x86
fi
fi
if [[ -z "${wallah_node_root}" ]]; then
wallah_node_root="${wallah_bin}/../../node"
fi
if [[ -z "${wallah_node_platform}" ]]; then
wallah_node_platform="$(uname | tr A-Z a-z)"
fi
if [[ -z "${wallah_node_version}" ]]; then
wallah_node_version="$(get_node_version_from_package_json)"
fi
}