From e31d091d6be58d9fbcd20d55e88326cda6232bb4 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Sat, 31 Dec 2022 14:24:39 +0100 Subject: [PATCH] bin: add `noautomount` -> prevent automount on macOS This script creates fstab(5) entries to prevent volumes to be automatically mounted on macOS. --- home/.local/bin/noautomount | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 home/.local/bin/noautomount diff --git a/home/.local/bin/noautomount b/home/.local/bin/noautomount new file mode 100755 index 0000000..6b63ab1 --- /dev/null +++ b/home/.local/bin/noautomount @@ -0,0 +1,35 @@ +#!/bin/sh +usage() { + echo "Usage: + + $(basename $0) [-h] -- generate /etc/fstab entry to prevent automount on macOS + + where: + -h print this help + volume the volume that should not be automounted +" +} + +error() { + usage + echo "$(tput setaf 1)ERROR: $1$(tput sgr0)" + exit 1 +}>&2 + +gen_fstab_entry() { + volume="$1" + info="$(diskutil info "$volume")" + uuid=$(echo "$info" | grep 'Volume UUID' | sed -e 's/^ *Volume UUID: *//') + fs=$(echo "$info" | grep 'Type (Bundle)' | sed -e 's/^ *Type (Bundle): *//') + echo "# $volume" + echo "UUID=$uuid none $fs rw,noauto" + echo +} + +case "$1" in + -h|--help) usage ;; + -*) error "invalid option: $1" ;; + "") error "volume required" ;; + *) gen_fstab_entry "$1";; +esac +