diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6cea548..40c3087 100755 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,8 +68,8 @@ jobs: local os=$1 local version=$2 - sed -i "s/RURIMA_LXC_OS=\".*\"/RURIMA_LXC_OS=\"${os}\"/g" config.conf - sed -i "s/RURIMA_LXC_OS_VERSION=\".*\"/RURIMA_LXC_OS_VERSION=\"${version}\"/g" config.conf + sed -i "s/^RURIMA_LXC_OS=.*/RURIMA_LXC_OS=${os}/g" config.conf + sed -i "s/^RURIMA_LXC_OS_VERSION=.*/RURIMA_LXC_OS_VERSION=${version}/g" config.conf zip -r "../asl-${os}-${version}.zip" . -x "*.git/*" -x ".github/*" diff --git a/action.sh b/action.sh index a37d9c3..28273b3 100755 --- a/action.sh +++ b/action.sh @@ -1,6 +1,6 @@ MODDIR=${0%/*} -PORT=$(sed -n 's/^PORT="\([^"]*\)"/\1/p' "$MODDIR/config.conf") -PID=$($MODDIR/bin/fuser "$PORT/tcp" 2>/dev/null) +PORT=$(sed -n 's/^PORT=\(.*\)/\1/p' "$MODDIR/config.conf") +PID=$("$MODDIR/bin/fuser" "$PORT/tcp" 2>/dev/null) BETA() { local PREFIX=/data/user/0/com.termux/files/usr @@ -9,13 +9,13 @@ BETA() { local TMPDIR=$PREFIX/tmp local BATE=$TMPDIR/asl.sh - if [ ! -d $PREFIX ]; then + if [ ! -d "$PREFIX" ]; then echo "- TThe environment of Termux is abnormal" return fi - cp -f $MODDIR/bate.sh $BATE - chmod 755 $BATE + cp -f "$MODDIR/bate.sh" "$BATE" + chmod 755 "$BATE" echo "- It will run in Termux soon. Please make sure the network is working properly" echo "- Check whether Termux is running in the background" @@ -55,13 +55,13 @@ update_ssh() { if [ -n "$PID" ]; then printf "- Stopping container...\n\n" - "$MODDIR"/container_ctrl.sh stop + "$MODDIR/container_ctrl.sh" stop sed -i 's|^description=.*|description=\[ stopped🙁 \] Android Subsystem for GNU/Linux Powered by ruri|' "$MODDIR/module.prop" BETA else printf "- Starting up container...\n\n" - "$MODDIR"/container_ctrl.sh start + "$MODDIR/container_ctrl.sh" start update_ssh fi diff --git a/bate.sh b/bate.sh index 2067e5c..3b3ae41 100755 --- a/bate.sh +++ b/bate.sh @@ -973,6 +973,7 @@ config_new_system() { if [ $? -eq 0 ]; then echo "系统 $new_os 基础配置完成" + echoRgb "请牢记你的密码: $sys_password 和端口: $sys_port" 3 return 0 else echo "系统 $new_os 基础配置失败" @@ -1012,7 +1013,8 @@ switch_lxc_os() { return 1 fi - sed -i "s/RURIMA_LXC_OS=\"[^\"]*\"/RURIMA_LXC_OS=\"$new_os\"/" "$CONFIG_FILE" + sed -i "s/^RURIMA_LXC_OS=.*/RURIMA_LXC_OS=$new_os/" "$CONFIG_FILE" + sed -i "s|^CONTAINER_DIR=.*|CONTAINER_DIR=$BASE_DIR/$new_os|" "$CONFIG_FILE" if [ $? -eq 0 ]; then echo "成功将系统切换为 $new_os" diff --git a/config.conf b/config.conf index 2a0f47d..24d2d9c 100644 --- a/config.conf +++ b/config.conf @@ -1,66 +1,32 @@ -#!/bin/sh # 本机连接ssh root@127.0.0.1 -p 22密码123456 # 请根据你自己的网络环境选择是本机(127.0.0.1)、局域网(192.*.*.*)或公网(ipv4地址)来连接 SSH # Mirror -RURIMA_LXC_MIRROR="images.linuxcontainers.org" -# OS to install. +RURIMA_LXC_MIRROR=images.linuxcontainers.org + +# OS to install # Make sure there is setup/${RURIMA_LXC_OS}.sh -RURIMA_LXC_OS="ubuntu" -# OS version to install. -RURIMA_LXC_OS_VERSION="oracular" +RURIMA_LXC_OS=ubuntu -# Add additional commands other than the system's built-in commands -BUSYBOX_PATHS=" -/data/adb/magisk/busybox -/data/adb/ksu/bin/busybox -/data/adb/ap/bin/busybox -" -HOSTNAME="$(getprop ro.product.model)" -PASSWORD="123456" -PORT="22" -CONTAINER_DIR="/data/${RURIMA_LXC_OS}" +# OS version to install +RURIMA_LXC_OS_VERSION=oracular -# In a chroot environment, the default interpreters and service startup commands may not be universal across different systems -case "$RURIMA_LXC_OS" in - archlinux|centos|debian|ubuntu) - SHELL="bash" - ;; - alpine) - SHELL="sh" - ;; - *) - SHELL="sh" - ;; -esac +PASSWORD=123456 +PORT=22 -# The servicectl command is an open-source project. If you find it inconvenient to use, you can opt for other startup commands It is not mandatory -# e.g. /usr/sbin/sshd -case "$RURIMA_LXC_OS" in - archlinux|centos) - START_SERVICES="servicectl start sshd" - ;; - debian|ubuntu) - START_SERVICES="service ssh start" - ;; - alpine) - START_SERVICES="rc-service sshd restart" - ;; - *) - START_SERVICES="" - ;; -esac +# OS dir to install +# CONTAINER_DIR="/data/${RURIMA_LXC_OS}" # ruri config -REQUIRE_SUDO="true" -MOUNT_POINT="/data/media/0" -MOUNT_ENTRANCE="/sdcard" -MOUNT_READ_ONLY="true" -UNMASK_DIRS="false" -PRIVILEGED="false" -RUNTIME="false" - +REQUIRE_SUDO=true +MOUNT_POINT=/data/media/0 +MOUNT_ENTRANCE=/sdcard +MOUNT_READ_ONLY=true +UNMASK_DIRS=false +PRIVILEGED=false +RUNTIME=false +# diff --git a/container_ctrl.sh b/container_ctrl.sh index ebcff0f..a3b1806 100644 --- a/container_ctrl.sh +++ b/container_ctrl.sh @@ -22,6 +22,23 @@ ruriumount() { ruristart() { ruriumount + # The servicectl command is an open-source project. If you find it inconvenient to use, you can opt for other startup commands It is not mandatory + # e.g. /usr/sbin/sshd + case "$RURIMA_LXC_OS" in + archlinux|centos) + START_SERVICES="servicectl start sshd" + ;; + debian|ubuntu) + START_SERVICES="service ssh start" + ;; + alpine) + START_SERVICES="rc-service sshd restart" + ;; + *) + START_SERVICES="" + ;; + esac + if [ "$REQUIRE_SUDO" = "true" ]; then mount --bind $CONTAINER_DIR $CONTAINER_DIR mount -o remount,suid $CONTAINER_DIR @@ -42,7 +59,7 @@ ruristart() { [ "$PRIVILEGED" = "true" ] && ARGS="$ARGS -p" [ "$RUNTIME" = "true" ] && ARGS="$ARGS -S" - ruri $ARGS $CONTAINER_DIR /bin/$SHELL -c "$START_SERVICES" & + ruri $ARGS "$CONTAINER_DIR" /bin/sh -c "$START_SERVICES" & echo "- Container started" } diff --git a/customize.sh b/customize.sh index ca262c6..5c16dd4 100644 --- a/customize.sh +++ b/customize.sh @@ -21,8 +21,8 @@ bootinspect() { link_busybox() { local busybox_file="" - if [ -f "$MODPATH"/bin/busybox ]; then - busybox_file="$MODPATH"/bin/busybox + if [ -f "$MODPATH/bin/busybox" ]; then + busybox_file="$MODPATH/bin/busybox" else for path in $BUSYBOX_PATHS; do if [ -f "$path" ]; then @@ -33,11 +33,11 @@ link_busybox() { fi if [ -n "$busybox_file" ]; then - mkdir -p "$MODPATH"/bin + 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 inotifyd; do - ln -s "$busybox_file" "$MODPATH"/bin/"$cmd" + ln -s "$busybox_file" "$MODPATH/bin/$cmd" done else abort "- No available Busybox file found Please check your installation environment" @@ -45,20 +45,28 @@ link_busybox() { } inotifyfile() { - id_value=$(sed -n 's/^id=\(.*\)$/\1/p' "$MODPATH"/module.prop) + id_value=$(sed -n 's/^id=\(.*\)$/\1/p' "$MODPATH/module.prop") MONITORFILE=".${id_value}.service.sh" - sed -i "2c MODULEID=\"$id_value\"" "$MODPATH"/inotify.sh + sed -i "2c MODULEID=\"$id_value\"" "$MODPATH/inotify.sh" mkdir -p /data/adb/service.d - mv -f "$MODPATH"/inotify.sh /data/adb/service.d/"$MONITORFILE" - chmod +x /data/adb/service.d/"$MONITORFILE" + mv -f "$MODPATH/inotify.sh" "/data/adb/service.d/$MONITORFILE" + chmod +x "/data/adb/service.d/$MONITORFILE" - sed -i "s/inotify.sh/$MONITORFILE/g" "$MODPATH"/uninstall.sh + sed -i "s/inotify.sh/$MONITORFILE/g" "$MODPATH/uninstall.sh" } configuration() { - set_perm_recursive "$MODPATH"/bin 0 0 0755 0755 - . "$MODPATH"/config.conf + set_perm_recursive "$MODPATH/bin" 0 0 0755 0755 + . "$MODPATH/config.conf" + + BUSYBOX_PATHS="/data/adb/magisk/busybox +/data/adb/ksu/bin/busybox +/data/adb/ap/bin/busybox" + + BASE_DIR="/data" + CONTAINER_DIR="${BASE_DIR}/${RURIMA_LXC_OS}" + echo "CONTAINER_DIR=${BASE_DIR}/${RURIMA_LXC_OS}" >> "$MODPATH/config.conf" export PATH="$MODPATH/bin:$PATH" @@ -97,13 +105,13 @@ automatic() { ui_print "- Please ensure the network environment is stable. The process may take some time, so please be patient!" ui_print "" sleep 2 - 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/setup.sh "$CONTAINER_DIR"/tmp/setup.sh - cp -r "$MODPATH"/setup/servicectl/* "$CONTAINER_DIR"/usr/local/lib/servicectl/ - chmod 777 "$CONTAINER_DIR"/tmp/setup.sh "$CONTAINER_DIR"/usr/local/lib/servicectl/servicectl "$CONTAINER_DIR"/usr/local/lib/servicectl/serviced + getprop ro.product.model >"$CONTAINER_DIR/etc/hostname" + mkdir -p "$CONTAINER_DIR/tmp" "$CONTAINER_DIR/usr/local/lib/servicectl/enabled" + cp "$MODPATH/setup/setup.sh" "$CONTAINER_DIR/tmp/setup.sh" + cp -r "$MODPATH/setup/servicectl"/* "$CONTAINER_DIR/usr/local/lib/servicectl/" + chmod 777 "$CONTAINER_DIR/tmp/setup.sh" "$CONTAINER_DIR/usr/local/lib/servicectl/servicectl" "$CONTAINER_DIR/usr/local/lib/servicectl/serviced" - ruri "$CONTAINER_DIR" /bin/"$SHELL" /tmp/setup.sh "$RURIMA_LXC_OS" "$PASSWORD" "$PORT" + ruri "$CONTAINER_DIR" /bin/sh /tmp/setup.sh "$RURIMA_LXC_OS" "$PASSWORD" "$PORT" inotifyfile #rm "$CONTAINER_DIR"/tmp/setup.sh @@ -122,7 +130,7 @@ main() { main # set_perm_recursive $MODPATH 0 0 0755 0644 -set_perm "$MODPATH"/container_ctrl.sh 0 0 0755 +set_perm "$MODPATH/container_ctrl.sh" 0 0 0755 ui_print "" ui_print "- Please restart the system" diff --git a/inotify.sh b/inotify.sh index 9740c6b..82d4042 100755 --- a/inotify.sh +++ b/inotify.sh @@ -14,7 +14,7 @@ while [ $(getprop sys.boot_completed) != 1 ]; do sleep 2 done -[ ! -f "$MODULEDIR"/disable ] && "$MODULEDIR/container_ctrl.sh" start +[ ! -f "$MODULEDIR/disable" ] && "$MODULEDIR/container_ctrl.sh" start ( inotifyd - "$MODULEDIR" 2>/dev/null | while read -r events _ file; do diff --git a/uninstall.sh b/uninstall.sh index 81b430c..e820e1b 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,6 +1,6 @@ MODDIR=${0%/*} "$MODDIR"/container_ctrl.sh stop -CONTAINER_DIR="/data/$(sed -n 's/^RURIMA_LXC_OS="\([^"]*\)"/\1/p' "$MODDIR/config.conf")" +CONTAINER_DIR=$(grep '^CONTAINER_DIR=' "$MODDIR/config.conf" | cut -d '=' -f 2) rm -f /data/adb/service.d/inotify.sh umount -lf "$CONTAINER_DIR"/dev