-
Notifications
You must be signed in to change notification settings - Fork 0
/
rundroid
executable file
·63 lines (55 loc) · 1.61 KB
/
rundroid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
set -e -u
set -o pipefail
# write some cool doc here
function usage ()
{
cat << EOF
Usage: ${0##*/} [OPTION]...
Options: --help, -h: show this help dialog
EOF
}
function main ()
{
while getopts "h-:" opt; do
case ${opt} in
h) # help message
usage
exit 0
;;
-)
case "${OPTARG}" in
help)
usage
exit 0
;;
*)
printf 'Unknown option, exiting now\n' >&2
exit 1
;;
esac
;;
?)
printf 'Unknown option, exiting now\n' >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
[[ "${1:-}" == '--' ]] && shift
if [ "$(adb devices|wc -l)" == 2 ]; then
printf "Error: no devices available\n" >&2
exit 1
fi
scriptfile="${1}"; shift
if [ ! -x "${scriptfile}" ]; then
printf "Error: script not executable\n" >&2
exit 1
fi
script="$(basename "${scriptfile}")"
adb push "${scriptfile}" /sdcard/
adb shell "su -c 'mv \"/sdcard/${script}\" /cache/; sed -i \"s%^#!/usr/bin/env %#!/system/bin/env %\" \"/cache/${script}\"; chmod +x \"/cache/${script}\"; PATH=/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/usr/bin/applets:/sbin:\$PATH \"/cache/${script}\" $@; rm -f \"/cache/${script}\" \"/sdcard/${scriptfile}\"'"
}
if [ "${BASH_SOURCE[0]}" == "$0" ]; then
main "$@"
fi