Last active
May 23, 2021 15:53
-
-
Save koonix/4e07195a524b5bdc13223da49a115fb1 to your computer and use it in GitHub Desktop.
[Bash Script] Mount android phones via ADB on linux.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# access the storage of android devices | |
# through adb via adbfs. | |
# requires adbfs-rootless. | |
# config | |
mnt=~/Mount/ADB | |
main () { | |
while true; do | |
nocursor | |
clear | |
echo "m: mount u: unmount" | |
echo "l: list o: open q: quit" | |
echo | |
case "$char" in | |
m) m ;; | |
u) u ;; | |
l) l ;; | |
o) o ;; | |
q) exit ;; | |
esac | |
read -s -n 1 char | |
done | |
} | |
m () { | |
l -q || return | |
is_mounted && echo "already mounted." && return | |
cleanup | |
adbfs -o auto_unmount "$mnt" | |
is_mounted && echo "mounted." | |
cleanup | |
} | |
u () { | |
fusermount -u "$mnt" && echo unmounted. | |
} | |
l () { | |
l="$(adb devices)" | |
[ "$(echo "$l" | wc -l)" = 1 ] && | |
echo "no adb devices found." >&2 && | |
return 1 | |
[ "$1" != -q ] && echo "$l" | |
} | |
o () { | |
m | |
is_mounted && $TERMFILE "$mnt" | |
} | |
cleanup () { | |
is_mounted || u >/dev/null 2>&1 | |
} | |
is_mounted () { | |
[ $(ls -A "$mnt" 2>/dev/null | wc -l) -gt 0 ] | |
} | |
nocursor () { | |
tput civis | |
trap 'tput cnorm' EXIT | |
} | |
main "$@" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment