2022-05-28 16:16:31 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# Mount the first phone to be found in a temporary directory with a name
|
|
|
|
# prefixed with "jmtpfs", in the /tmp directory. If -u is passed, unmount all
|
|
|
|
# directories with this same name pattern and remove them (after confirmation).
|
|
|
|
|
|
|
|
if ! command -v jmtpfs > /dev/null; then
|
|
|
|
echo "jmtpfs is not installed."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2022-07-05 12:27:27 +02:00
|
|
|
unmount_phones() {
|
2022-05-28 16:16:31 +02:00
|
|
|
for mount_dir in /tmp/jmtpfs.*; do
|
|
|
|
if [ -d "$mount_dir" ]; then
|
|
|
|
umount "$mount_dir"
|
|
|
|
echo "$mount_dir unmounted. It should now be empty:"
|
|
|
|
ls -la "$mount_dir"
|
|
|
|
rm -rI "$mount_dir"
|
|
|
|
fi
|
|
|
|
done
|
2022-07-05 12:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SHOW_MOUNT=
|
|
|
|
while getopts "hus" OPTION; do
|
|
|
|
case $OPTION in
|
|
|
|
h) usage; exit 0 ;;
|
|
|
|
u) unmount_phones; exit 0 ;;
|
|
|
|
s) SHOW_MOUNT=true ;;
|
|
|
|
*) usage; exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
2022-05-28 16:16:31 +02:00
|
|
|
|
|
|
|
mount_dir="$(mktemp -d -p /tmp jmtpfs.XXXXXXXXXX)"
|
|
|
|
jmtpfs "$mount_dir"
|
|
|
|
echo "Mount directory: $mount_dir"
|
2022-07-05 12:27:27 +02:00
|
|
|
[[ "$SHOW_MOUNT" = true ]] && nohup open "$mount_dir" > /dev/null 2>&1
|