shell-scripts/mountain/mountain

36 lines
624 B
Bash
Executable file

#!/usr/bin/bash
TEXT=$(/usr/lib/mountain/mountain-handle $1)
CODE=$?
if [[ $CODE -eq 1 ]]; then
echo "mountain: no device supplied"
exit 1
elif [[ $CODE -eq 2 ]]; then
echo "mountain: no settings for \"$1\""
exit 2
fi
read -t 1 -ra PROP <<< $TEXT
DEV=${PROP[0]}
DIR=${PROP[1]}
mount | grep "$DEV" >> /dev/null
EXISTS=$?
if [[ "$2" == "u" ]]; then
if [[ $EXISTS -ne 0 ]]; then
echo "mountain: $DEV is not mounted"
exit 2
fi
echo "Unmounting $DIR"
sudo umount $DIR
exit 0
fi
if [[ $EXISTS -ne 1 ]]; then
echo "mountain: $DEV is already mounted"
exit 2
fi
echo "Mounting $DEV at $DIR"
sudo mount $DEV $DIR