1
0

mounting script

This commit is contained in:
dtb 2021-07-24 09:31:44 -04:00
parent feeef87e1c
commit 689a6fb791
2 changed files with 35 additions and 0 deletions

34
dotfiles-old/bin/mnt Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh
set -e
DEV="/dev"
MNT="/mnt"
# preliminary checks
[ -n "$2" ] || [ -z "$1" ] \
&& printf "Usage: %b [device in %b/]" "$0" "$DEV" >>/dev/stderr \
&& exit 1 \
|| true
! [ "$(id -u)" = 0 ] \
&& printf "%b: This script must be run as root.\n" "$0" >>/dev/stderr \
&& exit 1 \
|| true
# exhaustive checks to ensure $DEV/$1 exists and that $MNT/$1 can be safely used as a mountpoint
! [ -d "$MNT/$1" ] && [ -a "$MNT/$1" ] \
&& printf "%b: '%b/%b' already exists, but isn't a directory.\n" "$0" "$MNT" "$1" >>/dev/stderr \
&& exit 1 \
|| true
[ -d "$MNT/$1" ] \
|| mkdir "$MNT/$1"
! [ "$(ls -A "$MNT/$1" | wc -c)" = 0 ] \
&& printf "%b: '%b/%b' is a directory, but isn't empty.\n" "$0" "$MNT" "$1" >>/dev/stderr \
&& exit 1 \
|| true
! [ -e "/dev/$1" ] \
&& printf "%b: '%b/%b' doesn't exist.\n" "$0" "$DEV" "$1" >>/dev/stderr \
&& exit 1 \
|| true
# ok, we're safe
mount "$DEV/$1" "$MNT/$1"

View File

@ -18,5 +18,6 @@
.config/i3status/config .config/i3status/config
bin/data bin/data
bin/displaym bin/displaym
bin/mnt
bin/volume bin/volume
src/dmenu/config.h src/dmenu/config.h