From fcf73d03a10f19f48ce39815a64c9e5fe2b25425 Mon Sep 17 00:00:00 2001 From: Andrew Klapp Date: Thu, 4 Oct 2018 20:58:32 -0500 Subject: [PATCH] Added some error messages to vm-mount. --- vm-mount | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/vm-mount b/vm-mount index 1057b30..aae2efe 100755 --- a/vm-mount +++ b/vm-mount @@ -8,17 +8,23 @@ REMOTE_DIRECTORY="/home/lumia/src/" if [ "$1" = "-u" ]; then vm_name="$2" mountpoint="${MOUNTPOINT_PARENT}/${vm_name}.vm" - # TODO: Print some messages here. + if [ -z "${vm_name}" ]; then + echo "Virtual machine name not provided." + exit 1 + fi if mount | grep -q "on ${mountpoint} "; then + echo "Unmounting ${mountpoint}." fusermount -u "${mountpoint}" fi if virsh list | grep -q " ${vm_name} "; then + echo "Stopping ${vm_name}" virsh destroy "${vm_name}" fi if [ -d "${mountpoint}" ]; then + echo "Deleting directory ${mountpoint}." rmdir "${mountpoint}" fi @@ -26,6 +32,11 @@ else vm_name="$1" mountpoint="${MOUNTPOINT_PARENT}/${vm_name}.vm" + if [ -z "${vm_name}" ]; then + echo "Virtual machine name not provided." + exit 1 + fi + if [ "$(virsh list | grep " ${vm_name} ")" = "" ]; then virsh start "${vm_name}" fi @@ -45,10 +56,10 @@ else # TODO: Make sure this directory isn't made if the vm fails to start or connect. mkdir -p "${mountpoint}" - # TODO: This needs a better "error" message and a proper timeout. + # TODO: This needs a proper timeout. echo "Attempting to mount over ssh." until sshfs "${vm_ip_address}:${REMOTE_DIRECTORY}" "${mountpoint}"; do + echo "Could not connect via SSH, retrying." sleep 3 - echo "An error occurred, retrying." done fi