-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidate_configuration
executable file
·76 lines (60 loc) · 1.44 KB
/
validate_configuration
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
#!/bin/sh
# validate_configuration — Validate Configuration
# Melusina Actions (https://github.com/melusina-org/setup-macports)
# This file is part of Melusina Actions.
#
# Copyright © 2022–2023 Michaël Le Barbier
# All rights reserved.
# This file must be used under the terms of the MIT License.
# This source file is licensed as described in the file LICENSE, which
# you should have received as part of this distribution. The terms
# are also available at https://opensource.org/licenses/MIT
wlog()
{
{
printf '%s: ' "$1"
shift
printf "$@"
printf '\n'
} 1>&2
}
failwith()
{
local OPTIND OPTION OPTARG status
status=1
OPTIND=1
while getopts 'x:' OPTION; do
case ${OPTION} in
x) status="${OPTARG}";;
*) 1>&2 printf 'failwith: %s: Unsupported option.\n' "${OPTION}";;
esac
done
shift $(expr ${OPTIND} - 1)
case "$1" in
[0-9][0-9][0-9]|[0-9][0-9]|[0-9])
status="$1"
shift
;;
*)
:
esac
wlog 'Error' "$@"
exit "${status}"
}
main()
{
if [ "$#" -ne 1 ]; then
failwith 'Exactly one argument is required.'
fi
if [ "$1" = ':no-value' ]; then
return 0
fi
if [ ! -f "$1" ]; then
failwith 'The pathname \047%s\047 does not designate a regular file.' "$1"
fi
if [ ! -r "$1" ]; then
failwith 'The pathname \047%s\047 does not designate a readable file.' "$1"
fi
}
main "$@"
# End of file `validate_configuration'