forked from appknox/droid-VNC-server
-
Notifications
You must be signed in to change notification settings - Fork 6
/
daemon.sh
executable file
·61 lines (49 loc) · 1.29 KB
/
daemon.sh
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
#!/usr/bin/env bash
# $ vnc-daemon -s 10 -m [fb|gb|adb] [start|stop|restart]
DAEMON_PATH=/data/local/tmp/
usage="usage: $0 [-s N] [-m S] [start|stop|restart]"
scale="100"
method="flinger"
action="restart"
kill_server() {
VNC_PID=$(adb shell ps | awk '/[a]ndroidvncserver/{print $2}')
if [ -n "$VNC_PID" ]; then
adb shell "su -c 'kill $VNC_PID'"
fi
}
start_server() {
PASS_CMD="'./${DAEMON_PATH}/androidvncserver -s ${scale} -m ${method} -e ${DAEMON_PATH}/passwd'"
NOPASS_CMD="'./${DAEMON_PATH}/androidvncserver -s ${scale} -m ${method}'"
adb shell "su -c 'if [ -e ${DAEMON_PATH}/passwd ]; then ${PASS_CMD}; else ${NOPASS_CMD}; fi'"
}
restart_server() {
kill_server
start_server
}
show_version() {
adb shell "su -c './${DAEMON_PATH}/androidvncserver -v'"
}
while getopts ":s:m:v" opt; do
case $opt in
s ) scale=$OPTARG ;;
m ) method=$OPTARG ;;
v ) show_version
exit 1 ;;
\? ) echo $usage
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
if [ -z "$@" ]; then
echo $usage
exit 1
else
action=$@
fi
case $action in
start ) start_server ;;
stop ) kill_server ;;
restart ) restart_server ;;
* ) echo "$0: unknown action. Use [stop|start|restart]"
exit 1 ;;
esac