Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions safe-eject.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@
# udisksctl → kernel unmount syscall directly
# → GVfs/Nautilus handles still live → EBUSY
#
# REQUIRES: zenity, udisks2, lsof, glib2-tools (gio)
# Install: sudo apt install zenity udisks2 lsof libglib2.0-bin
# REQUIRES: zenity, udisks2, lsof, glib2-tools (gio), flock
# Install: sudo apt install zenity udisks2 lsof libglib2.0-bin util-linux
#================================================================================

set -uo pipefail

# =============================================================================
# Preflight: Ensure the script is not already running
# =============================================================================
LOCKFILE="/tmp/safe-eject-linux.lock"
exec 9>"${LOCKFILE}"

if ! flock -n 9; then
exit 1
fi

# =============================================================================
# Preflight: verify required tools are present
# =============================================================================
Expand All @@ -30,7 +40,7 @@ for TOOL in zenity udisksctl lsof lsblk findmnt gio; do
done

if [[ ${#MISSING[@]} -gt 0 ]]; then
MSG="Required tools are not installed: ${MISSING[*]}\n\nInstall with:\n sudo apt install zenity udisks2 lsof libglib2.0-bin"
MSG="Required tools are not installed: ${MISSING[*]}\n\nInstall with:\n sudo apt install zenity udisks2 lsof libglib2.0-bin util-linux"
if command -v zenity &>/dev/null; then
zenity --error --title="Missing Dependencies" --text="$MSG" --width=400
else
Expand Down