Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #6

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions action.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#!/bin/sh
MODDIR=${0%/*}
if grep -q "status=running" "$MODDIR/module.prop"; then
STATUS="running"
PORT=$(sed -n 's/^PORT="\([^"]*\)"/\1/p' "$MODDIR/config.conf")
PID=$($MODDIR/bin/fuser "$PORT/tcp" 2>/dev/null)

if [ -n "$PID" ]; then
printf "- Stopping container...\n\n"
"$MODDIR"/container_ctrl.sh stop
sed -i 's|^description=.*|description=\[ stopped🙁 \] Android Subsystem for GNU/Linux Powered by ruri|' "$MODDIR/module.prop"
else
STATUS="stopped"
fi
if [ "$STATUS" = "stopped" ]; then
"$MODDIR"/start.sh
sed -i 's|\[.*\]|[status=running😉]|' "$MODDIR/module.prop"
else
"$MODDIR"/stop.sh
sed -i 's|\[.*\]|[status=stopped😇]|' "$MODDIR/module.prop"
printf "- Starting up container...\n\n"
"$MODDIR"/container_ctrl.sh start
sed -i 's|^description=.*|description=\[ running😉 \] Android Subsystem for GNU/Linux Powered by ruri|' "$MODDIR/module.prop"
fi

countdown=5
while [ $countdown -gt 0 ]; do
printf "\r- %d" "$countdown"
sleep 1
countdown=$((countdown - 1))
done
2 changes: 1 addition & 1 deletion config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ esac
# ruri config

REQUIRE_SUDO="true"
MOUNT_POINT="/sdcard"
MOUNT_POINT="/data/media/0"
MOUNT_ENTRANCE="/sdcard"
MOUNT_READ_ONLY="true"
UNMASK_DIRS="false"
Expand Down
60 changes: 60 additions & 0 deletions container_ctrl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

init_setup() {
MODDIR=${0%/*}
export PATH="$MODDIR/bin:$PATH"
. "$MODDIR"/config.conf
}

ruriumount() {
init_setup
fuser -k "$CONTAINER_DIR" >/dev/null 2>&1
ruri -U "$CONTAINER_DIR" >/dev/null 2>&1
umount -lvf "$CONTAINER_DIR" 2>/dev/null
umount -lf "$CONTAINER_DIR"/sdcard 2>/dev/null
umount -lf "$CONTAINER_DIR"/sys 2>/dev/null
umount -lf "$CONTAINER_DIR"/proc 2>/dev/null
umount -lf "$CONTAINER_DIR"/dev 2>/dev/null
echo "- Container stopped"
sleep 2
}

ruristart() {
ruriumount

if [ "$REQUIRE_SUDO" = "true" ]; then
mount --bind $CONTAINER_DIR $CONTAINER_DIR
mount -o remount,suid $CONTAINER_DIR
fi

ARGS="-w"

if [ -n "$MOUNT_POINT" ] && [ -n "$MOUNT_ENTRANCE" ]; then
if [ "$MOUNT_READ_ONLY" = "true" ]; then
ARGS="$ARGS -M $MOUNT_POINT $MOUNT_ENTRANCE"
else
ARGS="$ARGS -m $MOUNT_POINT $MOUNT_ENTRANCE"
fi
fi
# [ ! -d "$CONTAINER_DIR/$MOUNT_ENTRANCE" ] && mkdir -p "$CONTAINER_DIR/$MOUNT_ENTRANCE"

[ "$UNMASK_DIRS" = "true" ] && ARGS="$ARGS -A"
[ "$PRIVILEGED" = "true" ] && ARGS="$ARGS -p"
[ "$RUNTIME" = "true" ] && ARGS="$ARGS -S"

ruri $ARGS $CONTAINER_DIR /bin/$SHELL -c "$START_SERVICES" &
echo "- Container started"
}

case "$1" in
start)
ruristart
;;
stop)
ruriumount
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
9 changes: 5 additions & 4 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ link_busybox() {
mkdir -p "$MODPATH"/bin
# "$busybox_file" --install -s "$MODPATH/bin"
# 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
for cmd in fuser; do
for cmd in fuser inotifyd; do
ln -s "$busybox_file" "$MODPATH"/bin/"$cmd"
done
else
Expand Down Expand Up @@ -88,7 +88,9 @@ automatic() {
ui_print "- Starting the chroot environment to perform automated installation..."
ui_print "- Please ensure the network environment is stable. The process may take some time, so please be patient!"
ui_print ""
sleep 3
sleep 2
echo "127.0.0.1 localhost" > "$CONTAINER_DIR"/etc/hosts
echo "::1 localhost ip6-localhost ip6-loopback" >> "$CONTAINER_DIR"/etc/hosts
echo "$HOSTNAME" >"$CONTAINER_DIR"/etc/hostname
mkdir -p "$CONTAINER_DIR"/tmp "$CONTAINER_DIR"/usr/local/lib/servicectl/enabled >/dev/null 2>&1
cp "$MODPATH/setup/${RURIMA_LXC_OS}.sh" "$CONTAINER_DIR"/tmp/setup.sh
Expand Down Expand Up @@ -116,8 +118,7 @@ main() {
main

# set_perm_recursive $MODPATH 0 0 0755 0644
set_perm "$MODPATH"/start.sh 0 0 0755
set_perm "$MODPATH"/stop.sh 0 0 0755
set_perm "$MODPATH"/container_ctrl.sh 0 0 0755

ui_print ""
ui_print "- Please restart the system"
36 changes: 15 additions & 21 deletions inotify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,39 @@ MODULEID="moduleid"
MODULEDIR="/data/adb/modules/$MODULEID"
DESCRIPTION="Android Subsystem for GNU/Linux Powered by ruri"

if command -v magisk 2>&1 >/dev/null; then
if command -v magisk >/dev/null 2>&1; then
if magisk -v | grep -q lite; then
MODULEDIR="/data/adb/lite_modules/$MODULEID"
fi
fi

export PATH="$MODULEDIR/bin:$PATH"

while [ $(getprop sys.boot_completed) != 1 ]; do
sleep 2
done

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

(
inotifyd - "$MODULEDIR" 2>/dev/null |
while read events dir file; do
# echo "$events $dir $file" >> debug.log
if [ "$file" = "disable" ]; then
NOW=$(TZ='Asia/Shanghai' date +"%m-%d %H:%M:%S %Z")
case "$events" in
inotifyd - "$MODULEDIR" 2>/dev/null | while read -r events _ file; do
if [ "$file" = "disable" ]; then
case "$events" in
d)
"$MODULEDIR"/start.sh
sed -i 's|^description=.*|description=\[status=running😉\] Android Subsystem for GNU/Linux Powered by ruri|' "$MODDIR/module.prop"
"$MODULEDIR/container_ctrl.sh" start
sed -i "6c description=[ on ] $DESCRIPTION" "$MODULEDIR/module.prop"
;;
n)
"$MODULEDIR"/stop.sh
sed -i 's|^description=.*|description=\[status=stopped😇\] Android Subsystem for GNU/Linux Powered by ruri|' "$MODDIR/module.prop"
"$MODULEDIR/container_ctrl.sh" stop
sed -i "6c description=[ off ] $DESCRIPTION" "$MODULEDIR/module.prop"
;;
*)
:
;;
esac
fi
done
esac
fi
done
) &

pid=$!
echo "$pid" > "$MODULEDIR"/.pidfile

(
sleep 15
rm -f "$MODULEDIR"/.pidfile
) &
sed -i "6c description=[ PID=$pid ] This container can be quickly controlled by enabling/disabling" "$MODULEDIR/module.prop"
20 changes: 0 additions & 20 deletions service.sh

This file was deleted.

27 changes: 0 additions & 27 deletions start.sh

This file was deleted.

17 changes: 0 additions & 17 deletions stop.sh

This file was deleted.

5 changes: 2 additions & 3 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/sh
MODDIR=${0%/*}
"$MODDIR"/stop.sh
sleep 3
"$MODDIR"/container_ctrl.sh stop
. "$MODDIR"/config.conf

rm -f /data/adb/service.d/inotify.sh
umount -lf "$CONTAINER_DIR"/dev
umount -lf "$CONTAINER_DIR"/proc
Expand Down
Loading