-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_script_dependencies
More file actions
executable file
·103 lines (88 loc) · 1.76 KB
/
list_script_dependencies
File metadata and controls
executable file
·103 lines (88 loc) · 1.76 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
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
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
#
# List dependencies of the script.
#
# Dependencies: coreutils, grep, util-linux
set -o nounset -o pipefail
readonly L_OPTS="help,optional,version"
readonly OPTS="hoVv"
readonly CMD="${0##*/}"
readonly USAGE="${CMD} [OPTION]... FILE"
readonly USAGE_ERR_MSG=$(
cat <<END
Usage: ${USAGE}
Try '${CMD} --help' for more information.
END
)
readonly VERSION_INFO=$(
cat <<END
${CMD} (scripts) 1.0.0
This is free and unencumbered software released into the public domain.
For more information, please refer to <https://unlicense.org/>.
END
)
readonly HELP=$(
cat <<END
SYNOPSIS
${USAGE}
DESCRIPTION
List dependencies of the script FILE.
OPTIONS
-h, --help
display this help and exit
-o, --optional
list optional dependencies instead of the required
-V, -v, --version
display version and exit
END
)
opts=$(getopt --options=${OPTS} --longoptions=${L_OPTS} --name "${CMD}" -- "$@")
if (($? != 0)); then
echo "${USAGE_ERR_MSG}"
exit 2
fi
eval set -- "${opts}"
need_help=false
need_optional=false
need_version=false
while true; do
case "$1" in
-h | --help)
need_help=true
shift
break
;;
-o | --optional)
need_optional=true
shift
;;
-V | -v | --version)
need_version=true
shift
break
;;
--)
shift
break
;;
esac
done
if [[ $need_help == true ]]; then
echo "${HELP}"
exit 0
fi
if [[ $need_version == true ]]; then
echo "${VERSION_INFO}"
exit 0
fi
if (($# != 1)); then
echo "${CMD}: expected 1 argument; got $#"
echo "${USAGE_ERR_MSG}"
exit 2
fi
prefix="# Dependencies:"
if [[ $need_optional == true ]]; then
prefix="# Optional dependencies:"
fi
grep --only-match --perl-regexp "^${prefix}\s+\K.*" "$1" \
| tr --squeeze-repeats ", " "\n"