Last active
April 14, 2026 06:52
-
-
Save aznoisib/10edbbe1dd7fd66d55958d01d536f22f to your computer and use it in GitHub Desktop.
Setup command rootfs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/system/bin/sh | |
| echo "[*] Setting up proot command..." | |
| BASE_DIR="$(pwd)" | |
| USR_DIR="$BASE_DIR/usr" | |
| BIN_DIR="$USR_DIR/bin" | |
| LIB_DIR="$USR_DIR/lib" | |
| mkdir -p "$BIN_DIR" "$LIB_DIR" | |
| # ===== Download binary ===== | |
| echo "[*] Downloading proot..." | |
| curl -L https://raw.githubusercontent.com/codeplugs/proot-rootfs-android/refs/heads/main/proot/aarch64/proot -o "$BIN_DIR/proot.bin" | |
| chmod 755 "$BIN_DIR/proot.bin" | |
| # ===== Download library ===== | |
| echo "[*] Downloading libtalloc..." | |
| curl -L https://raw.githubusercontent.com/codeplugs/proot-rootfs-android/refs/heads/main/proot/aarch64/libtalloc.so.2 -o "$LIB_DIR/libtalloc.so.2" | |
| chmod 755 "$LIB_DIR/libtalloc.so.2" | |
| # ===== Download Alpine RootFS ===== | |
| echo "[*] Downloading Alpine rootfs..." | |
| ROOTFS_DIR="$BASE_DIR/rootfs" | |
| mkdir -p "$ROOTFS_DIR" | |
| curl -L https://cdimage.debian.org/mirror/alpinelinux.org/v3.21/releases/aarch64/alpine-minirootfs-3.21.5-aarch64.tar.gz -o alpine.tar.gz | |
| # ===== Extract RootFS ===== | |
| echo "[*] Extracting rootfs..." | |
| tar -xzf alpine.tar.gz -C "$ROOTFS_DIR" | |
| # ===== Cleanup ===== | |
| rm alpine.tar.gz | |
| echo "[✓] RootFS ready at $ROOTFS_DIR" | |
| # ===== Basic System config ===== | |
| echo "127.0.0.1 localhost localhost.localdomain" > "$ROOTFS_DIR/etc/hosts" | |
| echo "::1 localhost localhost.localdomain" >> "$ROOTFS_DIR/etc/hosts" | |
| echo "nameserver 8.8.8.8" > "$ROOTFS_DIR/etc/resolv.conf" | |
| echo "nameserver 1.1.1.1" >> "$ROOTFS_DIR/etc/resolv.conf" | |
| echo "[*] Checking resolv.conf:" | |
| cat "$ROOTFS_DIR/etc/resolv.conf" | |
| ls -l "$ROOTFS_DIR/etc/resolv.conf" | |
| echo "Welcome to Alpine!" > "$ROOTFS_DIR/etc/motd" | |
| echo "" >> "$ROOTFS_DIR/etc/motd" | |
| echo "The Alpine Wiki contains a large amount of how-to information about administrating Alpine systems." >> "$ROOTFS_DIR/etc/motd" | |
| echo "See <https://wiki.alpinelinux.org/>." >> "$ROOTFS_DIR/etc/motd" | |
| echo "" >> "$ROOTFS_DIR/etc/motd" | |
| echo "Installing : apk add <pkg>" >> "$ROOTFS_DIR/etc/motd" | |
| echo "Updating : apk update && apk upgrade" >> "$ROOTFS_DIR/etc/motd" | |
| # ===== Remove setup alpine ===== | |
| rm -f "$ROOTFS_DIR/sbin/setup-alpine" | |
| rm -rf "$ROOTFS_DIR/etc/alpine-release" 2>/dev/null | |
| # ===== Create wrapper command ===== | |
| echo "[*] Creating proot command..." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # === CONFIG === | |
| export ALPINE_ISO_URL="https://dl-cdn.alpinelinux.org/alpine/v3.17/releases/x86_64/alpine-virt-3.17.9-x86_64.iso" | |
| export IMG_FILE="alpine.img" | |
| export IMG_SIZE="3G" | |
| export ROOT_PASSWORD="ga#£&26GZv16352525" | |
| export PREFIX=/usr | |
| # === PREPARE === | |
| [ ! -f alpine.iso ] && curl -L -o alpine.iso "$ALPINE_ISO_URL" | |
| rm -f ./qemukey ./qemukey.pub | |
| ssh-keygen -b 2048 -t rsa -N "" -f ./qemukey | |
| rm -f "$IMG_FILE" | |
| qemu-img create -f raw "$IMG_FILE" "$IMG_SIZE" | |
| # === EXPECT SCRIPT: INSTALL === | |
| expect <<'EOT' | |
| set timeout -1 | |
| set qemukey [exec cat ./qemukey.pub] | |
| set answerfile [exec cat ./answerfile] | |
| spawn qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \ | |
| -drive if=pflash,format=raw,read-only=on,file=$env(PREFIX)/share/qemu/edk2-x86_64-code.fd \ | |
| -netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \ | |
| -cdrom alpine.iso \ | |
| -drive file=alpine.img,format=raw \ | |
| -nographic | |
| # LOGIN | |
| expect "login:" | |
| send "root\r" | |
| expect "localhost:~#" | |
| send "setup-interfaces\r" | |
| expect "\[eth0\]" | |
| send "\r" | |
| expect "\[dhcp\]" | |
| send "\r" | |
| expect "\[no\]" | |
| send "\r" | |
| expect "localhost:~#" | |
| send "ifup eth0\r" | |
| # FIX CONSOLE | |
| expect "#" | |
| send "sed -i -E 's/(local kernel_opts)=.*/\\1=\"console=ttyS0\"/' /sbin/setup-disk\r" | |
| # === WRITE ANSWERFILE (FIXED) === | |
| expect "#" | |
| send "cat > /root/answerfile <<'EOL'\r" | |
| send -- "$answerfile\r" | |
| send "EOL\r" | |
| # VERIFY | |
| expect "#" | |
| send "cat /root/answerfile\r" | |
| # RUN SETUP | |
| expect "#" | |
| send "echo nameserver 8.8.8.8 > /etc/resolv.conf\r" | |
| expect "#" | |
| send "apk update\r" | |
| expect "#" | |
| send "apk upgrade\r" | |
| expect "#" | |
| send "apk add dosfstools e2fsprogs syslinux\r" | |
| expect "#" | |
| send "setup-alpine -f /root/answerfile\r" | |
| expect "password:" | |
| send "$::env(ROOT_PASSWORD)\r" | |
| expect "password:" | |
| send "$::env(ROOT_PASSWORD)\r" | |
| expect "user?" | |
| send "no\r" | |
| expect "Erase the above disk" | |
| sleep 5 | |
| send "y\r" | |
| expect "Please reboot" | |
| send "halt\r" | |
| sleep 5 | |
| send "\x01" | |
| send "x" | |
| expect eof | |
| EOT | |
| # === EXPECT SCRIPT: REBOOT === | |
| expect <<'EOT' | |
| set timeout -1 | |
| set qemukey [exec cat ./qemukey.pub] | |
| spawn qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \ | |
| -drive if=pflash,format=raw,read-only=on,file=/data/data/com.termux/files/usr/share/qemu/edk2-x86_64-code.fd \ | |
| -drive file=alpine.img,format=raw,if=virtio \ | |
| -netdev user,id=n1,hostfwd=tcp::2222-:22,net=192.168.50.0/24 \ | |
| -device virtio-net,netdev=n1 \ | |
| -nographic | |
| expect "login:" | |
| send "root\r" | |
| expect "Password:" | |
| send "$env(ROOT_PASSWORD)\r" | |
| expect "#" | |
| send "apk update && apk add docker ip6tables\r" | |
| expect "#" | |
| send "service docker start\r" | |
| expect "#" | |
| send "rc-update add docker\r" | |
| expect "#" | |
| send "apk add zram-init\r" | |
| expect "#" | |
| send "sed -i -E 's/num_devices=2/num_devices=1/' /etc/conf.d/zram-init\r" | |
| expect "#" | |
| send "service zram-init start\r" | |
| expect "#" | |
| send "rc-update add zram-init\r" | |
| expect "#" | |
| send "mkdir -p /root/.ssh\r" | |
| expect "#" | |
| send "chmod 700 /root/.ssh\r" | |
| expect "#" | |
| send "echo \"$qemukey\" >> /root/.ssh/authorized_keys\r" | |
| expect "#" | |
| send "chmod 600 /root/.ssh/authorized_keys\r" | |
| expect "#" | |
| send "halt\r" | |
| sleep 5 | |
| send "\x01" | |
| send "x" | |
| expect eof | |
| EOT | |
| echo "[+] Alpine Linux installed successfully" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment