mountUnmountGoogleDrive_auto.sh 1.1 KB

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env bash
  2. gdrive_name="GoogleDrive_auto"
  3. gdrive_path="$HOME/GoogleDrive_auto/"
  4. gdrive_statusfile_path="$HOME/.myScripts/GoogleDriveStatus_auto.txt"
  5. is_mounted=$(mount | grep "$gdrive_name")
  6. if [[ "$is_mounted" ]]; then # if mounted
  7. notify-send -i dialog-information -t 3000 "$gdrive_name" "is already mounted. Try to unmount"
  8. fusermount -u "$gdrive_path" 2> "$gdrive_statusfile_path" 1> "$gdrive_statusfile_path" # try to unmount GoogleDrive
  9. result_unmount=$(cat "$gdrive_statusfile_path" | cut -d":" -f3)
  10. # if [[ "$?" == 0 ]]; then
  11. if [[ -z "$result_unmount" ]]; then
  12. notify-send -i dialog-information -t 3000 "$gdrive_name" "unmounted successfully"
  13. else
  14. notify-send -i dialog-information -t 3000 "$gdrive_name" "Can't unmount: $result_unmount"
  15. fi
  16. else # if not mounted
  17. google-drive-ocamlfuse -label auto "$gdrive_path" # try to mount GoogleDrive
  18. if [[ "$?" == 0 ]]; then
  19. notify-send -i dialog-information -t 3000 "$gdrive_name" "mounted successfully"
  20. else
  21. notify-send -i dialog-information -t 3000 "Error" "Failed to mount $gdrive_name"
  22. fi
  23. fi