Browse Source

chg: remove requirement on ``sha256sum``

Also provide and use a ``hash_get`` function that will choose in the
available binary program. It supports ``sha512sum``, ``md5sum`` (GNU
version) and ``md5`` (BSD version).

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
cache-relation
Valentin Lab 5 years ago
parent
commit
656069c59a
  1. 37
      bin/compose

37
bin/compose

@ -17,16 +17,18 @@
ANSI_ESC=$'\e['
md5_compat() {
if get_path md5sum >/dev/null; then
md5_compat() { md5sum | cut -c -32; }
hash_get() {
if get_path sha256sum >/dev/null; then
hash_get() { local x; x=$(sha256sum) || return 1; echo "${x:0:32}"; }
elif get_path md5sum >/dev/null; then
hash_get() { local x; x=$(md5sum) || return 1; echo "${x:0:32}"; }
elif get_path md5 >/dev/null; then
md5_compat() { md5; }
hash_get() { md5; }
else
die "$exname: required GNU or BSD date not found"
err "required GNU md5sum or BSD md5 not found"
return 1
fi
md5_compat
hash_get
}
@ -408,14 +410,14 @@ get_hash_image() {
p0 ""
[ -n "$override" ] && cat "$override"
true
} | md5_compat
} | hash_get
return "${PIPESTATUS[0]}"
}
get_compose_file_opt() {
local hash_bin="$1" override="$2" \
cache_file="$COMPOSE_LAUNCHER_CACHE/$FUNCNAME.cache.$(p0 "$@" | md5_compat)"
cache_file="$COMPOSE_LAUNCHER_CACHE/$FUNCNAME.cache.$(p0 "$@" | hash_get)"
if [ -e "$cache_file" ]; then
cat "$cache_file" &&
touch "$cache_file" || return 1
@ -454,7 +456,7 @@ get_compose_file_opt() {
replace_compose_file_opt() {
local hash_bin="$1" override="$2" \
cache_file="$COMPOSE_LAUNCHER_CACHE/$FUNCNAME.cache.$(p0 "$@" | md5_compat)"
cache_file="$COMPOSE_LAUNCHER_CACHE/$FUNCNAME.cache.$(p0 "$@" | hash_get)"
if [ -e "$cache_file" ]; then
cat "$cache_file" &&
touch "$cache_file" || return 1
@ -565,7 +567,7 @@ get_compose_single_opts_list() {
get_volume_opt() {
local cache_file="$COMPOSE_LAUNCHER_CACHE/$FUNCNAME.cache.$(p0 "$@" | md5_compat)"
local cache_file="$COMPOSE_LAUNCHER_CACHE/$FUNCNAME.cache.$(p0 "$@" | hash_get)"
if [ -e "$cache_file" ]; then
cat "$cache_file" &&
touch "$cache_file" || return 1
@ -800,7 +802,7 @@ mk_docker_run_options() {
## get TZ value and prepare TZ_PATH
TZ=$(get_tz) || return 1
mkdir -p "${TZ_PATH}"
TZ_PATH="${TZ_PATH}/$(e "$TZ" | sha256sum | cut -c 1-8)" || return 1
TZ_PATH="${TZ_PATH}/$(e "$TZ" | hash_get | cut -c 1-8)" || return 1
[ -e "$TZ_PATH" ] || e "$TZ" > "$TZ_PATH"
## CACHE/DATA DIRS
@ -913,7 +915,7 @@ mk_docker_run_options() {
## Docker host is not same linux than WSL, so
## access to root files are not the same.
##YYYvlab, check on cp where is the base
dst="$COMPOSE_LAUNCHER_CACHE/compose.$(md5_compat < "$compose_file").yml"
dst="$COMPOSE_LAUNCHER_CACHE/compose.$(hash_get < "$compose_file").yml"
cp "$compose_file" "$dst"
## docker host start with /c/... whereas WSL could start with /mnt/c/...
local="$dst"
@ -938,12 +940,11 @@ mk_docker_run_options() {
clean_unused_sessions
filename=$(mktemp -p /tmp/ -t launch_opts-XXXXXXXXXXXXXXXX)
p0 "${docker_run_opts[@]}" > "$filename"
sha=$(sha256sum "$filename")
sha=${sha:0:64}
src="$SESSION_DIR/$UID-$sha"
dest="/var/lib/compose/sessions/$UID-$sha"
hash=$(hash_get < "$filename") || return 1
src="$SESSION_DIR/$UID-$hash"
dest="/var/lib/compose/sessions/$UID-$hash"
additional_docker_run_opts=(
"-v" "$SESSION_DIR/$UID-$sha:$dest:ro"
"-v" "$SESSION_DIR/$UID-$hash:$dest:ro"
"-e" "COMPOSE_LAUNCHER_OPTS=$dest"
"-e" "COMPOSE_LAUNCHER_BIN=$COMPOSE_LAUNCHER_BIN"
)

Loading…
Cancel
Save