-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
126 lines (113 loc) · 2.24 KB
/
entrypoint.sh
File metadata and controls
126 lines (113 loc) · 2.24 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh
# SPDX-FileCopyrightText: 2025 Alexandre Gomes Gaigalas <alganet@gmail.com>
# SPDX-License-Identifier: ISC
# Script intended to be ran from inside the docker container
# Keep compatibility with direct shell execution
if test -f "$1"
then
exec "$@"
exit $?
fi
display_run () {
echo "# $1"
if test "x$*" = "x$1"
then set -- "$1" -c ':'
fi
"${@:-}"
}
display_compare () {
if test "$1" = "$COMPARE"
then return 0
fi
OUTPUT="$("$@")"
if test "x$OUTPUT" = "x$EXPECTED"
then
echo "# OK $1"
else
echo "# NOT OK $1"
echo "$OUTPUT"
fi
}
COMPARE=''
EXPECTED=''
MATCH='*'
ACTION=display_run
while test -n "$1" && test "${1#--}" != "$1"
do
case "${1:-}" in
--help)
echo "Usage: entrypoint.sh [--match <shell-name>] [--compare <reference-shell>] <commands>"
echo
echo "Examples:"
echo " # List all shells"
echo " entrypoint.sh"
echo " # Run a command in all shells matching 'ash*'"
echo " entrypoint.sh --match 'ash*' -c 'echo Hello World'"
echo " # Compare output of a command against a reference shell"
echo " entrypoint.sh --compare '/opt/bash_5.3/bin/bash' -c 'echo \${BASH_VERSION:-}'"
exit 0
;;
--match)
if ! test -n "$2" || test "${2#--}" != "$2"
then
echo "Error: --match requires an argument" >&2
exit 1
fi
MATCH="$2"
shift 2
;;
--compare)
if ! test -n "$2" || test "${2#--}" != "$2"
then
echo "Error: --match requires an argument" >&2
exit 1
fi
ACTION=display_compare
COMPARE="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done
if test -n "$COMPARE"
then
if ! test -x "$COMPARE"
then
echo "Error: reference shell '$COMPARE' is not executable" >&2
exit 1
fi
echo "--- REFERENCE ---"
echo "# $COMPARE"
EXPECTED="$("$COMPARE" "$@")"
echo "$EXPECTED"
echo "--- TESTS ---"
fi
RAN_SOMETHING=0
while read -r sh_path || test -n "$sh_path"
do
if test "$MATCH" != '*'
then
sh_name="${sh_path#'/opt/'}"
sh_name="${sh_name%'/bin'*}"
eval "
case \$sh_name in
$MATCH) : ;;
*) continue ;;
esac
"
fi
$ACTION "$sh_path" "$@"
RAN_SOMETHING=1
done < /opt/shvr/manifest.txt
if test "$RAN_SOMETHING" = 0
then
echo "Error: no shells matched '$MATCH'" >&2
exit 1
fi