mirror of
https://github.com/samuelncui/yatm.git
synced 2026-11-08 12:26:33 +00:00
38 lines
907 B
Bash
Executable File
38 lines
907 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
mkdir -p "${TAPE_DIR}"
|
|
|
|
main() {
|
|
command -v fuser >/dev/null
|
|
command -v mt >/dev/null
|
|
CURDIR=$(cd "$(dirname "$0")"; pwd)
|
|
SG_DEVICE=$("${CURDIR}/get_device")
|
|
|
|
sleep 2
|
|
umount -- "${MOUNT_POINT}"
|
|
|
|
deadline=$(($(date +%s) + 600))
|
|
while fuser -s "${SG_DEVICE}"; do
|
|
if (($(date +%s) >= deadline)); then
|
|
echo "Tape device is still in use after unmount: ${SG_DEVICE}" >&2
|
|
exit 1
|
|
fi
|
|
sleep 2
|
|
done
|
|
|
|
while true; do
|
|
status=$(mt -f "${DEVICE}" status 2>&1 || true)
|
|
if grep -qw 'DR_OPEN' <<< "${status}"; then
|
|
return
|
|
fi
|
|
if (($(date +%s) >= deadline)); then
|
|
echo "Tape device did not eject after unmount: ${DEVICE}; status: ${status}" >&2
|
|
exit 1
|
|
fi
|
|
sleep 2
|
|
done
|
|
}
|
|
|
|
main 2>&1 | tee -a "${TAPE_DIR}/ltfs.log"
|