forked from flexera-public/rightlink_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrs_run
executable file
·76 lines (66 loc) · 2.32 KB
/
rs_run
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
#! /bin/bash
# This script runs a recipe on the local server by asking the RS platform to
# schedule the execution. If passed the -f flag, it follows the audit entry and
# prints what is happening. OOPS, right now it always follows, you can't turn that off!
if ! curl --version >/dev/null; then
echo "ERROR: cannot find curl: it is required for this script, sorry"
exit 1
fi
if [[ -z "$RS_RLL_PORT" || -z "$RS_RLL_SECRET" ]]; then
if ! . <(sudo cat /var/run/rll-secret); then
echo "ERROR: cannot source /var/run/rll-secret to get access to the local proxy for RS API calls"
exit 1
fi
if [[ -z "$RS_RLL_PORT" ]]; then echo "ERROR: RS_RLL_PORT not set"; exit 1; fi
if [[ -z "$RS_RLL_SECRET" ]]; then echo "ERROR: RS_RLL_SECRET not set"; exit 1; fi
#if [[ -z "$RS_SELF_HREF" ]]; then echo "ERROR: RS_SELF_HREF not set"; exit 1; fi
fi
# ===== Parse arguments
# Usage info
show_help() {
cat <<EOT
Usage: ${0##*/} [-options...] [cookbook::]recipe
Run a recipe on the local server
-f follow the script execution and print the audit entry as it unfolds
-h show this help
NOTE: -f is the default and you can't turn it off, someday...
EOT
}
follow=
while getopts "hf" opt; do
case "$opt" in
h) show_help; exit 0 ;;
f) follow=1 ;;
'?') show_help >&2; exit 1 ;;
esac
done
shift "$((OPTIND-1))" # Shift off the options and optional --.
# ===== Parse cookbook::recipe
if [[ -z "$1" ]]; then
echo "ERROR: cookbook::recipe name missing"
show_help;
exit 1
fi
re1='^[-a-zA-Z0-9_][-a-zA-Z0-9_]*::[-a-zA-Z0-9_][-a-zA-Z0-9_]*$'
re2='^[-a-zA-Z0-9_][-a-zA-Z0-9_]*$'
recipe=
if [[ "$1" =~ $re1 ]]; then
recipe=$1
elif [[ "$1" =~ $re2 ]]; then
cook=`basename $PWD`
recipe="$cook::$1"
echo "Running '$recipe' (taking cookbook name from current directory)"
else
echo "ERROR: recipe argument '$1' doesn't look like a cookbook::recipe name"
exit 1
fi
t0=`date '+%s'`
# ===== Make a /rll/run/recipe call to the local RLL
# Note that the body of the response is sent to stdout, this will be the audt entry
# detail of the script execution as it happens...
curl -sS -gG -X POST -H X-RLL-Secret:$RS_RLL_SECRET \
"http://127.0.0.1:$RS_RLL_PORT/rll/run/recipe" \
--data-urlencode "recipe=$recipe"
echo "" # most responses don't include a newline
t1=$(( `date '+%s'` - $t0 ))
echo "********** TOOK ${t1} seconds"