mount_phone (662B)
1 #!/usr/bin/env bash 2 # set -x 3 if ! command -v simple-mtpfs &>/dev/null; then 4 echo "simple-mtpfs not installed." >&2 5 exit 1 6 fi 7 8 mountdir="/Users/alex/phone" 9 clean_up() { 10 echo "Exiting..." 11 if kill -0 "$mtpfs_pid" &> /dev/null; then 12 kill "$mtpfs_pid" 13 wait "$mtpfs_pid" 14 fi 15 [ ! -d "$mountpoint" ] || rmdir "$mountpoint"; 16 [ ! -L "$mountdir" ] || unlink "$mountdir"; 17 } 18 trap clean_up INT TERM EXIT 19 20 try_to_mount() { 21 echo "Mounting phone..." 22 simple-mtpfs -f "$mountpoint" & 23 mtpfs_pid=$! 24 } 25 26 mountpoint=$(mktemp -d) 27 try_to_mount 28 ln -s "$mountpoint" "$mountdir" 29 echo "Mounted at $mountdir (=> $mountpoint)." 30 echo "Send interrupt to unmount." 31 wait