mirror of
https://github.com/lobaro/restic-backup-docker.git
synced 2026-11-14 16:02:43 +00:00
test: probe the image once for all features
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
421006e90b
commit
bc3dfcd950
1 file changed
+19
-15
+19
-15
@@ -211,24 +211,28 @@ feature_is_required() {
|
|||||||
| grep -qx "[[:space:]]*${feature}[[:space:]]*"
|
| grep -qx "[[:space:]]*${feature}[[:space:]]*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# One throwaway container probes the image for all features at once; the
|
||||||
|
# result is cached so every has_feature call after the first is free.
|
||||||
|
FEATURE_PROBE=""
|
||||||
|
FEATURE_PROBED=0
|
||||||
|
|
||||||
|
probe_features() {
|
||||||
|
[ "$FEATURE_PROBED" -eq 0 ] || return 0
|
||||||
|
FEATURE_PROBE="$(docker run --rm --entrypoint sh "$IMAGE" -c '
|
||||||
|
grep -q RESTIC_STREAM /bin/backup && echo stream
|
||||||
|
command -v docker >/dev/null && echo docker-cli
|
||||||
|
command -v bash >/dev/null && echo bash
|
||||||
|
command -v msmtp >/dev/null && echo msmtp
|
||||||
|
true' 2>/dev/null | tr -d '\r')"
|
||||||
|
FEATURE_PROBED=1
|
||||||
|
}
|
||||||
|
|
||||||
# has_feature <name> - detection runs against the built image, not the source
|
# has_feature <name> - detection runs against the built image, not the source
|
||||||
has_feature() {
|
has_feature() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
stream)
|
stream|docker-cli|bash|msmtp)
|
||||||
docker run --rm --entrypoint sh "$IMAGE" -c \
|
probe_features
|
||||||
'grep -q RESTIC_STREAM /bin/backup' >/dev/null 2>&1
|
printf '%s\n' "$FEATURE_PROBE" | grep -qx "$1"
|
||||||
;;
|
|
||||||
docker-cli)
|
|
||||||
docker run --rm --entrypoint sh "$IMAGE" -c \
|
|
||||||
'command -v docker' >/dev/null 2>&1
|
|
||||||
;;
|
|
||||||
bash)
|
|
||||||
docker run --rm --entrypoint sh "$IMAGE" -c \
|
|
||||||
'command -v bash' >/dev/null 2>&1
|
|
||||||
;;
|
|
||||||
msmtp)
|
|
||||||
docker run --rm --entrypoint sh "$IMAGE" -c \
|
|
||||||
'command -v msmtp' >/dev/null 2>&1
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "unknown feature: $1" >&2
|
echo "unknown feature: $1" >&2
|
||||||
|
|||||||
Reference in new issue
Block a user