-
Notifications
You must be signed in to change notification settings - Fork 0
/
shvr.sh
executable file
·73 lines (56 loc) · 1.07 KB
/
shvr.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
#!/usr/bin/env sh
# Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
# SPDX-License-Identifier: ISC
set -euf
SHVR_DIR_SELF="$(cd "$(dirname "$0")"; pwd)"
SHVR_DIR_SRC="${SHVR_DIR_SRC:-"/usr/src/shvr"}"
SHVR_DIR_OUT="${SHVR_DIR_OUT:-"/opt"}"
shvr ()
{
shvr_"${@:-}"
}
shvr_build ()
{
if test -z "$*"
then set -- $(printf '%s ' $(shvr_targets))
fi
set -x
shvr_each build "${@:-}"
}
shvr_targets ()
{
if test -z "$*"
then set -- $(printf '%s ' $(shvr_interpreters))
fi
shvr_each targets "${@:-}"
}
shvr_current ()
{
if test -z "$*"
then set -- $(printf '%s ' $(shvr_interpreters))
fi
shvr_each current "${@:-}"
}
shvr_interpreters ()
{
find "${SHVR_DIR_SELF}/variants" -type f |
while read -r variant_file
do basename "${variant_file}" | sed 's/\.sh$//'
done |
sort
}
shvr_each ()
{
subcommand="$1"
shift
while test $# -gt 0
do
interpreter="${1%%_*}"
version="${1#*_}"
. "${SHVR_DIR_SELF}/variants/${interpreter}.sh"
"shvr_${subcommand}_${interpreter}" "$version"
rm -Rf "${SHVR_DIR_SRC}/${interpreter}"
shift
done
}
shvr "${@:-}"