-
Notifications
You must be signed in to change notification settings - Fork 0
/
ros2_ws_set_metadata
executable file
·92 lines (77 loc) · 1.98 KB
/
ros2_ws_set_metadata
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
#!/bin/bash
set -e
# This checks all ROS packages in the workspace have the same version
# Arguments parsing
# Example:
# ./ros2_ws_set_metadata --src="./workspace/src"
help() {
usage="$(basename "$0") --src=<SRC> [--regex=<REGEX>] [ --help ]
Check all ROS packages in the workspace have the license set
Arguments:
--help Show this help text
--src Source folder of all ros packages (mandatory)
--regex Package name need to match a regex (optional, Default=\".*\")
"
echo "${usage}"
}
for i in "$@"
do
case $i in
--src=*)
SRC="${i#*=}"
shift # past argument=value
;;
--regex=*)
REGEX="${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
if [ -z "${REGEX}" ]; then
REGEX=".*"
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
ret_code="0"
# License
while IFS= read -r -d $'\n'; do
if [[ $(xmllint --xpath 'package/license/text()' "${REPLY}") == *"TODO"* ]]; then
echo "Need to set license in ${REPLY}"
ret_code="1"
fi
done < <(find "${SRC}" -maxdepth 2 -regextype egrep -regex ".*${REGEX}/package.xml")
# Maintainer
while IFS= read -r -d $'\n'; do
if [[ $(xmllint --xpath 'package/maintainer/text()' "${REPLY}") == *"root"* ]]; then
echo "Need to set maintainer in ${REPLY}"
ret_code="1"
fi
done < <(find "${SRC}" -maxdepth 2 -regextype egrep -regex ".*${REGEX}/package.xml")
# Description
while IFS= read -r -d $'\n'; do
if [[ $(xmllint --xpath 'package/description/text()' "${REPLY}") == *"TODO"* ]]; then
echo "Need to set description in ${REPLY}"
ret_code="1"
fi
done < <(find "${SRC}" -maxdepth 2 -regextype egrep -regex ".*${REGEX}/package.xml")
exit ${ret_code}