Changes between Version 8 and Version 9 of SshfsMnt


Ignore:
Timestamp:
Oct 14, 2015, 12:22:30 PM (3 years ago)
Author:
chris
Comment:

Sorted out exit codes

Legend:

Unmodified
Added
Removed
Modified
  • SshfsMnt

    v8 v9  
    1616if [[ ! -d "$MOUNT_POINT" ]]; then
    1717  echo "It looks like $MOUNT_POINT doesn't exist?"
    18   exit
     18  exit 1
    1919fi
    2020
     
    3838  echo "   Hostname example.org"
    3939  echo
    40   exit
     40  exit 1
    4141fi
    4242
     
    4444if [[ ! -d "$MOUNT_POINT/$SERVER" ]]; then
    4545  echo "Creating $MOUNT_POINT/$SERVER"
    46   mkdir "$MOUNT_POINT/$SERVER"
     46  mkdir "$MOUNT_POINT/$SERVER" || { echo "Failed to create $MOUNT_POINT/$SERVER" ; exit 1 ; }
    4747fi
    4848
    49 # check if the file system appears to already be mounted
     49# check is the file system appears to already be mounted
    5050DF=$(df | awk -F' ' '{ print $6 }' | grep "$MOUNT_POINT/$SERVER")
    5151if [[ $DF ]]; then
    5252  echo "It appears that $SERVER is already mounted at $DF?"
    53   exit
     53  exit 1
    5454fi
    5555
    5656# Mount the file system
    57 sshfs $SERVER:/ $MOUNT_POINT/$SERVER/
     57sshfs $SERVER:/ $MOUNT_POINT/$SERVER/ && \
     58  # if this succeeded
     59  { echo "Mounted $SERVER:/ on $MOUNT_POINT/$SERVER/" ; exit 0 ; } || \
     60  # if this failed
     61  { echo "Problem mounting $SERVER:/ $MOUNT_POINT/$SERVER/" ; exit 1 ; }
    5862}}}
    5963
     
    6973if [[ ! -d "$MOUNT_POINT" ]]; then
    7074  echo "It looks like $MOUNT_POINT doesn't exist?"
    71   exit
     75  exit 1
    7276fi
    7377
     
    8084  SERVER=$server
    8185fi
     86 
     87# check if the mount point exists
     88if [[ ! -d "$MOUNT_POINT/$SERVER" ]]; then
     89  echo "It looks like "$MOUNT_POINT/$SERVER" doesn't exist?"
     90  exit 1
     91fi
    8292
    8393# check if the file system appears to already be mounted
    84 DF=$(df | awk -F' ' '{ print $6 }' | grep "$MOUNT_POINT/$SERVER")
     94DF=$(df | awk -F' ' '{ print $6 }' | grep -w "$MOUNT_POINT/$SERVER")
    8595if [[ $DF ]]; then
    86   echo "Umounting $SERVER at $DF?"
    87   fusermount -u $MOUNT_POINT/$SERVER
    88   exit
     96  # unmount the filesystem
     97  fusermount -u $MOUNT_POINT/$SERVER && \
     98    # if success
     99    { echo "Umounted $SERVER at $DF" ; exit 0 ; } || \
     100    # if mounting failed
     101    { echo "Problem unmounting $MOUNT_POINT/$SERVER" ; exit 1 ; }
    89102else
    90   echo "It appears that $SERVER is not mounted"
     103  echo "It appears that $SERVER is not mounted at $MOUNT_POINT/$SERVER"
     104  exit 1
    91105fi
    92106}}}