adbfs-rootless icon indicating copy to clipboard operation
adbfs-rootless copied to clipboard

[Feature request] allow to specify Android device to mount.

Open dreirund opened this issue 1 year ago • 9 comments

As what the the old/ orphaned "zach-klippenstein/adbfs" provided, I hereby feature-request an option to specify which android device to mount, e.g.

./adbfs -o android_device 02b5c5a809117c73 /mnt/android

This is useful e.g. if

  • there is more than one device connected,
  • in scripted backup situations where the mount should only succeed if the specific device is connected and not any other (which is my current use case).

Regards!

dreirund avatar Jan 22 '24 13:01 dreirund

While I'd love to see this feature built-in, I just found a workaround: set an environment variable ANDROID_SERIAL="02b5c5a809117c73" (taking the example you gave) before starting adbfs, e.g.

ANDROID_SERIAL="02b5c5a809117c73" ./adbfs /mnt/android

baeuchle avatar Jan 28 '24 13:01 baeuchle

Tip - I have written this snippet just for that:

#!/bin/bash

# Get the serial number of the first device
ANDROID_SERIAL=$(adb devices | awk 'NR==2 {print $1}')

# Check if a device was found
if [ -z "$ANDROID_SERIAL" ]; then
    echo "No device found."
    exit 1
fi

# Set the ANDROID_SERIAL environment variable
export ANDROID_SERIAL

# Unmount the existing mountpoint
sudo fusermount -u /media/android_via_adb_adbfs_mountpoint

# Mount the Android device file system
sudo -E /usr/bin/adbfs /media/android_via_adb_adbfs_mountpoint  -o allow_other

# Open the mounted directory in Nautilus, nemo etc.
nemo /media/android_via_adb_adbfs_mountpoint

Manamama avatar Mar 18 '24 00:03 Manamama

Tip - I have written this snippet just for that:

You seem to have messed up the markdown formatting, @Manamama.

Try to change the

`

to

```bash

(the trailing bash is optional, and only at the opening triple backticks, not at the end.)

Regards!

dreirund avatar Mar 26 '24 11:03 dreirund

I just found a workaround: set an environment variable ANDROID_SERIAL="02b5c5a809117c73"

OK, I made a wrapper script:
adbfs-devspecific.sh


Note: I previously had a bogous script, see this follow-up comment by @Manamama. For reference, I keep the bogous script here:
adbfs-devspecific.sh_-_BOGOUS.

dreirund avatar Mar 26 '24 11:03 dreirund

@dreirund -

  1. I have fixed my backticks (had been writing the above on mobile - clunky UI then).
  2. FYI, yours is even more cryptic than mine ;) :
adbfs-devspecific.sh --help
Usage:
  * /home/zezen/Downloads/adbfs-devspecific.sh --help
  * /home/zezen/Downloads/adbfs-devspecific.sh -D [Android Device ID] <adbfs-options>

Where '[Android Device ID]' is a serial number as shown by 'adb devices'.

Runs 'adbfs' only for the specified android device.

but:

adbfs-devspecific.sh -D ZHE{xyz} ->

Error: Second argument needs to be an Android device ID.

Ms Bing gracefully comments upon perusal thereof:

The error is in the regular expression used to validate the Android device ID. The script checks if the second argument matches the regular expression [0-9a-fA-F]*, which is a sequence of hexadecimal digits.

However, Android device IDs are not limited to hexadecimal characters. They can contain any alphanumeric characters (both uppercase and lowercase) as well as special character...

->


case "$2" in
  [0-9a-zA-Z]*)
    shift
    shift
  ;;
  *)
    errmsg "$0: Error: Second argument needs to be an Android device ID."
    errmsg ""
    errmsg "Run '$0 --help' for usage info."
    errmsg ""
    errmsg "Aborting."
    exit 3
  ;;
esac


But then, again, if e.g.:

adb devices List of devices attached ZHE6{xyz} device 192.168.221.156:5555 device 192.168.44.1:5555 device

->

 + '[' 2 -eq 0 ']'
+ '[' -Dx == --helpx ']'
+ '[' -Dx '!=' -Dx ']'
+ case "$2" in
+ shift
+ shift
+ adbfs -s
--*-- exec_command: adb shell "ls"
error: more than one device/emulator
fuse: missing mountpoint parameter
--*-- exec_command: rm -rf /tmp/adbfs-3uErXY/
 

and here I (and Ms Bing) give up.

Manamama avatar Mar 27 '24 12:03 Manamama

However, Android device IDs are not limited to hexadecimal characters.

Thanks for informing me, I updated my script (now to accept any non-empty string).

Also, I actually did forget the most important stuff, to actually set ANDROID_SERIAL after all the parsing and testing.

Updated script in my original comment.

dreirund avatar Mar 27 '24 12:03 dreirund

Confirmed to work @dreirund , also on my finicky (rooted, with e.g. nano in the /bin, Magisked, triply connected, also via BT, etc) Droid. My suggestion, as per the above - add it to the base options. Bows

Manamama avatar Mar 27 '24 13:03 Manamama

My suggestion, as per the above - add it to the base options.

I do not understand what you mean by this.

dreirund avatar Mar 27 '24 13:03 dreirund

Re

My suggestion, as per the above - add it to the base options.

I should have looked up the names.

Self-fix :

My suggestion, for @spion, as per the above comment by @dreirund : do (@spion) add the wrapper's functionality, to the base switches, e.g. -o android_device (as per @dreirund's original idea, once again).

Manamama avatar Mar 27 '24 14:03 Manamama