From f5b24fbd72f68a6546299ca5c89626007c9afba7 Mon Sep 17 00:00:00 2001 From: dece Date: Sat, 28 May 2022 16:16:31 +0200 Subject: [PATCH] mount-jmtpfs: add script --- mount-jmtpfs.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 mount-jmtpfs.sh diff --git a/mount-jmtpfs.sh b/mount-jmtpfs.sh new file mode 100755 index 0000000..39521a4 --- /dev/null +++ b/mount-jmtpfs.sh @@ -0,0 +1,25 @@ +#!/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 + +if [[ "$1" = "-u" ]]; then + 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 + exit +fi + +mount_dir="$(mktemp -d -p /tmp jmtpfs.XXXXXXXXXX)" +jmtpfs "$mount_dir" +echo "Mount directory: $mount_dir"