fix set -e

This commit is contained in:
Urban Modig
2025-10-01 12:06:27 +02:00
parent 57fcdef4fe
commit 34f6c8dc1d

View File

@ -12,7 +12,7 @@ set -Eeuo pipefail
IFS=$'\n\t'
SCRIPT_NAME=${0##*/}
VERSION="1.2.1"
VERSION="1.2.2"
# ------------------------------- logging & utils -------------------------------
log() { printf '[%s] %s
@ -37,40 +37,27 @@ cleanup_tmp() { rm -rf "$WORKDIR" 2>/dev/null || true; }
# ----------------------------- lock/unlock logic ------------------------------
# Use a fixed numeric FD (200) for wider Bash compatibility (e.g., macOS bash 3.2).
LOCK_FD=200
LOCK_FILE="/tmp/${SCRIPT_NAME}.lock"
LOCK_HELD=0
lock() {
log "Creating lock… ($LOCK_FILE)"
# Use a literal FD number for portability: exec 200>"$LOCK_FILE"
# Open lock file on FD 200 and try to acquire non-blocking lock
exec 200>"$LOCK_FILE" || die "Could not open lock file $LOCK_FILE"
if flock -n 200; then
LOCK_HELD=1
else
die "Lock failed — another process is running."
fi
}>"$LOCK_FILE" || die "Could not open lock file $LOCK_FILE"
if flock -n ${LOCK_FD}; then
LOCK_HELD=1
else
die "Lock failed — another process is running."
fi
}
unlock() {
if (( LOCK_HELD )); then
log "Releasing lock…"
flock -u 200 || true
# Close the FD to avoid lingering descriptors
exec 200>&- || true
LOCK_HELD=0
fi
} || true
# Close the FD to avoid lingering descriptors
exec ${LOCK_FD}>&- || true
LOCK_HELD=0
fi
}
# Always cleanup on exit/interrupt