Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dreirund opened this issue Jan 22, 2024 · 9 comments
Open

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

dreirund opened this issue Jan 22, 2024 · 9 comments

Comments

@dreirund
Copy link

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!

@baeuchle
Copy link

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

@Manamama
Copy link

Manamama commented Mar 18, 2024

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

@dreirund
Copy link
Author

dreirund commented Mar 26, 2024

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
Copy link
Author

dreirund commented Mar 26, 2024

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.

@Manamama
Copy link

Manamama commented Mar 27, 2024

@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.

@dreirund
Copy link
Author

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.

@Manamama
Copy link

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

@dreirund
Copy link
Author

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

I do not understand what you mean by this.

@Manamama
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants