-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind.sh
executable file
·67 lines (49 loc) · 1.16 KB
/
find.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
#!/bin/sh
BASEDIR=`dirname -- "$0"` || exit $?
BASEDIR=`realpath -- "${BASEDIR}"` || exit $?
. "${BASEDIR}/lib.subr"
main()
{
if [ $# -lt 1 ]; then
usage
exit ${EX_USAGE}
fi
local tags
tags="$1"
local vm_bhyve_dir
vm_bhyve_dir=`sysrc -ni vm_dir`
if [ -z "${vm_bhyve_dir}" ]; then
err "Could not get vm(1) directory!"
exit ${EX_NOINPUT}
fi
local pattern_file
pattern_file=`mktemp`
local tag
for tag in ${tags}; do
printf "%s\n" "${tag}"
done > "${pattern_file}" || exit $?
local next_id
next_id=1
while :; do
if [ ${next_id} -ge 999 ]; then
break
fi
local next_name
next_name=`printf "vm%003d" "${next_id}"`
local tags_file
tags_file="${vm_bhyve_dir}/${next_name}/.tags"
if [ -f "${tags_file}" ]; then
if rg --pcre2 -qf "${pattern_file}" "${tags_file}"; then
printf "%s\n" "${next_name}"
fi
fi
next_id=$((next_id+1))
done | sort | uniq
rm -f "${pattern_file}"
return ${EX_OK}
}
usage()
{
echo "usage: find.sh <tags>"
}
main "$@"