-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathros2_ws_get_version
More file actions
executable file
·66 lines (52 loc) · 1.02 KB
/
ros2_ws_get_version
File metadata and controls
executable file
·66 lines (52 loc) · 1.02 KB
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
#!/bin/bash
set -e
# This gets the version of the packages
# Arguments parsing
# Example:
# ./ros2_ws_get_version --src="./ros/src"
help() {
usage="$(basename "$0") --src=<SRC> [ --help ]
Get version to check
Arguments:
--help Show this help text
--src Source folder of all ros packages (mandatory)
"
echo "${usage}"
}
for i in "$@"
do
case $i in
--src=*)
SRC="${i#*=}"
shift # past argument=value
;;
--help)
HELP=YES
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
# Arguments check
if [ -n "${HELP}" ]; then
help
exit 0
fi
if [ -z "${SRC}" ]; then
help
exit 1
fi
# Will throw an error if not installed
if ! command -v xmllint &> /dev/null
then
echo "xmllint could not be found. Please install it"
exit 1
fi
# Checking package.xml
result=$(find "${SRC}" -name package.xml -exec xmllint --xpath 'package/version/text()' {} \; | tr '\n' ' ')
array=()
IFS=', ' read -r -a array <<< "${result}"
version="${array[0]}"
echo "${version}"