1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00
falk-werner_webfuse/build/get_container_id.sh
nosamad 1d413456a2 fix(webfuse): fix macros (#18)
* fixes return code on error

* fixes macro usage

* adds clean target

* fixes file mode

* fixes image name

* adds registry prefix to allow usage of custom registry (on-premise)

* changes syntax in travis file for package installation

* fixes duplicate settings discovery
2019-03-29 13:23:17 +01:00

40 lines
722 B
Bash
Executable File

#!/bin/sh
set -e
container_id() {
if [ "$#" -le 0 ]; then
# shellcheck disable=SC2119
container_id_by_cgroup
else
"$DOCKER" inspect --format='{{.Id}}' "$@"
fi
}
# shellcheck disable=SC2120
container_id_by_cgroup() {
impl_container_id_by_cgroup "$@" || return "$?"
}
impl_container_id_by_cgroup() {
file="${1:-/proc/self/cgroup}"
while IFS= read -r cmd; do
id="$(echo "$cmd" | sed -n -e 's/[^:]*:[^:]*:.*\/\([0-9a-fA-F]\+\)$/\1/p')"
if container_id "$id" >/dev/null 2>&1; then
echo "$id"
return 0
fi
done < "$file"
return 1
}
DOCKER="${DOCKER:-docker}"
if [ -z "${CONTAINER+x}" ] && [ -n "$DOCKER" ]; then
CONTAINER="$(container_id "$@")"
fi
echo "$CONTAINER"