Skip to content

Commit 7218d33

Browse files
authored
Merge pull request #6 from lin1328/main
Update
2 parents fa88408 + 447be99 commit 7218d33

File tree

9 files changed

+100
-104
lines changed

9 files changed

+100
-104
lines changed

action.sh

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
#!/bin/sh
21
MODDIR=${0%/*}
3-
if grep -q "status=running" "$MODDIR/module.prop"; then
4-
STATUS="running"
2+
PORT=$(sed -n 's/^PORT="\([^"]*\)"/\1/p' "$MODDIR/config.conf")
3+
PID=$($MODDIR/bin/fuser "$PORT/tcp" 2>/dev/null)
4+
5+
if [ -n "$PID" ]; then
6+
printf "- Stopping container...\n\n"
7+
"$MODDIR"/container_ctrl.sh stop
8+
sed -i 's|^description=.*|description=\[ stopped🙁 \] Android Subsystem for GNU/Linux Powered by ruri|' "$MODDIR/module.prop"
59
else
6-
STATUS="stopped"
7-
fi
8-
if [ "$STATUS" = "stopped" ]; then
9-
"$MODDIR"/start.sh
10-
sed -i 's|\[.*\]|[status=running😉]|' "$MODDIR/module.prop"
11-
else
12-
"$MODDIR"/stop.sh
13-
sed -i 's|\[.*\]|[status=stopped😇]|' "$MODDIR/module.prop"
10+
printf "- Starting up container...\n\n"
11+
"$MODDIR"/container_ctrl.sh start
12+
sed -i 's|^description=.*|description=\[ running😉 \] Android Subsystem for GNU/Linux Powered by ruri|' "$MODDIR/module.prop"
1413
fi
14+
15+
countdown=5
16+
while [ $countdown -gt 0 ]; do
17+
printf "\r- %d" "$countdown"
18+
sleep 1
19+
countdown=$((countdown - 1))
20+
done

config.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ esac
5555
# ruri config
5656

5757
REQUIRE_SUDO="true"
58-
MOUNT_POINT="/sdcard"
58+
MOUNT_POINT="/data/media/0"
5959
MOUNT_ENTRANCE="/sdcard"
6060
MOUNT_READ_ONLY="true"
6161
UNMASK_DIRS="false"

container_ctrl.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
3+
init_setup() {
4+
MODDIR=${0%/*}
5+
export PATH="$MODDIR/bin:$PATH"
6+
. "$MODDIR"/config.conf
7+
}
8+
9+
ruriumount() {
10+
init_setup
11+
fuser -k "$CONTAINER_DIR" >/dev/null 2>&1
12+
ruri -U "$CONTAINER_DIR" >/dev/null 2>&1
13+
umount -lvf "$CONTAINER_DIR" 2>/dev/null
14+
umount -lf "$CONTAINER_DIR"/sdcard 2>/dev/null
15+
umount -lf "$CONTAINER_DIR"/sys 2>/dev/null
16+
umount -lf "$CONTAINER_DIR"/proc 2>/dev/null
17+
umount -lf "$CONTAINER_DIR"/dev 2>/dev/null
18+
echo "- Container stopped"
19+
sleep 2
20+
}
21+
22+
ruristart() {
23+
ruriumount
24+
25+
if [ "$REQUIRE_SUDO" = "true" ]; then
26+
mount --bind $CONTAINER_DIR $CONTAINER_DIR
27+
mount -o remount,suid $CONTAINER_DIR
28+
fi
29+
30+
ARGS="-w"
31+
32+
if [ -n "$MOUNT_POINT" ] && [ -n "$MOUNT_ENTRANCE" ]; then
33+
if [ "$MOUNT_READ_ONLY" = "true" ]; then
34+
ARGS="$ARGS -M $MOUNT_POINT $MOUNT_ENTRANCE"
35+
else
36+
ARGS="$ARGS -m $MOUNT_POINT $MOUNT_ENTRANCE"
37+
fi
38+
fi
39+
# [ ! -d "$CONTAINER_DIR/$MOUNT_ENTRANCE" ] && mkdir -p "$CONTAINER_DIR/$MOUNT_ENTRANCE"
40+
41+
[ "$UNMASK_DIRS" = "true" ] && ARGS="$ARGS -A"
42+
[ "$PRIVILEGED" = "true" ] && ARGS="$ARGS -p"
43+
[ "$RUNTIME" = "true" ] && ARGS="$ARGS -S"
44+
45+
ruri $ARGS $CONTAINER_DIR /bin/$SHELL -c "$START_SERVICES" &
46+
echo "- Container started"
47+
}
48+
49+
case "$1" in
50+
start)
51+
ruristart
52+
;;
53+
stop)
54+
ruriumount
55+
;;
56+
*)
57+
echo "Usage: $0 {start|stop}"
58+
exit 1
59+
;;
60+
esac

customize.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ link_busybox() {
3636
mkdir -p "$MODPATH"/bin
3737
# "$busybox_file" --install -s "$MODPATH/bin"
3838
# This method creates links pointing to all commands of busybox, so it is not recommended. The following is an alternative approach for creating symbolic links pointing to the busybox file for specific commands
39-
for cmd in fuser; do
39+
for cmd in fuser inotifyd; do
4040
ln -s "$busybox_file" "$MODPATH"/bin/"$cmd"
4141
done
4242
else
@@ -88,7 +88,9 @@ automatic() {
8888
ui_print "- Starting the chroot environment to perform automated installation..."
8989
ui_print "- Please ensure the network environment is stable. The process may take some time, so please be patient!"
9090
ui_print ""
91-
sleep 3
91+
sleep 2
92+
echo "127.0.0.1 localhost" > "$CONTAINER_DIR"/etc/hosts
93+
echo "::1 localhost ip6-localhost ip6-loopback" >> "$CONTAINER_DIR"/etc/hosts
9294
echo "$HOSTNAME" >"$CONTAINER_DIR"/etc/hostname
9395
mkdir -p "$CONTAINER_DIR"/tmp "$CONTAINER_DIR"/usr/local/lib/servicectl/enabled >/dev/null 2>&1
9496
cp "$MODPATH/setup/${RURIMA_LXC_OS}.sh" "$CONTAINER_DIR"/tmp/setup.sh
@@ -116,8 +118,7 @@ main() {
116118
main
117119

118120
# set_perm_recursive $MODPATH 0 0 0755 0644
119-
set_perm "$MODPATH"/start.sh 0 0 0755
120-
set_perm "$MODPATH"/stop.sh 0 0 0755
121+
set_perm "$MODPATH"/container_ctrl.sh 0 0 0755
121122

122123
ui_print ""
123124
ui_print "- Please restart the system"

inotify.sh

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,39 @@ MODULEID="moduleid"
33
MODULEDIR="/data/adb/modules/$MODULEID"
44
DESCRIPTION="Android Subsystem for GNU/Linux Powered by ruri"
55

6-
if command -v magisk 2>&1 >/dev/null; then
6+
if command -v magisk >/dev/null 2>&1; then
77
if magisk -v | grep -q lite; then
88
MODULEDIR="/data/adb/lite_modules/$MODULEID"
99
fi
1010
fi
1111

12+
export PATH="$MODULEDIR/bin:$PATH"
13+
1214
while [ $(getprop sys.boot_completed) != 1 ]; do
1315
sleep 2
1416
done
1517

16-
# [ ! -f "$MODULEDIR"/disable ] && "$MODULEDIR"/start.sh
18+
[ ! -f "$MODULEDIR"/disable ] && "$MODULEDIR/container_ctrl.sh" start
1719

1820
(
19-
inotifyd - "$MODULEDIR" 2>/dev/null |
20-
while read events dir file; do
21-
# echo "$events $dir $file" >> debug.log
22-
if [ "$file" = "disable" ]; then
23-
NOW=$(TZ='Asia/Shanghai' date +"%m-%d %H:%M:%S %Z")
24-
case "$events" in
21+
inotifyd - "$MODULEDIR" 2>/dev/null | while read -r events _ file; do
22+
if [ "$file" = "disable" ]; then
23+
case "$events" in
2524
d)
26-
"$MODULEDIR"/start.sh
27-
sed -i 's|^description=.*|description=\[status=running😉\] Android Subsystem for GNU/Linux Powered by ruri|' "$MODDIR/module.prop"
25+
"$MODULEDIR/container_ctrl.sh" start
26+
sed -i "6c description=[ on ] $DESCRIPTION" "$MODULEDIR/module.prop"
2827
;;
2928
n)
30-
"$MODULEDIR"/stop.sh
31-
sed -i 's|^description=.*|description=\[status=stopped😇\] Android Subsystem for GNU/Linux Powered by ruri|' "$MODDIR/module.prop"
29+
"$MODULEDIR/container_ctrl.sh" stop
30+
sed -i "6c description=[ off ] $DESCRIPTION" "$MODULEDIR/module.prop"
3231
;;
3332
*)
3433
:
3534
;;
36-
esac
37-
fi
38-
done
35+
esac
36+
fi
37+
done
3938
) &
40-
4139
pid=$!
42-
echo "$pid" > "$MODULEDIR"/.pidfile
4340

44-
(
45-
sleep 15
46-
rm -f "$MODULEDIR"/.pidfile
47-
) &
41+
sed -i "6c description=[ PID=$pid ] This container can be quickly controlled by enabling/disabling" "$MODULEDIR/module.prop"

service.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

start.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

stop.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

uninstall.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#!/bin/sh
21
MODDIR=${0%/*}
3-
"$MODDIR"/stop.sh
4-
sleep 3
2+
"$MODDIR"/container_ctrl.sh stop
53
. "$MODDIR"/config.conf
4+
65
rm -f /data/adb/service.d/inotify.sh
76
umount -lf "$CONTAINER_DIR"/dev
87
umount -lf "$CONTAINER_DIR"/proc

0 commit comments

Comments
 (0)