blob: cf4c1a3f3da57c2bb8708abc9543ee7cbd6e0f96 (
plain)
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
|
#!/usr/bin/env bash
source "$(dirname "$BASH_SOURCE")/util.bash"
source "$(dirname "$BASH_SOURCE")/logging.bash"
main() {
[[ -z $1 ]] && usage && exit 2
local action="$1"
shift
debug "Handling action '$action'"
local action_path="$BASEDIR/lib/actions/$action.bash"
debug "Checking $action_path"
if [[ ! -f $action_path ]]
then
debug "No script found to handle action, showing usage"
usage
exit 2
fi
# Set some global defaults
RSTAR_TOOLS=()
RSTAR_BACKEND=moar
RSTAR_PREFIX="$BASEDIR"
# Source the file defining the action.
debug "Sourcing $action_path"
source "$action_path"
# Ensure all required tools are available
depcheck_bin || exit 3
depcheck_perl || exit 3
# TODO: Figure out which OS/distro we're on, to allow for working
# around edge-cases. Probably expose this info as RSTAR_PLATFORM, in an
# associative array.
# Maintain our own tempdir
export TMPDIR="$BASEDIR/tmp"
mkdir -p -- "$TMPDIR"
debug "\$TMPDIR set to $TMPDIR"
# Actually perform the action
debug "Running action"
action "$@"
local action_exit=$?
# Clean up if necessary
if [[ -z $RSTAR_MESSY ]]
then
debug "Cleaning up tempfiles at $TMPDIR"
rm -rf -- "$TMPDIR"
fi
# Use the action's exit code
exit $action_exit
}
usage() {
cat <<EOF
Usage: rstar <action> [options] [arguments]
rstar is the entry point for all utilities to deal with Rakudo Star.
Actions:
clean Clean up the repository.
dist Create a distributable tarball of this repository.
fetch Fetch all required sources.
install Install Raku on this system.
test Run tests on Raku and the bundled ecosystem modules.
EOF
}
# This function checks for the availability of (binary) utilities in the user's
# $PATH environment variable.
depcheck_bin() {
local missing=()
for tool in "${RSTAR_DEPS_BIN[@]}"
do
command -v "$tool" > /dev/null && continue
missing+=("$tool")
done
if [[ ${missing[*]} ]]
then
alert "Some required tools are missing:"
for tool in "${missing[@]}"
do
# TODO: Include current distro's package name
# containing the tool
alert " $tool"
done
return 1
fi
}
# This function checks for the availability of all Perl modules required.
depcheck_perl() {
local missing=()
for module in "${RSTAR_DEPS_PERL[@]}"
do
perl -M"$module" -e 0 2> /dev/null && continue
missing+=("$tool")
done
if [[ ${missing[*]} ]]
then
alert "Some required Perl modules are missing:"
for module in "${missing[@]}"
do
alert " $module"
done
return 1
fi
}
main "$@"
|