-
Notifications
You must be signed in to change notification settings - Fork 54
/
queue-push.sh
executable file
·73 lines (63 loc) · 1.61 KB
/
queue-push.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
#!/bin/bash
#
#
# Put a new version into the build queue
#
#
# Function to display usage and exit
usage_exit() {
echo "Usage: $0 -v version [-r recipe ...]"
exit "${1:-0}" # Exit with provided code or default to 0
}
__dirname="$(CDPATH= cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Bring location of the build queue file into scope
source "${__dirname}/_config.sh"
# Bring the lock functions into scope
source "${__dirname}/_lock.sh"
# Variable declaration
version=""
recipes_to_build=()
# Parse options
while getopts "v:r:" opt; do
case $opt in
v)
version="$OPTARG"
;;
r)
if ! recipe_exists "$OPTARG"; then
echo "Error: Recipe '$OPTARG' does not exist."
usage_exit 1
fi
recipes_to_build+=("$OPTARG")
;;
\?)
echo "Invalid option: -$OPTARG" >&2;
usage_exit 1
;;
:)
echo "Invalid option: $OPTARG requires an argument" 1>&2
usage_exit
;;
esac
done
shift $((OPTIND-1))
# Exit if no version was passed via -v
if [ -z "$version" ]; then
usage_exit 1
fi
recipes_string="" # No recipes provided, default to all (handled later)
if [ ${#recipes_to_build[@]} -gt 0 ]; then
# Join the array of passed recipes using a comma separator
recipes_string=$(IFS=,; echo "${recipes_to_build[*]}")
fi
# Acquire a lock on the build queue
acquire_lock "build_queue"
# Add the version (and optionally recipes) to the queue
echo "Queuing $version with recipes: ${recipes_string:-"all"}"
if [[ -n "$recipes_string" ]]; then
echo "$version|$recipes_string" >> "$queuefile"
else
echo "$version" >> "$queuefile"
fi
# Release the lock
release_lock