mount-file.bash: be quieter when debugging is off

This commit is contained in:
ckie 2022-11-17 08:09:12 +02:00
parent def994adbd
commit 32a5793139
No known key found for this signature in database
GPG key ID: 13E79449C0525215

View file

@ -19,14 +19,19 @@ mountPoint="$1"
targetFile="$2" targetFile="$2"
debug="$3" debug="$3"
trace() {
if (( "$debug" )); then
echo "$@"
fi
}
if (( "$debug" )); then if (( "$debug" )); then
set -o xtrace set -o xtrace
fi fi
if [[ -L "$mountPoint" && $(readlink -f "$mountPoint") == "$targetFile" ]]; then if [[ -L "$mountPoint" && $(readlink -f "$mountPoint") == "$targetFile" ]]; then
echo "$mountPoint already links to $targetFile, ignoring" trace "$mountPoint already links to $targetFile, ignoring"
elif mount | grep -F "$mountPoint"' ' >/dev/null && ! mount | grep -F "$mountPoint"/ >/dev/null; then elif mount | grep -F "$mountPoint"' ' >/dev/null && ! mount | grep -F "$mountPoint"/ >/dev/null; then
echo "mount already exists at $mountPoint, ignoring" trace "mount already exists at $mountPoint, ignoring"
elif [[ -e "$mountPoint" ]]; then elif [[ -e "$mountPoint" ]]; then
echo "A file already exists at $mountPoint!" >&2 echo "A file already exists at $mountPoint!" >&2
exit 1 exit 1