This repository was archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmalior-droid
executable file
·162 lines (150 loc) · 5.42 KB
/
malior-droid
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/env bash
# set -ex
MH_BEFORE=${MALIOR_HOME:-$HOME}
source ${MALIOR_HOME:-$HOME}/.config/malior/envs.sh
[ ! -z "$MALIOR_HOME" ] && [ "$MH_BEFORE" != "$MALIOR_HOME" ] \
&& echo "Found new MALIOR_HOME $MH_BEFORE -> $MALIOR_HOME" \
&& echo "It is recommended to put MALIOR_HOME in .bashrc instead of envs.sh" \
&& source $MALIOR_HOME/.config/malior/envs.sh
MALIOR_HOME=${MALIOR_HOME:-$HOME}
MALIOR_PREFIX=${MALIOR_PREFIX:-https://github.com/ChisBread}
MALIOR_DROID_IMAGE=${MALIOR_IMAGE:-registry.cn-hangzhou.aliyuncs.com/whsyf/dobox:rk3588-202303010}
MALIOR_RUNNING=1
if [ "`sudo docker ps|grep redroid-rk3588-$USER`" == "" ]; then
MALIOR_RUNNING=0
fi
DOCKER_OPTS='-i'
if [ -t 0 ] && [ -t 1 ]; then
DOCKER_OPTS=$DOCKER_OPTS" -t"
fi
function help() {
cat <<EOF
Usage:
$(basename $0) [command] <game|application> <args>
note. kernel config PSI ASHMEM ANDROID_BINDERFS etc... is required
warning. zygisk is not supported, will mess up the container when enabled
e.g.
'malior-droid whoami' is same as 'adb shell whoami' (root user)
'adb connect localhost:5555' for adb
'scrcpy -s localhost:5555' view redroid screen
Command:
help This usage guide
update Update malior redroid image
recreate Recreate malior redroid container
destroy Stop and remove malior redroid container
pause|stop Pause(docker stop) malior redroid container
resume|start Resume(docker start) malior redroid container
restart Restart malior redroid container
resize Resize redroid window e.g. malior-droid resize 1920x1080
install-overlay Overlays, it will be mounted on the rootfs of redroid and stored in ~/.local/malior/redroid_overlay
base: Automatically installed overlay, providing magisk support and gapps support
EOF
}
function resize() {
sudo docker exec $DOCKER_OPTS redroid-rk3588-$USER /system/bin/sh -c "
wm size $1
"
}
function safetydownloadto() {
sudo wget $1 -O $2
[ "$?" != "0" ] && echo "failed to download $1"
}
function install_overlay() {
[ ! -d $MALIOR_HOME/.local/malior/redroid_overlay/ ] && mkdir -p $MALIOR_HOME/.local/malior/redroid_overlay
safetydownloadto $MALIOR_PREFIX/malior/releases/download/redroid-overlays-latest/$1_overlay.zip \
$MALIOR_HOME/.local/malior/redroid_overlay/$1_overlay.zip
sudo bash -c "cd $MALIOR_HOME/.local/malior/redroid_overlay/ && unzip -o $1_overlay.zip && rm -f $1_overlay.zip"
}
function runtime_start() {
if [ ! -d $MALIOR_HOME/.local/malior/redroid_overlay/ ]; then
mkdir -p $MALIOR_HOME/.local/malior/redroid_overlay
echo "install base overlay"
install_overlay base
sudo chmod -R +x $MALIOR_HOME/.local/malior/redroid_overlay/vendor/bin/*
fi
if [ "`sudo docker container ls -a|grep redroid-rk3588-$USER`" == "" ]; then
OVERLAY_BIND=$(sudo find $MALIOR_HOME/.local/malior/redroid_overlay -type f | sed -e 's@\(.*local.*redroid_overlay\)\(.*\)@-v \1\2:\2@g')
[ "$NO_OVERLAY" != "" ] && OVERLAY_BIND=""
sudo docker run -itd --privileged --name redroid-rk3588-$USER \
-v $MALIOR_HOME/.local/malior/redroid:/data \
$OVERLAY_BIND \
-p ${MALIOR_DROID_PORT:-5555}:5555 \
-v /dev/net/tun:/dev/tun -v /dev/mali0:/dev/mali0 \
${MALIOR_DROID_IMAGE}
echo "Some features (ro.secure=0 etc...) will take effect on the next start"
else
sudo docker start redroid-rk3588-$USER
fi
#init
# Wait for some initialization
LOOP_CNT=0
echo "checking android status..."
while :
do
LOOP_CNT=$(( $LOOP_CNT + 1 ))
if [ $LOOP_CNT -eq 100 ]; then
sudo docker rm -f redroid-rk3588-$USER
exit 1
fi
sleep 4
echo "check android status $LOOP_CNT times"
sudo docker exec $DOCKER_OPTS redroid-rk3588-$USER \
/system/bin/sh -c '[ -e /dev/binderfs/binder ] || exit 1'
[ "$?" != "0" ] && echo ' /dev/binderfs/binder not available' && continue
sudo docker exec $DOCKER_OPTS redroid-rk3588-$USER \
/system/bin/sh -c '[ "$(ps |grep com.android.systemui)" != "" ] || exit 1'
[ "$?" != "0" ] && echo ' com.android.systemui not available' && continue
break
done
}
COMMAND=$1
case $COMMAND in
help)
help
exit
;;
update)
if [ $MALIOR_RUNNING -eq 1 ]; then
sudo docker rm -f redroid-rk3588-$USER
fi
sudo docker pull ${MALIOR_DROID_IMAGE}
MALIOR_RUNNING=0
shift
;;
recreate)
if [ $MALIOR_RUNNING -eq 1 ]; then
sudo docker rm -f redroid-rk3588-$USER
fi
MALIOR_RUNNING=0
shift
;;
destroy)
sudo docker rm -f redroid-rk3588-$USER
exit
;;
pause|stop)
sudo docker stop redroid-rk3588-$USER
exit
;;
resume|start)
runtime_start
exit
;;
restart)
sudo docker stop redroid-rk3588-$USER
runtime_start
exit
;;
resize)
resize $2
exit
;;
install-overlay)
install_overlay $2
exit
;;
esac
if [ $MALIOR_RUNNING -eq 0 ]; then
runtime_start
fi
sudo docker exec $DOCKER_OPTS redroid-rk3588-$USER /system/bin/sh -c "$*"