diff --git a/action.sh b/action.sh index ba380b9..bfbf8e9 100644 --- a/action.sh +++ b/action.sh @@ -55,15 +55,15 @@ update_ssh() { 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" - - BETA + if "$MODDIR/container_ctrl.sh" stop; then + sed -i 's|^description=.*|description=stopped🙁 Android Subsystem for GNU/Linux Powered by ruri|' "$MODDIR/module.prop" + BETA + fi else printf "- Starting up container...\n\n" - "$MODDIR/container_ctrl.sh" start - - update_ssh + if "$MODDIR/container_ctrl.sh" start; then + update_ssh + fi fi countdown=3 diff --git a/config.conf b/config.conf index b1d7472..3d2321b 100644 --- a/config.conf +++ b/config.conf @@ -9,6 +9,11 @@ RURIMA_LXC_OS=ubuntu # OS version to install RURIMA_LXC_OS_VERSION=oracular +# OS dir to install +# The actual directory is the `CONTAINER_DIR` in `customize.sh` +# CONTAINER_DIR=/data/${RURIMA_LXC_OS} +CONTAINER_DIR=/data/ubuntu + PASSWORD=123456 PORT=22 @@ -22,8 +27,3 @@ MOUNT_READ_ONLY=true UNMASK_DIRS=false PRIVILEGED=false RUNTIME=false - - -# OS dir to install -# The actual directory is the `CONTAINER_DIR` in `customize.sh` -# CONTAINER_DIR=/data/${RURIMA_LXC_OS} diff --git a/container_ctrl.sh b/container_ctrl.sh index af5ddb8..d4efbe5 100644 --- a/container_ctrl.sh +++ b/container_ctrl.sh @@ -2,6 +2,10 @@ . "${0%/*}/config.conf" +if [ ! -e "$CONTAINER_DIR/etc/os-release" ]; then + exit 1 +fi + ruriumount() { fuser -k "$CONTAINER_DIR" >/dev/null 2>&1 ruri -U "$CONTAINER_DIR" >/dev/null 2>&1 diff --git a/customize.sh b/customize.sh index c4a0cc3..b5fb7f7 100644 --- a/customize.sh +++ b/customize.sh @@ -1,5 +1,6 @@ SKIPUNZIP=0 +ASL= REPLACE=" " bootinspect() { @@ -20,24 +21,21 @@ bootinspect() { link_busybox() { local busybox_file="" + local BUSYBOX_PATHS="/data/adb/magisk/busybox /data/adb/ksu/bin/busybox /data/adb/ap/bin/busybox" - if [ -f "$MODPATH/system/xbin/busybox" ]; then - busybox_file="$MODPATH/system/xbin/busybox" - else - for path in $BUSYBOX_PATHS; do - if [ -f "$path" ]; then - busybox_file="$path" - break - fi - done - fi + for path in $BUSYBOX_PATHS; do + if [ -f "$path" ]; then + busybox_file="$path" + break + fi + done if [ -n "$busybox_file" ]; then mkdir -p "$MODPATH/system/xbin" # "$busybox_file" --install -s "$MODPATH/system/xbin" # 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 - ln -s "$busybox_file" "$MODPATH/system/xbin/$cmd" + ln -sf "$busybox_file" "$MODPATH/system/xbin/$cmd" done if ! inotifyd --help >/dev/null 2>&1; then @@ -46,6 +44,9 @@ link_busybox() { else abort "- No available Busybox file found Please check your installation environment" fi + + set_perm_recursive "$MODPATH/system/xbin" 0 0 0755 0755 + export PATH="$MODPATH/system/xbin:$PATH" } inotifyfile() { @@ -61,20 +62,13 @@ inotifyfile() { } configuration() { - set_perm_recursive "$MODPATH/system/xbin" 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" + sed -i "s|^CONTAINER_DIR=.*|CONTAINER_DIR=$CONTAINER_DIR|" "$MODPATH/config.conf" - CASE=$(sed -n '/case "\$LXC_OS"/,/^[[:space:]]*esac/p' "$MODPATH/setup/setup.sh") - SUPPORT=$(echo "$CASE" | \ - sed -n 's/^[[:space:]]*\([a-zA-Z0-9|]*\))$/\1/p' | \ - tr '|' ' ' | \ - tr '\n' ' ') + SUPPORT=$(sed -nE 's/^OS_LIST="([^"]+)"/\1/p' "$MODPATH/setup/setup.sh") if ! echo "$SUPPORT" | grep -qw "$RURIMA_LXC_OS"; then abort "- $RURIMA_LXC_OS is not supported by the setup script" @@ -116,8 +110,7 @@ automatic() { 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/sh /tmp/setup.sh "$RURIMA_LXC_OS" "$PASSWORD" "$PORT" - - inotifyfile + ruri -U "$CONTAINER_DIR" ui_print "- Automated installation completed!" ui_print "- Note: Please change the default password. Exposing an SSH port with password authentication instead of key-based authentication is always a high-risk behavior!" @@ -125,10 +118,14 @@ automatic() { main() { bootinspect - configuration link_busybox - automatic - ruri -U "$CONTAINER_DIR" + + if [ -z "$ASL" ]; then + configuration + automatic + fi + + inotifyfile } main @@ -137,4 +134,5 @@ main set_perm "$MODPATH/container_ctrl.sh" 0 0 0755 ui_print "" -ui_print "- Please restart the system" +(sleep 5 && reboot) & +ui_print "The system will restart in 5 seconds..." diff --git a/inotify.sh b/inotify.sh index 7cc58e6..dda6858 100644 --- a/inotify.sh +++ b/inotify.sh @@ -1,5 +1,5 @@ #!/bin/sh -MODULEID="moduleid" +MODULEID="asl" MODULEDIR="/data/adb/modules/$MODULEID" if command -v magisk >/dev/null 2>&1; then diff --git a/setup/setup.sh b/setup/setup.sh index 24ef6ae..e3f45b1 100644 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -1,6 +1,7 @@ LXC_OS=$1 PASSWORD=$2 PORT=$3 +OS_LIST="alpine archlinux centos debian fedora kali ubuntu" configure_dns_host() { if [ -L /etc/resolv.conf ]; then @@ -268,36 +269,32 @@ configure_ssh() { } main() { - configure_dns_host + local valid=0 - create_groups + for os in $OS_LIST; do + if [ "$LXC_OS" = "$os" ]; then + valid=1 + break + fi + done - add_user_to_groups + if [ "$valid" -eq 0 ]; then + echo "Unsupported LXC operating system '$LXC_OS'" + return 1 + fi + configure_dns_host + create_groups + add_user_to_groups echo "root:${PASSWORD:-123456}" | chpasswd case "$LXC_OS" in - archlinux) - setup_archlinux - ;; - alpine) - setup_alpine - ;; - centos) - setup_centos - ;; - debian|ubuntu) - setup_debian - ;; - fedora) - setup_fedora - ;; - kali) - setup_kali - ;; - *) - echo "Unsupported LXC OS: $LXC_OS" - ;; + archlinux) setup_archlinux ;; + alpine) setup_alpine ;; + centos) setup_centos ;; + debian|ubuntu) setup_debian ;; + fedora) setup_fedora ;; + kali) setup_kali ;; esac configure_ssh