diff --git a/.github/scripts/android/install-termux-x11.sh b/.github/scripts/android/install-termux-x11.sh index 961fc5f..3a1b564 100755 --- a/.github/scripts/android/install-termux-x11.sh +++ b/.github/scripts/android/install-termux-x11.sh @@ -14,8 +14,10 @@ if [ "$API_LEVEL" -lt 26 ]; then fi TERMUX_X11_VERSION="${TERMUX_X11_VERSION:-1.03.01}" -TERMUX_X11_SHA256="${TERMUX_X11_SHA256:-a0cdf8da2ecebe17c3441faecd7e06a433d23d8da49c37c8945feeb5ced3e8fe}" -APK_NAME="termux-x11-universal-debug.apk" +TERMUX_X11_SHA256="${TERMUX_X11_SHA256:-77c1791d6dccb4853a0b9e5e5fd85dc27872968fefe9122a8c6e45abd342f618}" +# Upstream dropped the universal debug APK in November 2026. The release +# build is the only universal APK left in the nightly tag. +APK_NAME="termux-x11-universal-release.apk" URL="https://github.com/termux/termux-x11/releases/download/nightly/$APK_NAME" CACHE="${RUNNER_TEMP:-/tmp}/termux-apks" mkdir -p "$CACHE" diff --git a/CHANGELOG.md b/CHANGELOG.md index 85a7790..540c3db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,26 @@ tag names, define the order. See the table at the bottom. ### Added +- Separate Android and external storage policies. Guided setup now offers + Both, Android only, External only, or None instead of one storage switch. + `lfa install` accepts `--android-storage on|off` and + `--external-storage on|off` (plus `--no-android-storage` and + `--no-external-storage`), and + `lfa storage android|external enable|disable|status` changes an existing + instance without reinstalling, and `--all` applies it to every instance + (`on`/`off` remain aliases). Disabling either + category starts the guest with proot-distro's `--isolated` mode and adds + back only the enabled binds, so the disabled tree is not reachable through + `/storage`. +- Custom Linux userlands. Guided setup gained option 9, and `lfa install` + gained `--iso PATH` and `--rootfs PATH`, so a rootfs tarball, an extracted + directory, or a live ISO can run under proot next to the eight built-in + distros. LFA checks the CPU architecture, extracts a live squashfs (or the + ext4 inside Fedora's `squashfs.img`), reads `/etc/os-release`, and maps the + image to a package-manager family so the normal desktop/software setup can + run. Unknown families install terminal-only instead of calling a package + manager that does not exist. The ISO is never booted, proot cannot emulate + another CPU, and installer-only images still need a rootfs tarball. - LFA notices now reach Android. `ui_ok`, `ui_warn`, and `ui_err` post a `termux-notification` through Termux:API as well as printing the terminal line, so install, update, backup, restore, repair, import, and error diff --git a/README.md b/README.md index b733c1f..f6678b1 100644 --- a/README.md +++ b/README.md @@ -88,9 +88,9 @@ Antigravity, and the CLI tools are in ## About the project -Linux for Android Manager runs a graphical Linux environment on an Android -phone without root. It is an interactive Bash script that wraps -`proot-distro` to install and manage Linux distributions on a phone or tablet. +Linux for Android Manager runs a Linux desktop on an Android phone or tablet +without root. It is an interactive Bash script that wraps `proot-distro` to +install and manage the distributions. Supported distributions: @@ -133,7 +133,7 @@ hardware, not simulated. Full details, root causes, and evidence are in | Alpine 3.18 (Android 5) | Yes | Yes | legacy VNC desktop, panel works; X11 and Both hidden | v1.7.1 | | Ubuntu GNOME 46 (experimental) | Yes | Yes | shell and apps run; session services missing | v1.7.0 | -> The test suite runs `881` checks with 0 failures. The same suite runs on the +> The test suite runs `965` checks with 0 failures. The same suite runs on the > devices (`tests/device-matrix.sh`). The table is as of v1.7.1. Ubuntu was > re-verified on v1.7.1, and Alpine 3.18 was re-verified on Android 5 on > 2026-11-04; the other rows were last verified on v1.7.0. A row is @@ -212,7 +212,7 @@ logind. Neither exists inside proot. This option skips `gnome-session` and launches `gnome-shell --x11` directly inside a D-Bus session. The shell itself runs. The session services that `gnome-session` normally -starts do not, which is where the breakage comes from. +starts do not. Two proot-specific patches make it start: @@ -303,7 +303,7 @@ as experimental only. replaced by snap stubs. - Google Antigravity IDE installs the official ARM64 build into `/opt/antigravity-ide` and launches it with the dbus and GPU flags it needs - inside proot. It is the real IDE, not a placeholder terminal edition. + inside proot. It is the full IDE. - The managed `/etc/lfa-chromium-flags` file lets the acceleration menu add or remove VirGL flags without overwriting the proot-safe Chromium wrapper. - The uninstaller shows the instance, distro and desktop, rootfs path, and @@ -461,7 +461,7 @@ is accepted. | Command | What it does | | --- | --- | -| `lfa install` (`i`, `in`) | install without menus; accepts `-d/--distro`, `-D/--desktop`, `-b/--backend`, `-a/--autostart`, `-u/--user`, `-H/--hostname`, `-t/--timezone`, `-s/--software`, and `-i` | +| `lfa install` (`i`, `in`) | install without menus; accepts `-d/--distro`, `--iso`, `--rootfs`, `--android-storage`, `--external-storage`, `-D/--desktop`, `-b/--backend`, `-a/--autostart`, `-u/--user`, `-H/--hostname`, `-t/--timezone`, `-s/--software`, and `-i` | | `lfa list` (`ls`, `l`) | list installed distributions (`-j/--json` for scripts) | | `lfa status` | show desktop, backend, autostart, and running state (`-j/--json`); also checks for a newer manager release | | `lfa start` (`desktop`) | start the desktop; `-x/--x11` or `-v/--vnc` forces a backend, `-r/--restart` replaces a running session | @@ -480,7 +480,7 @@ is accepted. | `lfa usb` | list, scan, attach, tty, flash, and exec real USB devices through Termux:API | | `lfa appimage` (`app`, `ai`) | extract an AppImage once and add a menu entry | | `lfa run` | run an AppImage once without installing it | -| `lfa storage` | Android storage status, repair, run, and protected data helpers | +| `lfa storage` | Android storage status, repair, run, protected data helpers, and separate Android/external access toggles | | `lfa diagnostics` (`diag`) | write a redacted support bundle | | `lfa notice` | `on`, `off`, or `status` for the `start-linux` change notice | | `lfa version` (`ver`) / `lfa help` | version and command list | @@ -494,6 +494,8 @@ Examples: ```bash lfa install --distro ubuntu --desktop xfce4 --backend both -i ubuntu +lfa install --rootfs ~/storage/downloads/debian-rootfs.tar.gz -i debian-custom +lfa install --iso ~/storage/downloads/alpine-live-arm64.iso -i alpine-live lfa start -i ubuntu --vnc lfa shell -i ubuntu --user lfa switch x11 -i ubuntu --remove-old @@ -538,7 +540,7 @@ Android side: it exposes real framework data through files in `$PREFIX/tmp` disabled without losing hardware data, and the risky parts are easier to audit. -Neither layer pretends to provide a kernel feature. Docker, Podman, Flatpak, +Neither layer provides a kernel feature. Docker, Podman, Flatpak, TUN/TAP, iptables, CUDA, ROCm, KVM, and kernel modules remain unavailable. The full list, with reasons, is in [docs/INCOMPATIBLE.md](docs/INCOMPATIBLE.md). @@ -583,8 +585,8 @@ are in [docs/USB.md](docs/USB.md). An AppImage normally mounts itself through FUSE. proot does not expose `/dev/fuse`, so a raw `./Foo.AppImage` fails with -`fuse: failed to open /dev/fuse: Permission denied`. LFA does not pretend -FUSE works; it runs the AppImage the way the runtime supports, by extracting: +`fuse: failed to open /dev/fuse: Permission denied`. LFA extracts the AppImage +instead: ```bash ./Foo.AppImage # works: the session exports APPIMAGE_EXTRACT_AND_RUN=1 @@ -635,6 +637,46 @@ guest group, write access, and the chmod result. The same helper is installed in the guest as `lfa-run-file`, and Thunar gets a **Run in Linux** entry in the right-click menu for files under shared storage. +### Storage access policies + +Android shared storage and external devices are separate policies. Both are +on by default. Guided setup asks once with four choices (Both, Android only, +External only, None), and the CLI accepts: + +```bash +lfa install --distro ubuntu --android-storage off -i ubuntu +lfa install --distro debian --external-storage off -i debian +lfa install --distro debian --no-android-storage --no-external-storage -i minimal +``` + +Change an existing install without reinstalling: + +```bash +lfa storage android disable -i ubuntu +lfa storage external disable -i ubuntu +lfa storage android enable -i ubuntu +lfa storage external status -i ubuntu +``` + +To change every installed instance at once, add `--all`: + +```bash +lfa storage android disable --all +lfa storage external enable --all +lfa storage android status --all +``` + +Without `--all` or `-i`, the command uses the only installed instance, or +stops and lists them when several exist. `on` and `off` are accepted as +aliases for `enable` and `disable`. + +Changes apply to new desktop and terminal sessions. When either category is +off, LFA starts the guest with proot-distro's `--isolated` mode and adds back +only the binds you kept: Android shared storage at `/sdcard` and +`/storage/emulated/0`, or external volumes at `/media/`. The +disabled category is not reachable through `/storage`. Disabling both also +hides the other Android and Termux host paths that `--isolated` skips. + ### Android/data and Android/obb Android 11 and later block `/storage/emulated/0/Android/data` and @@ -710,9 +752,56 @@ different instance name in guided setup. Each instance has its own rootfs. The chosen image is recorded as `IMAGE="..."` in `/etc/termux-linux-manager.conf` inside the guest. -Arbitrary rootfs tarballs are not supported by the installer. `proot-distro` -can install a custom rootfs through a plugin, but the manager will not offer it -in the menu, and its launchers assume one of the eight supported distros. +### Custom ISO and rootfs images + +The installer can also unpack a userland you provide. This is the same proot +container model as the supported distros: the image must match the phone's +CPU, and the ISO itself is never booted. + +| Source | What happens | +| --- | --- | +| Rootfs tarball (`.tar`, `.tar.gz`, `.tar.xz`, `.tar.bz2`, `.tar.zst`) | Extracted directly; a single top-level directory is flattened. | +| Extracted rootfs directory | Copied into the instance. | +| Live ISO or raw image (`.iso`, `.img`, `.zip`) | `7z` unpacks the image, LFA finds the live squashfs (or the ext4 inside Fedora's `squashfs.img`) and extracts that root filesystem. `7zip` is installed automatically when missing. | + +Choose **Custom Linux ISO / rootfs** in guided setup (option 9), or use the +CLI: + +```bash +lfa install --rootfs ~/storage/downloads/debian-rootfs.tar.gz -i debian-custom +lfa install --iso ~/storage/downloads/alpine-live-arm64.iso -i alpine-live +lfa install --iso ~/storage/downloads/debian-live-arm64.iso -i debian-live \ + --desktop xfce4 --backend vnc +``` + +`--iso` and `--rootfs` imply `--distro custom`; do not combine them with +another `--distro`. On the CLI, a custom install defaults to `--desktop none`, +because LFA only knows how to drive a desktop for the families it recognises. + +LFA reads `/etc/os-release` after extraction and maps the image to Debian, +Ubuntu, Kali, Fedora, openSUSE, Void, Arch, or Alpine. A recognised family +gets the normal desktop/software setup and the same launchers as a distro +installed from proot-distro. If the package manager is unknown, the instance +is installed terminal-only and LFA prints the command to open a root shell; +install a desktop inside the guest with its own package manager if you want +one. + +Things that will not work: + +- **A different CPU.** proot does not emulate, so an `x86_64` ISO cannot run + on an arm64 phone. Use an arm64 image (most desktop ISOs are amd64-only). +- **Installer-only ISOs.** Images without a live squashfs/root filesystem + (for example Ubuntu Server) have nothing for LFA to extract. Use the + distro's rootfs tarball or cloud image instead. +- **Booting, kernels, and block devices.** There is no kernel, initramfs, + systemd, loop mount, or block layer under proot. Live-ISO extraction gives + you the filesystem only. +- **OCI/Docker archives.** These need `proot-distro` v5's own installer. + Export a plain rootfs instead: `docker export NAME -o rootfs.tar`. + +The chosen source and detected identity are recorded as `CUSTOM_SOURCE`, +`CUSTOM_NAME`, and `CUSTOM_ID` in +`/etc/termux-linux-manager.conf` inside the guest. ### Testing an older version @@ -976,9 +1065,8 @@ shortcut, which is created automatically. inside proot and is unnecessary because you already own every file. - Why no real sudo? Android app processes carry the `NO_NEW_PRIVS` flag, and proot cannot grant real root, so `sudo` and `su` can never work inside proot - on any device. You already own every file, so elevation is unnecessary. On - Alpine the manager is `apk`, not `apt`. Bare `apt` resolves to Termux's host - copy and fails to link. + on any device. On Alpine the manager is `apk`, not `apt`. Bare `apt` resolves + to Termux's host copy and fails to link. ### Stopping your Linux desktop @@ -1241,7 +1329,7 @@ short list is: nodes (`lfa usb` provides userspace access instead) - Wayland compositors, simultaneous X11 + VNC, foreign-architecture binaries -Full reasons, the “works with caveats” list, Android 5/6/7 differences, and +Full reasons, the "works with caveats" list, Android 5/6/7 differences, and what Termux:API can actually expose are in [docs/INCOMPATIBLE.md](docs/INCOMPATIBLE.md). @@ -1462,8 +1550,8 @@ If you need `ubuntu-desktop`, note that it is only a metapackage. Removing ### 14. `reboot` / `shutdown` say "System has not been booted with systemd" or "Failed to talk to init daemon" -Cause: a proot guest is a container, not a VM. There is no PID 1, so there is -nothing to reboot. Android owns the kernel. +Cause: a proot guest is a container with no PID 1, so there is nothing to +reboot. Android owns the kernel. Fix: leave the guest with `exit`, then from Termux use `stop-linux` to stop everything or `start-linux` to restart the desktop. From v1.5.8, `reboot`, @@ -1539,7 +1627,7 @@ update-desktop-database /usr/share/applications 2>/dev/null || true ``` Chromium needs `--no-sandbox --disable-dev-shm-usage`. The menu 12 wrapper adds -both. This is a proot limitation, not a bug that can be fixed in the apps. +both. The apps cannot fix this proot limitation. ## Contributing @@ -1564,7 +1652,7 @@ plus `script` from util-linux for the pty test, which is skipped if absent: ```bash chmod +x tests/test-all.sh -./tests/test-all.sh # expect: PASS=881 FAIL=0 +./tests/test-all.sh # expect: PASS=965 FAIL=0 ``` The suite is deliberately stubbed. It cannot prove a desktop actually appears. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 16af8c3..b4fd872 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -63,6 +63,15 @@ saved config ─┘ │ └─ 7. verify core components, then "Installation complete" ``` +A custom source replaces step 2. Guided setup unpacks the chosen ISO, tarball, +or directory into a private staging tree before the desktop/software menus so +it can read `/etc/os-release` and pick the package-manager family. The stage +is moved into the proot-distro container layout once the instance name is +known; `install_linux()` reuses it instead of unpacking twice. If the family is +unknown, the desktop/software menus and the guest setup script are skipped and +the instance is terminal-only. The EXIT trap removes a stage that never +reaches an installed instance. + Step 3 is the unusual one. Instead of a long chain of `proot-distro login ... -- cmd` calls (each paying proot startup and losing environment), the installer writes one guest bash script and runs it once. It is fast and can @@ -225,6 +234,14 @@ desktop user gid 1023 as its primary group, which makes the mode check pass. Without it Thunar draws `emblem-unreadable` on every folder even though the files are readable. +Android storage and external storage are separate policies in the instance +config. With both on, LFA leaves proot-distro's default binds alone. If either +is off, `lfa_storage_args` adds `--isolated` and re-adds only the enabled +category: `/sdcard` plus `/storage/emulated/0` for Android, or +`/media/` for SD cards and USB drives. The same helper is used by +`start-linux`, `terminal-linux`, and `lfa storage status`, so the policy +applies to every normal guest session rather than only the desktop. + `chmod` does not work there. The FUSE mount fixes the mode, so `chmod +x` is ignored even as root. `lfa storage exec` and the guest-side `lfa-run-file` copy a file to `/tmp`, set the mode on the copy, and run it. diff --git a/docs/USB.md b/docs/USB.md index a5c731a..db0d32f 100644 --- a/docs/USB.md +++ b/docs/USB.md @@ -303,6 +303,12 @@ The card destinations deliberately avoid `/sdcard` and `/mnt/sdcard`: proot-distro v5 binds internal storage there already and warns when a destination is used twice. +The card binds follow the instance's external-storage policy. If it is off +(`lfa storage external disable -i NAME`), sessions start with `--isolated` and +neither `/media/` nor `/mnt/card` is bound. `lfa storage android` +controls internal storage separately, so a guest can keep `/sdcard` while +hiding cards and drives. + `lfa usb storage --json` prints the same data for scripts. If `/storage/` is readable but not writable, the mode column says `ro`; proot cannot enforce read-only binds, so LFA warns instead of diff --git a/install_linux.sh b/install_linux.sh index 8d0203a..a2b976a 100755 --- a/install_linux.sh +++ b/install_linux.sh @@ -34,8 +34,23 @@ CLI_INSTANCE="${CLI_INSTANCE:-}" # failed install (a stray copy used to survive forever). # ------------------------------------------------------------ LFA_TMP_ARTIFACTS=() +LFA_TMP_DIRS=() lfa_track_tmp() { LFA_TMP_ARTIFACTS+=("$1"); } +lfa_track_tmpdir() { LFA_TMP_DIRS+=("$1"); } lfa_cleanup() { + # A staged custom userland is a directory, not a file. Only remove it + # while it still lives under the manager's private staging prefix; once + # install_linux moves it into place the variable is cleared. + case "${LFA_CUSTOM_STAGE:-}" in + "$PREFIX"/var/lib/proot-distro/.lfa-custom-*) + rm -rf "$LFA_CUSTOM_STAGE" 2>/dev/null || true ;; + esac + local _d + for _d in ${LFA_TMP_DIRS[@]+"${LFA_TMP_DIRS[@]}"}; do + case "$_d" in + "$PREFIX"/tmp/lfa-custom-*) rm -rf "$_d" 2>/dev/null || true ;; + esac + done [ "${LFA_KEEP_SETUP_SCRIPT:-0}" = "1" ] && return 0 local _f for _f in ${LFA_TMP_ARTIFACTS[@]+"${LFA_TMP_ARTIFACTS[@]}"}; do @@ -910,6 +925,7 @@ SERVER="$SERVER" RESOLUTION="$RESOLUTION" COLOR_MODE="$COLOR_MODE" APP_CHOICES="$APP_CHOICES" +CUSTOM_SOURCE="$(lfa_custom_conf_escape "${LFA_CUSTOM_SOURCE:-}")" INSTANCE_NAME="$INSTANCE_NAME" SETUP_USER="$SETUP_USER" SETUP_USER_B64="$SETUP_USER_B64" @@ -921,6 +937,8 @@ NEED_VIRGL="$NEED_VIRGL" AUTOSTART_SERVER="$AUTOSTART_SERVER" DO_AUTOSTART="$DO_AUTOSTART" DO_STORAGE="$DO_STORAGE" +STORAGE_ANDROID="${STORAGE_ANDROID:-1}" +STORAGE_EXTERNAL="${STORAGE_EXTERNAL:-1}" DO_SSH="$DO_SSH" DO_WIDGET="$DO_WIDGET" EOF @@ -932,6 +950,9 @@ setup_summary() { printf '\n %sSetup Summary%s\n' "$C_BOLD$C_WHITE" "$C_RESET" ui_rule printf ' %s%-13s%s %s\n' "$C_GRAY" "Distribution" "$C_RESET" "$DISTRO" + if [ "${LFA_CUSTOM:-0}" = "1" ] && [ -n "${LFA_CUSTOM_NAME:-}" ]; then + printf ' %s%-13s%s %s\n' "$C_GRAY" "Userland" "$C_RESET" "$LFA_CUSTOM_NAME" + fi printf ' %s%-13s%s %s\n' "$C_GRAY" "Desktop" "$C_RESET" "$DE" [ "$DE" != "none" ] && printf ' %s%-13s%s %s\n' "$C_GRAY" "Wallpaper" "$C_RESET" "$COLOR_MODE" printf ' %s%-13s%s %s\n' "$C_GRAY" "Server" "$C_RESET" "$SERVER" @@ -946,7 +967,8 @@ setup_summary() { printf ' %s%-13s%s %s\n' "$C_GRAY" "HW accel" "$C_RESET" "$([ "$NEED_VIRGL" = "1" ] && echo on || echo off)" printf ' %s%-13s%s %s\n' "$C_GRAY" "Prompt style" "$C_RESET" "$PSTYLE" printf ' %s%-13s%s %s\n' "$C_GRAY" "Autostart" "$C_RESET" "$([ "$DO_AUTOSTART" = "1" ] && echo "yes (${AUTOSTART_SERVER:-$SERVER})" || echo no)" - printf ' %s%-13s%s %s\n' "$C_GRAY" "Storage perm" "$C_RESET" "$([ "$DO_STORAGE" = "1" ] && echo yes || echo no)" + printf ' %s%-13s%s %s\n' "$C_GRAY" "Android stg" "$C_RESET" "$([ "${STORAGE_ANDROID:-1}" = "1" ] && echo yes || echo no)" + printf ' %s%-13s%s %s\n' "$C_GRAY" "External stg" "$C_RESET" "$([ "${STORAGE_EXTERNAL:-1}" = "1" ] && echo yes || echo no)" printf ' %s%-13s%s %s\n' "$C_GRAY" "SSH server" "$C_RESET" "$([ "$DO_SSH" = "1" ] && echo yes || echo no)" printf ' %s%-13s%s %s\n' "$C_GRAY" "Widget hint" "$C_RESET" "$([ "$DO_WIDGET" = "1" ] && echo yes || echo no)" ui_rule @@ -970,6 +992,8 @@ setup_quick() { if [ "$IS_LEGACY" = "1" ]; then NEED_VIRGL=0; else NEED_VIRGL=1; fi AUTOSTART_SERVER="$SERVER" DO_AUTOSTART=0 + STORAGE_ANDROID=1 + STORAGE_EXTERNAL=1 DO_STORAGE=1 DO_SSH=0 DO_WIDGET=0 @@ -996,7 +1020,8 @@ setup_guided() { "5|OpenSUSE|Zypper · enterprise" \ "6|Void Linux|XBPS · lightweight, rolling" \ "7|Arch Linux|Pacman · rolling (may be unstable on ARM64)" \ - "8|Alpine Linux|APK · musl · best for Android 5/6 + low RAM"; then + "8|Alpine Linux|APK · musl · best for Android 5/6 + low RAM" \ + "9|Custom Linux ISO / rootfs|extract any proot-compatible userland"; then show_menu return fi @@ -1012,8 +1037,36 @@ setup_guided() { 6) DISTRO="void"; break ;; 7) DISTRO="archlinux"; break ;; 8) DISTRO="alpine"; break ;; + 9) DISTRO="custom"; break ;; esac done + if [ "$DISTRO" = "custom" ]; then + if [ -z "${LFA_CUSTOM_SOURCE:-}" ]; then + if ! lfa_custom_ask_source; then + show_menu + return + fi + fi + if ! lfa_custom_stage_source; then + ui_pause + show_menu + return 1 + fi + if [ "$LFA_CUSTOM_FAMILY" = "unknown" ]; then + LFA_CUSTOM_UNKNOWN=1 + fi + fi + if [ "${LFA_CUSTOM_UNKNOWN:-0}" = "1" ]; then + # No package manager LFA can drive: keep the questions that still + # apply (name, user, passwords, timezone, SSH) and skip the rest. + DE="none"; SERVER="none"; COLOR_MODE="light" + RESOLUTION="1280x720"; NEED_VIRGL=0; AUTOSTART_SERVER="none" + APP_CHOICES="" + echo "" + echo "[!] LFA does not know this userland's package manager." + echo " It installs as a terminal-only system. Add a desktop inside" + echo " the guest with its own package manager if you want one." + else # 2. Desktop local _de _dedef if [ "$IS_LEGACY" = "1" ] || [ "$(setup_ram_mb)" -le 2048 ]; then _de="None (CLI only)"; _dedef=4; else _de="XFCE4"; _dedef=1; fi @@ -1021,7 +1074,7 @@ setup_guided() { show_menu return fi - if [ "$DISTRO" = "alpine" ] && [ "$DE" = "lxde" ]; then + if { [ "$DISTRO" = "alpine" ] || [ "${LFA_CUSTOM_FAMILY:-}" = "alpine" ]; } && [ "$DE" = "lxde" ]; then echo "[*] LXDE is not packaged for Alpine -> using XFCE4 instead." DE="xfce4" fi @@ -1101,6 +1154,7 @@ setup_guided() { return fi APP_CHOICES="$UI_MULTI" + fi # 5. Instance name echo "" while true; do @@ -1161,7 +1215,8 @@ setup_guided() { 2) PSTYLE="informative" ;; esac # 12-14. Autostart / storage / SSH / widget - if ui_confirm "Autostart at boot via Termux:Boot? (needs the Termux:Boot app)" n; then + if [ "${LFA_CUSTOM_UNKNOWN:-0}" != "1" ] && \ + ui_confirm "Autostart at boot via Termux:Boot? (needs the Termux:Boot app)" n; then DO_AUTOSTART=1 if [ "$SERVER" = "both" ]; then if ! ui_select "Autostart backend" "1" \ @@ -1183,7 +1238,21 @@ setup_guided() { DO_AUTOSTART=0 AUTOSTART_SERVER="none" fi - if ui_confirm "Request Android storage access now? (Downloads/Documents)" y; then DO_STORAGE=1; else DO_STORAGE=0; fi + if ! ui_select "Storage inside Linux (Android and external are separate)" "1" \ + "1|Both|Android shared storage + SD cards/USB drives" \ + "2|Android only|shared storage, no external devices" \ + "3|External only|SD cards/USB drives, no Android shared storage" \ + "4|None|no host storage inside Linux"; then + show_menu + return + fi + case "$UI_SELECTED" in + 2) STORAGE_ANDROID=1; STORAGE_EXTERNAL=0 ;; + 3) STORAGE_ANDROID=0; STORAGE_EXTERNAL=1 ;; + 4) STORAGE_ANDROID=0; STORAGE_EXTERNAL=0 ;; + *) STORAGE_ANDROID=1; STORAGE_EXTERNAL=1 ;; + esac + if [ "$STORAGE_ANDROID" = "1" ] || [ "$STORAGE_EXTERNAL" = "1" ]; then DO_STORAGE=1; else DO_STORAGE=0; fi if ui_confirm "Start an SSH server after install? (port 8022)" n; then DO_SSH=1; else DO_SSH=0; fi if ui_confirm "Show Termux:Widget shortcut instructions?" n; then DO_WIDGET=1; else DO_WIDGET=0; fi # Summary + save + go @@ -1191,6 +1260,10 @@ setup_guided() { UI_NO_CLEAR=1 if ! ui_confirm "Proceed with installation?" y; then echo "Setup cancelled." + case "${LFA_CUSTOM_STAGE:-}" in + "$PREFIX"/var/lib/proot-distro/.lfa-custom-*) + rm -rf "$LFA_CUSTOM_STAGE"; LFA_CUSTOM_STAGE="" ;; + esac show_menu return fi @@ -1215,8 +1288,15 @@ setup_load_saved() { : "${SETUP_USER_B64:=cm9vdA==}" "${SETUP_ROOT_B64:=cm9vdA==}" : "${TIMEZONE:=UTC}" "${HOSTNAME:=localhost}" "${PSTYLE:=minimal}" : "${NEED_VIRGL:=1}" "${DO_AUTOSTART:=0}" "${DO_STORAGE:=1}" + if [ "${DO_STORAGE:-1}" = "0" ]; then + : "${STORAGE_ANDROID:=0}" "${STORAGE_EXTERNAL:=0}" + else + : "${STORAGE_ANDROID:=1}" "${STORAGE_EXTERNAL:=1}" + fi : "${DO_SSH:=0}" "${DO_WIDGET:=0}" - : "${AUTOSTART_SERVER:=}" + : "${AUTOSTART_SERVER:=}" "${CUSTOM_SOURCE:=}" + LFA_CUSTOM_SOURCE="$CUSTOM_SOURCE" + if [ "${DISTRO:-}" = "custom" ]; then LFA_CUSTOM=1; fi if [ -z "$AUTOSTART_SERVER" ]; then case "$SERVER" in both) AUTOSTART_SERVER="vnc" ;; @@ -1461,7 +1541,13 @@ Global short option: Install options: -d, --distro NAME ubuntu, debian, kali, fedora, opensuse, - void, archlinux, alpine + void, archlinux, alpine, custom + --iso PATH custom live ISO (its root filesystem is extracted) + --rootfs PATH custom rootfs tarball or extracted directory + --android-storage on|off + expose Android shared storage in the guest (default on) + --external-storage on|off + expose SD cards/USB drives in the guest (default on) -D, --desktop NAME xfce4, lxde, mate, gnome, none -b, --backend NAME x11, vnc, both, none -a, --autostart NAME x11, vnc, none @@ -1484,6 +1570,8 @@ Compatibility options: Examples: lfa install --distro ubuntu --desktop xfce4 --backend both -i ubuntu + lfa install --iso ~/storage/downloads/debian-live-arm64.iso -i debian-live + lfa install --rootfs ~/storage/downloads/alpine-rootfs.tar.gz -i alpine-custom lfa start -i ubuntu --vnc lfa shell -i ubuntu --user lfa switch x11 -i ubuntu --remove-old @@ -5133,14 +5221,14 @@ lfa_instance_session_running() { # $1 = instance } lfa_cli_status_one() { # $1 = instance, $2 = json - local _inst="$1" _json="${2:-0}" _conf _d _de _srv _auto _pid _run="none" + local _inst="$1" _json="${2:-0}" _conf _d _de _srv _auto _pid _run="none" _cname="" _conf="$(pd_conf "$_inst" 2>/dev/null)" _d=""; _de=""; _srv="none"; _auto="none" if [ -f "$_conf" ]; then # shellcheck disable=SC1090 - { IFS= read -r _d; IFS= read -r _de; IFS= read -r _srv; IFS= read -r _auto; } < <( + { IFS= read -r _d; IFS= read -r _de; IFS= read -r _srv; IFS= read -r _auto; IFS= read -r _cname; } < <( . "$_conf" 2>/dev/null - printf '%s\n%s\n%s\n%s\n' "${DISTRO:-}" "${DE:-none}" "${SERVER:-none}" "${AUTOSTART_SERVER:-none}" + printf '%s\n%s\n%s\n%s\n%s\n' "${DISTRO:-}" "${DE:-none}" "${SERVER:-none}" "${AUTOSTART_SERVER:-none}" "${CUSTOM_NAME:-}" ) fi if [ -f "$PREFIX/tmp/lfa-vnc-$_inst.pid" ]; then @@ -5158,6 +5246,7 @@ lfa_cli_status_one() { # $1 = instance, $2 = json else echo "instance: $_inst" echo "distro: ${_d:-unknown}" + [ -n "$_cname" ] && echo "userland: $_cname" echo "desktop: ${_de:-none}" echo "backend: ${_srv:-none}" echo "autostart: ${_auto:-none}" @@ -5573,6 +5662,11 @@ Usage: lfa storage [options] fix | fx repair links, bookmarks, and the storage group exec | x FILE [args...] run a file from shared storage without chmod open | o show where shared storage is and how to open it + android enable|disable|status [--all] + expose Android shared storage in the guest + external enable|disable|status [--all] + expose SD cards/USB drives in the guest + (on/off are aliases; -i NAME picks one instance) data status check adb access to Android/data and Android/obb (short: d st) data list list packages under Android/data and Android/obb @@ -5646,17 +5740,24 @@ lfa_storage_status() { require_proot_distro || return 1 [ -n "$_inst" ] && CLI_INSTANCE="$_inst" select_installed_instance || return 1 - local _id="$INSTANCE_NAME" _user _out + local _id="$INSTANCE_NAME" _user _out _android _external _st_args=() _user="$(lfa_appimage_user "$_id")" echo "instance: $_id" + # shellcheck disable=SC1090 # instance config, path resolved at runtime + _android="$( . "$(pd_conf "$_id")" 2>/dev/null; printf '%s' "${STORAGE_ANDROID:-1}" )" + # shellcheck disable=SC1090 + _external="$( . "$(pd_conf "$_id")" 2>/dev/null; printf '%s' "${STORAGE_EXTERNAL:-1}" )" + echo "android storage: $([ "$_android" = "1" ] && echo on || echo off)" + echo "external storage: $([ "$_external" = "1" ] && echo on || echo off)" if [ -d "$HOME/storage" ]; then echo "termux storage: present" echo "shared target: $(readlink -f "$HOME/storage/shared" 2>/dev/null || echo unknown)" else echo "termux storage: missing (run: lfa storage fix -i $_id)" fi + mapfile -t _st_args < <(lfa_storage_args "$_id") # shellcheck disable=SC2046 # flag list, not one argument - _out="$(proot-distro login $(pd_login_flags) "$_id" --user "$_user" --shared-tmp -- bash -c ' + _out="$(proot-distro login $(pd_login_flags) "${_st_args[@]}" "$_id" --user "$_user" --shared-tmp -- bash -c ' printf "guest gid: %s\n" "$(id -g)" printf "storage: " ls -ld /storage/emulated/0 2>&1 @@ -5899,6 +6000,81 @@ lfa_storage_data() { esac } +lfa_storage_policy() { # $1 = android|external, $2 = enable|disable|status, then -i NAME | --all + local _what="$1" _mode="${2:-status}" _inst="" _all=0 _conf _cur _val _name _rc=0 + local -a _targets=() + [ $# -gt 0 ] && shift || true + [ $# -gt 0 ] && shift || true + while [ $# -gt 0 ]; do + case "$1" in + -i|--instance) _inst="${2:-}"; shift 2 ;; + --all|-a) _all=1; shift ;; + *) echo "Unknown option: $1" >&2; return 2 ;; + esac + done + case "$_what" in + android|external) ;; + *) echo "Unknown storage policy: $_what" >&2; return 2 ;; + esac + if [ "$_all" = "1" ] && [ -n "$_inst" ]; then + echo "Use --all or -i NAME, not both." >&2 + return 2 + fi + case "$_mode" in + status|st) _mode=status ;; + on|enable|1|yes) _mode=enable ;; + off|disable|0|no) _mode=disable ;; + *) echo "Usage: lfa storage $_what enable|disable|status [--all | -i NAME]" >&2; return 2 ;; + esac + require_proot_distro || return 1 + if [ "$_all" = "1" ]; then + mapfile -t _targets < <(pd_instances) + [ "${#_targets[@]}" -gt 0 ] || { echo "No distributions installed." >&2; return 1; } + else + [ -n "$_inst" ] && CLI_INSTANCE="$_inst" + select_installed_instance || return 1 + [ -n "${INSTANCE_NAME:-}" ] || return 1 + _targets=("$INSTANCE_NAME") + fi + for _name in "${_targets[@]}"; do + _conf="$(pd_conf "$_name" 2>/dev/null)" + if [ ! -f "$_conf" ]; then + echo "$_name: no config" >&2 + [ "$_all" = "1" ] && { _rc=1; continue; } + return 1 + fi + if [ "$_what" = "android" ]; then + # shellcheck disable=SC1090 # instance config, path resolved at runtime + _cur="$( . "$_conf" 2>/dev/null; printf '%s' "${STORAGE_ANDROID:-1}" )" + else + # shellcheck disable=SC1090 + _cur="$( . "$_conf" 2>/dev/null; printf '%s' "${STORAGE_EXTERNAL:-1}" )" + fi + if [ "$_mode" = "status" ]; then + [ "$_all" = "1" ] && printf '%s: ' "$_name" + echo "$_what storage: $([ "$_cur" = "1" ] && echo on || echo off)" + continue + fi + if [ "$_mode" = "enable" ]; then _val=1; else _val=0; fi + if [ "$_what" = "android" ]; then + if grep -q '^STORAGE_ANDROID=' "$_conf" 2>/dev/null; then + sed -i "s/^STORAGE_ANDROID=.*/STORAGE_ANDROID=\"$_val\"/" "$_conf" + else + printf 'STORAGE_ANDROID="%s"\n' "$_val" >> "$_conf" + fi + else + if grep -q '^STORAGE_EXTERNAL=' "$_conf" 2>/dev/null; then + sed -i "s/^STORAGE_EXTERNAL=.*/STORAGE_EXTERNAL=\"$_val\"/" "$_conf" + else + printf 'STORAGE_EXTERNAL="%s"\n' "$_val" >> "$_conf" + fi + fi + [ "$_all" = "1" ] && printf '%s: ' "$_name" + echo "$_what storage: $([ "$_val" = "1" ] && echo on || echo off) (new sessions)" + done + return "$_rc" +} + lfa_cli_storage() { local _sub="${1:-status}" [ $# -gt 0 ] && shift || true @@ -5915,6 +6091,8 @@ lfa_cli_storage() { exec) lfa_storage_exec "$@" ;; open) lfa_storage_open "$@" ;; data) lfa_storage_data "$@" ;; + android|and) lfa_storage_policy android "$@" ;; + external|ext) lfa_storage_policy external "$@" ;; help|-h|--help) lfa_storage_usage ;; *) echo "Unknown storage command: $_sub" >&2; lfa_storage_usage >&2; return 2 ;; esac @@ -5965,9 +6143,17 @@ lfa_software_choices() { # $1 = comma-separated names -> space-separated menu n lfa_cli_install() { local _distro="" _de="" _backend="" _inst="" _auto="" _user="user" _tz="" _host="localhost" _software="" + local _source="" _storage_android="1" _storage_external="1" while [ $# -gt 0 ]; do case "$1" in --distro|-d) _distro="${2:-}"; shift 2 ;; + --android-storage) _storage_android="${2:-}"; shift 2 ;; + --external-storage) _storage_external="${2:-}"; shift 2 ;; + --no-android-storage) _storage_android="off"; shift ;; + --no-external-storage) _storage_external="off"; shift ;; + --iso|--rootfs|--rootfs-tar) + [ $# -ge 2 ] || { echo "[!] $1 needs a path." >&2; return 2; } + _source="$2"; shift 2 ;; --desktop|-D) _de="${2:-}"; shift 2 ;; --backend|-b) _backend="${2:-}"; shift 2 ;; -i|--instance) _inst="${2:-}"; shift 2 ;; @@ -5980,6 +6166,25 @@ lfa_cli_install() { *) echo "Unknown option: $1" >&2; return 2 ;; esac done + if [ -n "$_source" ] && [ -z "$_distro" ]; then _distro="custom"; fi + if [ "$_distro" = "custom" ] && [ -z "$_source" ]; then + echo "[!] A custom install needs --iso PATH or --rootfs PATH." >&2 + return 2 + fi + if [ "$_distro" != "custom" ] && [ -n "$_source" ]; then + echo "[!] --iso/--rootfs imply --distro custom; drop the other --distro." >&2 + return 2 + fi + case "$_storage_android" in + on|yes|1|true|enabled) _storage_android=1 ;; + off|no|0|false|disabled) _storage_android=0 ;; + *) echo "Invalid --android-storage value '$_storage_android': use on or off." >&2; return 2 ;; + esac + case "$_storage_external" in + on|yes|1|true|enabled) _storage_external=1 ;; + off|no|0|false|disabled) _storage_external=0 ;; + *) echo "Invalid --external-storage value '$_storage_external': use on or off." >&2; return 2 ;; + esac local _software_choices="" if [ -n "$_software" ]; then _software_choices="$(lfa_software_choices "$_software")" || return 2 @@ -6003,9 +6208,13 @@ lfa_cli_install() { if [ -z "$_distro" ]; then [ "$IS_LEGACY" = "1" ] && _distro="alpine" || _distro="debian" fi - case "$_distro" in ubuntu|debian|kali|fedora|opensuse|void|archlinux|alpine) ;; *) echo "Unknown distro: $_distro" >&2; return 2 ;; esac + case "$_distro" in ubuntu|debian|kali|fedora|opensuse|void|archlinux|alpine|custom) ;; *) echo "Unknown distro: $_distro" >&2; return 2 ;; esac if [ -z "$_de" ]; then - if [ "$IS_LEGACY" = "1" ] || [ "$(setup_ram_mb)" -le 2048 ]; then _de="none"; else _de="xfce4"; fi + if [ "$_distro" = "custom" ] || [ "$IS_LEGACY" = "1" ] || [ "$(setup_ram_mb)" -le 2048 ]; then + _de="none" + else + _de="xfce4" + fi fi case "$_de" in xfce|xfce4) _de="xfce4" ;; lxde|mate|gnome|none) ;; *) echo "Unknown desktop: $_de" >&2; return 2 ;; esac if [ "$_de" = "none" ] && [ -n "$_backend" ] && [ "$_backend" != "none" ]; then @@ -6034,6 +6243,10 @@ lfa_cli_install() { fi _tz="${_tz:-$(setup_guess_timezone)}" DISTRO="$_distro"; DE="$_de"; SERVER="$_backend" + if [ "$_distro" = "custom" ]; then + LFA_CUSTOM=1 + LFA_CUSTOM_SOURCE="$_source" + fi INSTANCE_NAME="$_inst" SETUP_USER="$_user" SETUP_USER_B64="$(b64enc "${LFA_USER_PASSWORD:-root}")" @@ -6042,6 +6255,7 @@ lfa_cli_install() { RESOLUTION="${LFA_RESOLUTION:-1280x720}" APP_CHOICES="$_software_choices" NEED_VIRGL=1; [ "$IS_LEGACY" = "1" ] && NEED_VIRGL=0 + [ "$_de" = "none" ] && NEED_VIRGL=0 DO_AUTOSTART=0; AUTOSTART_SERVER="none" if [ -n "$_auto" ] && [ "$_auto" != "none" ]; then case "$_auto" in x11|vnc) ;; *) echo "Unknown autostart backend: $_auto" >&2; return 2 ;; esac @@ -6053,7 +6267,11 @@ lfa_cli_install() { fi DO_AUTOSTART=1; AUTOSTART_SERVER="$_auto" fi - DO_STORAGE=0; DO_SSH=0; DO_WIDGET=0; SETUP_ANSWERED=1 + STORAGE_ANDROID="$_storage_android" + STORAGE_EXTERNAL="$_storage_external" + DO_STORAGE=0 + if [ "$STORAGE_ANDROID" = "1" ] || [ "$STORAGE_EXTERNAL" = "1" ]; then DO_STORAGE=1; fi + DO_SSH=0; DO_WIDGET=0; SETUP_ANSWERED=1 setup_save LFA_NONINTERACTIVE=1 LFA_ASSUME_YES=1 install_linux } @@ -6379,7 +6597,8 @@ select_os_flavor() { "5|OpenSUSE|Zypper" \ "6|Void Linux|XBPS" \ "7|Arch Linux|Pacman · may be unstable on ARM64" \ - "8|Alpine Linux|APK · musl · best for Android 5/6"; then + "8|Alpine Linux|APK · musl · best for Android 5/6" \ + "9|Custom Linux ISO / rootfs|extract any proot-compatible userland"; then return 1 fi case "$UI_SELECTED" in @@ -6391,6 +6610,7 @@ select_os_flavor() { 6) DISTRO="void" ;; 7) DISTRO="archlinux" ;; 8) DISTRO="alpine" ;; + 9) DISTRO="custom" ;; esac } @@ -6446,6 +6666,522 @@ pd_instance_exists() { [ -d "$base/installed-rootfs/$inst/var" ] || [ -d "$base/installed-rootfs/$inst/usr" ] } +# Storage policy for a guest session. Both categories default to on, which +# keeps proot-distro's normal /storage and /sdcard binds. When either one is +# disabled the session becomes --isolated and LFA adds only the binds the +# user kept, so the disabled category cannot leak through /storage. +lfa_storage_args() { # $1 = instance; prints proot-distro login arguments + local _inst="${1:-}" _conf="" _root="" _android=1 _external=1 + local _shared="" _vol _id _spec _guest _ifs + if declare -F pd_conf >/dev/null 2>&1; then + _conf="$(pd_conf "$_inst" 2>/dev/null || true)" + _root="$(pd_rootfs "$_inst" 2>/dev/null || true)" + else + _conf="$(lfa_conf "$_inst" 2>/dev/null || true)" + _root="$(lfa_rootfs "$_inst" 2>/dev/null || true)" + fi + if [ -f "$_conf" ]; then + # shellcheck disable=SC1090 + _android="$( . "$_conf" 2>/dev/null; printf '%s' "${STORAGE_ANDROID:-1}" )" + # shellcheck disable=SC1090 + _external="$( . "$_conf" 2>/dev/null; printf '%s' "${STORAGE_EXTERNAL:-1}" )" + fi + case "$_android" in 0|no|off|false|disabled) _android=0 ;; *) _android=1 ;; esac + case "$_external" in 0|no|off|false|disabled) _external=0 ;; *) _external=1 ;; esac + + _lfa_storage_emit() { # $1 = host:guest + _guest="${1##*:}" + [ -n "$_root" ] && mkdir -p "$_root$_guest" 2>/dev/null || true + printf '%s\n' "--bind" "$1" + } + + if [ "$_android" = "1" ] && [ "$_external" = "1" ]; then + # Default binds already expose both. USB auto mode may have added + # explicit card binds; keep them. + if [ -n "${LFA_STORAGE_BIND:-}" ]; then + _ifs="$IFS"; IFS=';' + for _spec in $LFA_STORAGE_BIND; do + [ -n "$_spec" ] && _lfa_storage_emit "$_spec" + done + IFS="$_ifs" + fi + return 0 + fi + + printf '%s\n' "--isolated" + if [ "$_android" = "1" ]; then + for _shared in /storage/self/primary /storage/emulated/0 /sdcard; do + [ -d "$_shared" ] && break + _shared="" + done + if [ -n "$_shared" ]; then + _lfa_storage_emit "$_shared:/sdcard" + _lfa_storage_emit "$_shared:/storage/emulated/0" + fi + fi + if [ "$_external" = "1" ]; then + if [ -n "${LFA_STORAGE_BIND:-}" ]; then + _ifs="$IFS"; IFS=';' + for _spec in $LFA_STORAGE_BIND; do + [ -n "$_spec" ] && _lfa_storage_emit "$_spec" + done + IFS="$_ifs" + else + for _vol in /storage/*; do + _id="${_vol##*/}" + case "$_id" in emulated|self|sdcard0) continue ;; esac + [ -d "$_vol" ] || continue + _lfa_storage_emit "$_vol:/media/$_id" + done + fi + fi +} + +# ============================================================ +# Custom Linux userlands (ISO, rootfs tarball, directory) +# +# proot has no kernel, no loop devices and no real mounts, so an ISO +# cannot be booted. What can run is its root filesystem: LFA extracts +# the live squashfs and treats the result like any other container. +# The userland must match the phone CPU and carry its own package +# manager; LFA only automates the distros it recognises. +# ============================================================ +LFA_CUSTOM=0 +LFA_CUSTOM_SOURCE="" +LFA_CUSTOM_FAMILY="" +LFA_CUSTOM_ID="" +LFA_CUSTOM_NAME="" +LFA_CUSTOM_ARCH="" +LFA_CUSTOM_STAGE="" +LFA_CUSTOM_UNKNOWN=0 + +lfa_custom_conf_escape() { # $1 = text for a double-quoted conf value + printf '%s' "${1:-}" | sed 's/[\\"$`]/\\&/g' +} + +lfa_custom_expand_path() { # $1 = user path; prints an absolute path + local _p="${1:-}" _tilde="~" + _p="${_p%\"}"; _p="${_p#\"}" + _p="${_p%\'}"; _p="${_p#\'}" + case "$_p" in + "$_tilde") _p="$HOME" ;; + "$_tilde"/*) _p="$HOME/${_p:2}" ;; + esac + case "$_p" in + /*) ;; + *) _p="$PWD/$_p" ;; + esac + printf '%s\n' "$_p" +} + +lfa_custom_host_arch() { + case "$(uname -m)" in + aarch64|arm64|armv8b) printf 'aarch64\n' ;; + armv7l|armv7|armv6l|arm) printf 'arm\n' ;; + x86_64|amd64) printf 'x86_64\n' ;; + i386|i486|i586|i686) printf 'i386\n' ;; + *) uname -m ;; + esac +} + +lfa_custom_has_sh() { # $1 = rootfs + local _r="$1" + if [ -e "$_r/bin/sh" ] || [ -L "$_r/bin/sh" ]; then return 0; fi + if [ -e "$_r/usr/bin/sh" ] || [ -L "$_r/usr/bin/sh" ]; then return 0; fi + return 1 +} + +lfa_custom_check_arch() { # $1 = rootfs + local _g _h + _g="$(lfa_usb_elf_arch "$1")" + _h="$(lfa_custom_host_arch)" + LFA_CUSTOM_ARCH="$_g" + if [ "$_g" = "unknown" ]; then + echo "[!] Could not read the userland architecture; continuing anyway." + return 0 + fi + [ "$_g" = "$_h" ] && return 0 + case "$_h:$_g" in + aarch64:arm|x86_64:i386) + echo "[!] This is a $_g userland on a $_h device. It can work, but" + echo " the 32-bit runtime is not installed by default." + return 0 ;; + esac + echo "[!] This image is $_g, but this device is $_h." + echo " proot does not emulate another CPU, so it cannot run here." + echo " Use an $_h rootfs or ISO (on phones that is usually arm64)." + return 1 +} + +lfa_custom_read_osrelease() { # $1 = rootfs; sets ID/NAME globals + local _root="$1" _rel="" _name + LFA_CUSTOM_ID="" + LFA_CUSTOM_NAME="" + for _rel in "$_root/etc/os-release" "$_root/usr/lib/os-release"; do + [ -r "$_rel" ] && break + _rel="" + done + [ -n "$_rel" ] || return 0 + LFA_CUSTOM_ID="$(sed -n 's/^ID=//p' "$_rel" | head -n1 | tr -d "\"'")" + LFA_CUSTOM_NAME="$(sed -n 's/^PRETTY_NAME=//p' "$_rel" | head -n1 | tr -d "\"'")" + if [ -z "$LFA_CUSTOM_NAME" ]; then + _name="$(sed -n 's/^NAME=//p' "$_rel" | head -n1 | tr -d "\"'")" + LFA_CUSTOM_NAME="$_name" + fi +} + +lfa_custom_family() { # $1 = rootfs; prints a family LFA can drive + local _root="$1" _like="" _rel="" _tok + lfa_custom_read_osrelease "$_root" + for _rel in "$_root/etc/os-release" "$_root/usr/lib/os-release"; do + [ -r "$_rel" ] && break + _rel="" + done + if [ -n "$_rel" ]; then + _like="$(sed -n 's/^ID_LIKE=//p' "$_rel" | head -n1 | tr -d "\"'")" + fi + for _tok in $LFA_CUSTOM_ID $_like; do + case "$_tok" in + kali) printf 'kali\n'; return 0 ;; + ubuntu|linuxmint|pop|elementary|zorin|neon|kubuntu|xubuntu|lubuntu) + printf 'ubuntu\n'; return 0 ;; + debian|devuan|raspbian|mx|parrot) + printf 'debian\n'; return 0 ;; + fedora|rhel|centos|rocky|almalinux|nobara|bazzite|amzn) + printf 'fedora\n'; return 0 ;; + opensuse*|suse|sles|tumbleweed|leap) + printf 'opensuse\n'; return 0 ;; + void) printf 'void\n'; return 0 ;; + arch|archlinux|archarm|manjaro|endeavouros|garuda|artix|cachyos) + printf 'archlinux\n'; return 0 ;; + alpine|postmarketos) + printf 'alpine\n'; return 0 ;; + esac + done + printf 'unknown\n' +} + +lfa_custom_type() { # $1 = source; prints dir|tar|image|unknown + local _p="$1" _magic + if [ -d "$_p" ]; then printf 'dir\n'; return 0; fi + case "$_p" in + *.iso|*.ISO|*.img|*.IMG|*.zip|*.ZIP) printf 'image\n'; return 0 ;; + *.tar|*.tar.gz|*.tgz|*.tar.xz|*.txz|*.tar.bz2|*.tbz2|*.tar.zst|*.tzst) + printf 'tar\n'; return 0 ;; + esac + _magic="$(od -An -tx1 -N6 "$_p" 2>/dev/null | tr -d ' \n')" + case "$_magic" in + 1f8b*|fd377a585a00*|425a68*|28b52ffd*|504b0304*) + printf 'tar\n'; return 0 ;; + esac + if [ "$(dd if="$_p" bs=1 skip=32769 count=5 2>/dev/null)" = "CD001" ]; then + printf 'image\n'; return 0 + fi + printf 'unknown\n' +} + +lfa_custom_is_oci() { # $1 = tar; true for an OCI/docker archive + local _list _rc=1 + _list="$(mktemp "$PREFIX/tmp/lfa-oci.XXXXXX")" || return 1 + lfa_track_tmp "$_list" + if tar -tf "$1" > "$_list" 2>/dev/null; then + grep -qxE 'oci-layout|manifest\.json' "$_list" && _rc=0 + fi + rm -f "$_list" + return $_rc +} + +lfa_custom_ask_source() { + local _p + echo "" + echo " Custom Linux userland (runs under proot)" + echo " Point at a rootfs tarball, an extracted directory, or a live ISO." + echo " For an ISO, LFA extracts the live root filesystem; proot cannot" + echo " boot the ISO itself." + echo "" + echo " Example: ~/storage/downloads/debian-rootfs.tar.gz" + echo "" + while :; do + if ! read -r -p "Path to ISO / rootfs archive / directory: " _p; then + echo "" + return 1 + fi + if [ -z "$_p" ]; then + echo "[!] Enter a path (or press Ctrl-C to go back)." + continue + fi + _p="$(lfa_custom_expand_path "$_p")" + if [ ! -e "$_p" ]; then + echo "[!] Not found: $_p" + continue + fi + LFA_CUSTOM_SOURCE="$_p" + return 0 + done +} + +lfa_custom_legacy_layout() { + [ "${IS_LEGACY:-0}" = "1" ] && return 0 + command -v proot-distro >/dev/null 2>&1 && pd_is_v4 && return 0 + return 1 +} + +lfa_custom_rootfs_new() { # $1 = instance; prints the directory to create + local _base="$PREFIX/var/lib/proot-distro" + if lfa_custom_legacy_layout; then + printf '%s' "$_base/installed-rootfs/$1" + elif [ -d "$_base/installed-rootfs" ] && [ ! -d "$_base/containers" ]; then + printf '%s' "$_base/installed-rootfs/$1" + else + printf '%s' "$_base/containers/$1/rootfs" + fi +} + +lfa_custom_default_name() { + local _n="${LFA_CUSTOM_ID:-custom}" + _n="$(printf '%s' "$_n" | tr -c 'A-Za-z0-9_.-' '-' | sed 's/^-*//; s/-*$//')" + [ -n "$_n" ] || _n="custom" + printf '%s\n' "$_n" +} + +lfa_custom_install_tool() { # $1 = command, $2 = package + command -v "$1" >/dev/null 2>&1 && return 0 + echo "[*] Installing $2 (needed to unpack this image)..." + pkg install -y "$2" >/dev/null 2>&1 || pkg install "$2" -y >/dev/null 2>&1 || true + command -v "$1" >/dev/null 2>&1 +} + +lfa_custom_flatten() { # $1 = rootfs; lift a single top-level directory + local _root="$1" _entry + lfa_custom_has_sh "$_root" && return 0 + local -a _entries=() + for _entry in "$_root"/*; do + [ -e "$_entry" ] || continue + _entries+=("$_entry") + done + [ "${#_entries[@]}" -eq 1 ] || return 1 + [ -d "${_entries[0]}" ] || return 1 + lfa_custom_has_sh "${_entries[0]}" || return 1 + ( shopt -s dotglob; mv "${_entries[0]}"/* "$_root"/ ) || return 1 + rmdir "${_entries[0]}" 2>/dev/null || true + return 0 +} + +lfa_custom_extract_tar() { # $1 = archive, $2 = target + local _src="$1" _dst="$2" _list + # Refuse absolute or parent-relative members. A rootfs tarball has no + # reason to escape its destination, and the target is user-supplied. + if _list="$(tar -tf "$_src" 2>/dev/null)"; then + if printf '%s\n' "$_list" | grep -Eq '(^/|(^|/)\.\.(/|$))'; then + echo "[!] Refusing an archive with absolute or parent-relative paths." + return 1 + fi + fi + if tar -xf "$_src" -C "$_dst" 2>/dev/null; then return 0; fi + case "$_src" in + *.tar.gz|*.tgz) tar -xzf "$_src" -C "$_dst" ;; + *.tar.xz|*.txz) tar -xJf "$_src" -C "$_dst" ;; + *.tar.bz2|*.tbz2) tar -xjf "$_src" -C "$_dst" ;; + *.tar.zst|*.tzst) tar --zstd -xf "$_src" -C "$_dst" ;; + *) return 1 ;; + esac +} + +lfa_custom_extract_image() { # $1 = ISO/raw image, $2 = target + local _img="$1" _dst="$2" _work="" _stage="" _cand _found=0 + local -a _cands=() + local _log="$PREFIX/tmp/lfa-custom-extract.log" + lfa_track_tmp "$_log" + _work="$(mktemp -d "$PREFIX/tmp/lfa-custom-iso.XXXXXX")" || return 1 + lfa_track_tmpdir "$_work" + _stage="$(mktemp -d "$PREFIX/tmp/lfa-custom-root.XXXXXX")" || { + rm -rf "$_work"; return 1 + } + lfa_track_tmpdir "$_stage" + if ! lfa_custom_install_tool 7z 7zip; then + echo "[!] 7z is required to unpack this image." + echo " Install it with: pkg install 7zip" + rm -rf "$_work" "$_stage" + return 1 + fi + echo "[*] Unpacking $(basename "$_img") (this can take a while)..." + if ! 7z x -y -o"$_work" "$_img" >"$_log" 2>&1; then + echo "[!] Could not unpack this image." + tail -n 5 "$_log" 2>/dev/null || true + rm -rf "$_work" "$_stage" + return 1 + fi + # A zipped rootfs often has one top-level directory; flatten it before + # deciding that this image has no root filesystem at all. + lfa_custom_flatten "$_work" || true + if lfa_custom_has_sh "$_work"; then + cp -a "$_work/." "$_dst/" || { + echo "[!] Could not copy the extracted root filesystem." + rm -rf "$_work" "$_stage" + return 1 + } + rm -rf "$_work" "$_stage" + return 0 + fi + while IFS= read -r _cand; do + [ -n "$_cand" ] && _cands+=("$_cand") + done < <(find "$_work" -type f \( \ + -name 'filesystem.squashfs' -o -name 'rootfs.squashfs' -o \ + -name 'airootfs.squashfs' -o -name '*.squashfs' -o \ + -name 'squashfs.img' -o -name 'rootfs.img' -o -name '*.ext4' \) \ + 2>/dev/null | sort) + if [ "${#_cands[@]}" -eq 0 ]; then + echo "[!] No root filesystem was found in this image." + echo " Live ISOs store one as squashfs; installer-only images do not." + echo " Use a rootfs tarball for those." + rm -rf "$_work" "$_stage" + return 1 + fi + for _cand in "${_cands[@]}"; do + echo "[*] Found $(basename "$_cand"); extracting..." + find "$_stage" -mindepth 1 -delete 2>/dev/null || true + # unsquashfs preserves ownership, modes and symlinks better than a + # generic archive unpacker. Fall back to 7z when it is missing or + # when the candidate is an ext4 image rather than squashfs. + if command -v unsquashfs >/dev/null 2>&1 && \ + unsquashfs -f -d "$_stage" "$_cand" >"$_log" 2>&1; then + : + else + find "$_stage" -mindepth 1 -delete 2>/dev/null || true + if ! 7z x -y -o"$_stage" "$_cand" >"$_log" 2>&1; then + echo "[!] Could not unpack $(basename "$_cand")." + continue + fi + fi + lfa_custom_flatten "$_stage" || true + if ! lfa_custom_has_sh "$_stage"; then + # Fedora LiveOS keeps an ext4 root inside squashfs.img. + local _nested _nested_dir + _nested="$(find "$_stage" -maxdepth 2 -type f \( -name '*.img' -o -name '*.ext4' \) 2>/dev/null | head -n1)" + if [ -n "$_nested" ]; then + echo "[*] Unpacking the nested $(basename "$_nested")..." + _nested_dir="$(mktemp -d "$PREFIX/tmp/lfa-custom-root2.XXXXXX")" || continue + lfa_track_tmpdir "$_nested_dir" + if 7z x -y -o"$_nested_dir" "$_nested" >"$_log" 2>&1; then + lfa_custom_flatten "$_nested_dir" || true + if lfa_custom_has_sh "$_nested_dir"; then + find "$_stage" -mindepth 1 -delete 2>/dev/null || true + cp -a "$_nested_dir/." "$_stage/" || true + fi + fi + rm -rf "$_nested_dir" + fi + fi + if lfa_custom_has_sh "$_stage"; then + cp -a "$_stage/." "$_dst/" || { + echo "[!] Could not copy the extracted root filesystem." + rm -rf "$_work" "$_stage" + return 1 + } + _found=1 + break + fi + done + rm -rf "$_work" "$_stage" + if [ "$_found" != "1" ]; then + echo "[!] This image does not contain a usable root filesystem." + echo " Installer-only ISOs need a kernel and loop devices, which proot" + echo " does not provide. Use the distro's rootfs/cloud image instead." + return 1 + fi + return 0 +} + +lfa_custom_prepare() { # $1 = source, $2 = target rootfs + local _src _dst _type + _src="$(lfa_custom_expand_path "${1:-}")" + _dst="${2:-}" + [ -n "$_dst" ] || return 1 + LFA_CUSTOM_SOURCE="$_src" + LFA_CUSTOM_FAMILY="unknown" + LFA_CUSTOM_ID="" + LFA_CUSTOM_NAME="" + LFA_CUSTOM_ARCH="" + if [ ! -e "$_src" ]; then + echo "[!] Not found: $_src" + return 1 + fi + if [ ! -r "$_src" ]; then + echo "[!] Cannot read: $_src" + return 1 + fi + _type="$(lfa_custom_type "$_src")" + if [ "$_type" = "unknown" ] && [ -f "$_src" ] && lfa_custom_is_oci "$_src"; then + echo "[!] This is an OCI/Docker archive, which needs proot-distro v5:" + echo " proot-distro install --name NAME \"$_src\"" + echo " Or export a plain rootfs tarball: docker export NAME -o rootfs.tar" + return 1 + fi + case "$_type" in + dir) + echo "[*] Copying the root filesystem from $_src..." + cp -a "$_src/." "$_dst/" || { + echo "[!] Could not copy this directory." + return 1 + } + ;; + tar) + echo "[*] Extracting $(basename "$_src")..." + if ! lfa_custom_extract_tar "$_src" "$_dst"; then + echo "[!] Could not extract this archive." + echo " Supported: .tar, .tar.gz, .tar.xz, .tar.bz2, .tar.zst" + return 1 + fi + lfa_custom_flatten "$_dst" || true + ;; + image) + lfa_custom_extract_image "$_src" "$_dst" || return 1 + ;; + *) + echo "[!] Unsupported source: $_src" + echo " Use a rootfs directory, a rootfs tarball, or a live ISO." + return 1 + ;; + esac + if ! lfa_custom_has_sh "$_dst"; then + echo "[!] The extracted tree has no /bin/sh, so it is not a root filesystem." + echo " For an ISO, LFA needs the live squashfs, not just the boot files." + return 1 + fi + lfa_custom_check_arch "$_dst" || return 1 + # Read os-release in this shell: a command substitution would run + # lfa_custom_family in a subshell and throw away the ID/NAME it sets. + lfa_custom_read_osrelease "$_dst" + LFA_CUSTOM_FAMILY="$(lfa_custom_family "$_dst")" + [ -n "$LFA_CUSTOM_ID" ] || LFA_CUSTOM_ID="custom" + [ -n "$LFA_CUSTOM_NAME" ] || LFA_CUSTOM_NAME="Custom Linux ($LFA_CUSTOM_FAMILY)" + echo "[*] Detected: $LFA_CUSTOM_NAME (${LFA_CUSTOM_FAMILY}, ${LFA_CUSTOM_ARCH:-unknown})" + return 0 +} + +lfa_custom_stage_source() { + # Extract the chosen userland into a private staging directory. The + # guided setup calls this before the desktop/software menus so the + # package family is known; install_linux reuses the same tree instead + # of unpacking a second time. The EXIT trap removes a stage that never + # reaches an installed instance. + [ -n "${LFA_CUSTOM_SOURCE:-}" ] || return 1 + LFA_CUSTOM_STAGE="$PREFIX/var/lib/proot-distro/.lfa-custom-$$" + rm -rf "$LFA_CUSTOM_STAGE" + if ! mkdir -p "$LFA_CUSTOM_STAGE"; then + echo "[!] Could not create the staging directory." + LFA_CUSTOM_STAGE="" + return 1 + fi + if ! lfa_custom_prepare "$LFA_CUSTOM_SOURCE" "$LFA_CUSTOM_STAGE"; then + rm -rf "$LFA_CUSTOM_STAGE" + LFA_CUSTOM_STAGE="" + return 1 + fi + LFA_CUSTOM=1 + return 0 +} + select_installed_instance() { INSTANCE_NAME="" if [ -n "$CLI_INSTANCE" ]; then @@ -7884,6 +8620,75 @@ lfa_instance_session_running() { # $1 = instance done return 1 } + +# Storage policy for a guest session. Both categories default to on, which +# keeps proot-distro's normal /storage and /sdcard binds. When either one is +# disabled the session becomes --isolated and LFA adds only the binds the +# user kept, so the disabled category cannot leak through /storage. +lfa_storage_args() { # $1 = instance; prints proot-distro login arguments + local _inst="${1:-}" _conf="" _root="" _android=1 _external=1 + local _shared="" _vol _id _spec _guest _ifs + if declare -F pd_conf >/dev/null 2>&1; then + _conf="$(pd_conf "$_inst" 2>/dev/null || true)" + _root="$(pd_rootfs "$_inst" 2>/dev/null || true)" + else + _conf="$(lfa_conf "$_inst" 2>/dev/null || true)" + _root="$(lfa_rootfs "$_inst" 2>/dev/null || true)" + fi + if [ -f "$_conf" ]; then + # shellcheck disable=SC1090 + _android="$( . "$_conf" 2>/dev/null; printf '%s' "${STORAGE_ANDROID:-1}" )" + # shellcheck disable=SC1090 + _external="$( . "$_conf" 2>/dev/null; printf '%s' "${STORAGE_EXTERNAL:-1}" )" + fi + case "$_android" in 0|no|off|false|disabled) _android=0 ;; *) _android=1 ;; esac + case "$_external" in 0|no|off|false|disabled) _external=0 ;; *) _external=1 ;; esac + + _lfa_storage_emit() { # $1 = host:guest + _guest="${1##*:}" + [ -n "$_root" ] && mkdir -p "$_root$_guest" 2>/dev/null || true + printf '%s\n' "--bind" "$1" + } + + if [ "$_android" = "1" ] && [ "$_external" = "1" ]; then + if [ -n "${LFA_STORAGE_BIND:-}" ]; then + _ifs="$IFS"; IFS=';' + for _spec in $LFA_STORAGE_BIND; do + [ -n "$_spec" ] && _lfa_storage_emit "$_spec" + done + IFS="$_ifs" + fi + return 0 + fi + + printf '%s\n' "--isolated" + if [ "$_android" = "1" ]; then + for _shared in /storage/self/primary /storage/emulated/0 /sdcard; do + [ -d "$_shared" ] && break + _shared="" + done + if [ -n "$_shared" ]; then + _lfa_storage_emit "$_shared:/sdcard" + _lfa_storage_emit "$_shared:/storage/emulated/0" + fi + fi + if [ "$_external" = "1" ]; then + if [ -n "${LFA_STORAGE_BIND:-}" ]; then + _ifs="$IFS"; IFS=';' + for _spec in $LFA_STORAGE_BIND; do + [ -n "$_spec" ] && _lfa_storage_emit "$_spec" + done + IFS="$_ifs" + else + for _vol in /storage/*; do + _id="${_vol##*/}" + case "$_id" in emulated|self|sdcard0) continue ;; esac + [ -d "$_vol" ] || continue + _lfa_storage_emit "$_vol:/media/$_id" + done + fi + fi +} EOF chmod +x "$PREFIX/bin/lfa-lib.sh" echo "[*] Generating Universal Quick-Launch Scripts..." @@ -8042,10 +8847,11 @@ if [ -n "${LFA_USB_DEVBIND:-}" ]; then for _ub in $LFA_USB_DEVBIND; do [ -n "$_ub" ] && USB_BIND+=(--bind "$_ub"); done IFS="$_ub_ifs"; unset _ub_ifs _ub fi -if [ -n "${LFA_STORAGE_BIND:-}" ]; then - _st_ifs="$IFS"; IFS=';' - for _st in $LFA_STORAGE_BIND; do [ -n "$_st" ] && USB_BIND+=(--bind "$_st"); done - IFS="$_st_ifs"; unset _st_ifs _st +if declare -F lfa_storage_args >/dev/null 2>&1; then + _storage_args=() + mapfile -t _storage_args < <(lfa_storage_args "$DISTRO") + [ "${#_storage_args[@]}" -gt 0 ] && USB_BIND+=("${_storage_args[@]}") + unset _storage_args fi USB_WRAP="" if [ -n "${LFA_USB_PRELOAD:-}" ] && [ -n "${LFA_USB_MAP:-}" ]; then @@ -8053,17 +8859,6 @@ if [ -n "${LFA_USB_PRELOAD:-}" ] && [ -n "${LFA_USB_MAP:-}" ]; then fi pd_login() { - if [ -n "${LFA_STORAGE_BIND:-}" ]; then - _st_rfs="$(lfa_rootfs "$DISTRO" 2>/dev/null || true)" - if [ -n "$_st_rfs" ]; then - _st_ifs="$IFS"; IFS=';' - for _st in $LFA_STORAGE_BIND; do - [ -n "$_st" ] && mkdir -p "$_st_rfs${_st##*:}" 2>/dev/null || true - done - IFS="$_st_ifs"; unset _st_ifs _st - fi - unset _st_rfs - fi proot-distro login "${USB_BIND[@]}" "$@" } @@ -8548,11 +9343,6 @@ if [ -n "${LFA_USB_DEVBIND:-}" ]; then for _ub in $LFA_USB_DEVBIND; do [ -n "$_ub" ] && USB_BIND+=(--bind "$_ub"); done IFS="$_ub_ifs"; unset _ub_ifs _ub fi -if [ -n "${LFA_STORAGE_BIND:-}" ]; then - _st_ifs="$IFS"; IFS=';' - for _st in $LFA_STORAGE_BIND; do [ -n "$_st" ] && USB_BIND+=(--bind "$_st"); done - IFS="$_st_ifs"; unset _st_ifs _st -fi USB_WRAP="" if [ -n "${LFA_USB_PRELOAD:-}" ] && [ -n "${LFA_USB_MAP:-}" ]; then USB_WRAP="export LD_PRELOAD=$LFA_USB_PRELOAD; export LFA_USB_MAP=$LFA_USB_MAP; " @@ -8637,16 +9427,11 @@ else echo "2) User terminal ('$TERM_USER' account)" read -p "Select [1-2, default 1]: " TERM_CHOICE fi -if [ -n "${LFA_STORAGE_BIND:-}" ]; then - _st_rfs="$(lfa_rootfs "$DISTRO" 2>/dev/null || true)" - if [ -n "$_st_rfs" ]; then - _st_ifs="$IFS"; IFS=';' - for _st in $LFA_STORAGE_BIND; do - [ -n "$_st" ] && mkdir -p "$_st_rfs${_st##*:}" 2>/dev/null || true - done - IFS="$_st_ifs"; unset _st_ifs _st - fi - unset _st_rfs +if declare -F lfa_storage_args >/dev/null 2>&1; then + _storage_args=() + mapfile -t _storage_args < <(lfa_storage_args "$DISTRO") + [ "${#_storage_args[@]}" -gt 0 ] && USB_BIND+=("${_storage_args[@]}") + unset _storage_args fi if [ "$TERM_CHOICE" == "2" ]; then if [ -n "$USB_WRAP" ]; then @@ -8813,6 +9598,37 @@ install_linux() { return fi fi + # Custom userland: unpack it now so the family is known before the + # desktop and software menus. The final instance name is asked later, + # so the tree waits in a staging directory until then. + if [ "${LFA_CUSTOM:-0}" = "1" ] || [ "$DISTRO" = "custom" ]; then + LFA_CUSTOM=1 + if [ -z "${LFA_CUSTOM_SOURCE:-}" ]; then + if ! lfa_custom_ask_source; then + show_menu + return + fi + fi + # Guided setup already unpacked the tree to learn the family. The + # CLI and classic menu arrive here with no stage and unpack now. + if [ -z "${LFA_CUSTOM_STAGE:-}" ]; then + if ! lfa_custom_stage_source; then + ui_pause + show_menu + return 1 + fi + fi + DISTRO="$LFA_CUSTOM_FAMILY" + if [ "$DISTRO" = "unknown" ]; then + LFA_CUSTOM_UNKNOWN=1 + DISTRO="custom" + DE="none"; SERVER="none"; AUTOSTART_SERVER="none" + echo "" + echo "[!] LFA does not know this userland's package manager." + echo " It installs as a terminal-only system. Add a desktop inside" + echo " the guest with its own package manager if you want one." + fi + fi # 32-bit ARM warning (Oppo A37fw and similar): some images lack armv7 builds if [ "$IS_32BIT_ARM" = "1" ]; then case "$DISTRO" in @@ -8827,7 +9643,13 @@ install_linux() { # first guest command (verified live). Debian auto-switches to the # bullseye plug-in (glibc 2.31, verified); Alpine (musl) is proven OK. PD_ALIAS="$DISTRO" - if [ "$IS_LEGACY" = "1" ]; then + if [ "${LFA_CUSTOM:-0}" = "1" ]; then + PD_ALIAS="" + if [ "$IS_LEGACY" = "1" ]; then + echo "[!] Android 5/6 runs a 3.10 kernel; modern glibc userlands fail." + echo " A musl rootfs (Alpine) is the safe choice on this device." + fi + elif [ "$IS_LEGACY" = "1" ]; then case "$DISTRO" in alpine) ;; debian) @@ -8856,7 +9678,7 @@ install_linux() { esac fi - if [ "$SETUP_ANSWERED" != "1" ]; then + if [ "$SETUP_ANSWERED" != "1" ] && [ "${LFA_CUSTOM_UNKNOWN:-0}" != "1" ]; then DE="none" SERVER="none" AUTOSTART_SERVER="" @@ -8923,7 +9745,7 @@ install_linux() { fi # SOFTWARE SELECTOR - if [ "$SETUP_ANSWERED" != "1" ]; then + if [ "$SETUP_ANSWERED" != "1" ] && [ "${LFA_CUSTOM_UNKNOWN:-0}" != "1" ]; then if ! ui_multi "Software Selector (optional)" \ "1|Python|python3 + pip" \ "2|Git|version control" \ @@ -8968,18 +9790,47 @@ install_linux() { 14) INSTALL_VSCODE=1 ;; esac done + if [ "${LFA_CUSTOM_UNKNOWN:-0}" = "1" ]; then + INSTALL_PYTHON=0; INSTALL_GIT=0; INSTALL_NODEJS=0; INSTALL_CURL=0 + INSTALL_WGET=0; INSTALL_IDE=0; INSTALL_FIREFOX=0; INSTALL_CHROMIUM=0 + INSTALL_LIBREOFFICE=0; INSTALL_VLC=0; INSTALL_GIMP=0 + INSTALL_HTOP=0; INSTALL_NEOFETCH=0; INSTALL_VSCODE=0 + APP_CHOICES="" + fi echo "" if [ "$SETUP_ANSWERED" != "1" ]; then read -p "Enter a custom name for this installation (Leave blank for auto-generation): " INSTANCE_NAME fi if [ -z "$INSTANCE_NAME" ]; then - if pd_instance_exists "$DISTRO" || [ -f "$PREFIX/etc/proot-distro/$DISTRO.sh" ]; then + if [ "${LFA_CUSTOM:-0}" = "1" ]; then + INSTANCE_NAME="$(lfa_custom_default_name)" + elif pd_instance_exists "$DISTRO" || [ -f "$PREFIX/etc/proot-distro/$DISTRO.sh" ]; then INSTANCE_NAME="${DISTRO}-$(date +%M%S)" else INSTANCE_NAME="$DISTRO" fi fi + if [ "${LFA_CUSTOM:-0}" = "1" ] && [ -n "${LFA_CUSTOM_STAGE:-}" ]; then + local _custom_final + _custom_final="$(lfa_custom_rootfs_new "$INSTANCE_NAME")" + if pd_instance_exists "$INSTANCE_NAME"; then + echo "[!] '$INSTANCE_NAME' already exists; using a timestamped name." + INSTANCE_NAME="${INSTANCE_NAME}-$(date +%M%S)" + _custom_final="$(lfa_custom_rootfs_new "$INSTANCE_NAME")" + fi + mkdir -p "$(dirname "$_custom_final")" + if ! mv "$LFA_CUSTOM_STAGE" "$_custom_final"; then + echo "[!] Could not move the userland into place." + rm -rf "$LFA_CUSTOM_STAGE" + LFA_CUSTOM_STAGE="" + ui_pause + show_menu + return 1 + fi + LFA_CUSTOM_STAGE="" + echo "[*] Userland ready as '$INSTANCE_NAME'." + fi echo "" echo "=========================================" @@ -9017,6 +9868,9 @@ install_linux() { return fi + if [ "${LFA_CUSTOM:-0}" = "1" ]; then + echo "[*] Using the extracted custom userland (as $INSTANCE_NAME)..." + else echo "[*] Installing $DISTRO (as $INSTANCE_NAME)..." verify_proot_distro_plugin "$PD_ALIAS" || { ui_pause @@ -9049,6 +9903,7 @@ install_linux() { else proot-distro install --override-alias "$INSTANCE_NAME" "$PD_ALIAS" 2>/dev/null || proot-distro install "$PD_ALIAS" fi + fi ROOTFS="$(pd_rootfs "$INSTANCE_NAME")" mkdir -p "$PREFIX/tmp" @@ -9242,6 +10097,13 @@ install_linux() { if [ "$INSTALL_NEOFETCH" == "1" ]; then SELECTED_PKGS="$SELECTED_PKGS fastfetch"; fi if [ "$INSTALL_VSCODE" == "1" ]; then echo "[!] VS Code has no Alpine build, skipping."; fi ;; + *) + # Custom userland whose package manager LFA does not know. + UPDATE_CMD="true" + INSTALL_CMD="true" + XFCE_PKG=""; LXDE_PKG=""; MATE_PKG=""; GNOME_PKG="" + VNC_PKG=""; LOADER_PKG=""; SUDO_PKG=""; SELECTED_PKGS="" + ;; esac # Save the configuration for dynamic boot! @@ -9268,6 +10130,8 @@ install_linux() { echo "AUTOSTART_SERVER=\"$AUTOSTART_SERVER\"" >> "$ROOTFS/etc/termux-linux-manager.conf" echo "DO_AUTOSTART=\"${DO_AUTOSTART:-0}\"" >> "$ROOTFS/etc/termux-linux-manager.conf" echo "DO_SSH=\"${DO_SSH:-0}\"" >> "$ROOTFS/etc/termux-linux-manager.conf" + echo "STORAGE_ANDROID=\"${STORAGE_ANDROID:-1}\"" >> "$ROOTFS/etc/termux-linux-manager.conf" + echo "STORAGE_EXTERNAL=\"${STORAGE_EXTERNAL:-1}\"" >> "$ROOTFS/etc/termux-linux-manager.conf" if [ "$SERVER" = "both" ]; then rm -f "$HOME/.config/linux-for-android/last-server-$INSTANCE_NAME" 2>/dev/null || true fi @@ -9279,12 +10143,21 @@ install_linux() { echo "HOSTNAME=\"${HOSTNAME:-localhost}\"" >> "$ROOTFS/etc/termux-linux-manager.conf" echo "NEED_VIRGL=\"${NEED_VIRGL:-1}\"" >> "$ROOTFS/etc/termux-linux-manager.conf" echo "PSTYLE=\"${PSTYLE:-minimal}\"" >> "$ROOTFS/etc/termux-linux-manager.conf" + if [ "${LFA_CUSTOM:-0}" = "1" ]; then + echo "CUSTOM_SOURCE=\"$(lfa_custom_conf_escape "${LFA_CUSTOM_SOURCE:-}")\"" >> "$ROOTFS/etc/termux-linux-manager.conf" + echo "CUSTOM_NAME=\"$(lfa_custom_conf_escape "${LFA_CUSTOM_NAME:-}")\"" >> "$ROOTFS/etc/termux-linux-manager.conf" + echo "CUSTOM_ID=\"$(lfa_custom_conf_escape "${LFA_CUSTOM_ID:-}")\"" >> "$ROOTFS/etc/termux-linux-manager.conf" + fi if [ -n "${IMAGE:-}" ]; then echo "IMAGE=\"$IMAGE\"" >> "$ROOTFS/etc/termux-linux-manager.conf" fi # (Removed broken universal wallpaper download) + if [ "${LFA_CUSTOM_UNKNOWN:-0}" = "1" ]; then + echo "[*] Skipping guest setup: no known package manager." + echo " Open a root shell with: lfa shell -i $INSTANCE_NAME --root" + else cat << EOF > "$SETUP_SCRIPT" #!/bin/bash export DEBIAN_FRONTEND=noninteractive @@ -9923,6 +10796,7 @@ EOF ui_pause return 1 fi + fi echo "[*] Setting up Home-Screen Widget Integration..." mkdir -p ~/.shortcuts diff --git a/tests/test-all.sh b/tests/test-all.sh index 81ee90b..8b18b6f 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -219,7 +219,7 @@ check "B install done" 'Installation complete!' "$T/b.log" echo "===== C: guided debian CLI, custom user, validation loops =====" fresh_env -printf '%s\n' 2 9 2 4 99 'x y' '' '' 'Bad Name!' 'dev' '' 's3cret' '' 'oppo-test' 5 2 'y' '' 'n' 'n' '' '' '13' \ +printf '%s\n' 2 10 2 4 99 'x y' '' '' 'Bad Name!' 'dev' '' 's3cret' '' 'oppo-test' 5 2 'y' '' 'n' 'n' '' '' '13' \ | bash "$REPO/install_linux.sh" > "$T/c.log" 2>&1; rc=$?; [ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: run c exit $rc"; } S=$(setup_sh_of) check "C user" 'useradd -m -s /bin/bash dev' "$S" @@ -282,7 +282,7 @@ check "D wallpaper autostart" 'Exec=/usr/local/bin/lfa-set-wallpaper --autostart echo "===== D5: both backends (X11 + VNC) =====" fresh_env -printf '%s\n' 2 1 1 1 3 1 1 '' '' '' '' '' UTC '' 1 n n n n y 13 \ +printf '%s\n' 2 1 1 1 3 1 1 '' '' '' '' '' UTC '' 1 n 4 n n y 13 \ | bash "$REPO/install_linux.sh" > "$T/d5.log" 2>&1; rc=$?; [ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: run d5 exit $rc"; } S=$(setup_sh_of) check "D5 both saved" 'SERVER="both"' "$T/home/.config/linux-for-android/setup.conf" @@ -306,7 +306,7 @@ check "D5 no default on first both start" 'Invalid selection.' "$T/d5nodefault.l echo "===== D6: both backends with X11 autostart =====" fresh_env -printf '%s\n' 2 1 1 1 3 1 1 '' '' '' '' '' UTC '' 1 y 2 n n n y 13 \ +printf '%s\n' 2 1 1 1 3 1 1 '' '' '' '' '' UTC '' 1 y 2 4 n n y 13 \ | bash "$REPO/install_linux.sh" > "$T/d6.log" 2>&1; rc=$?; [ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: run d6 exit $rc"; } check "D6 autostart x11 saved" 'AUTOSTART_SERVER="x11"' "$T/home/.config/linux-for-android/setup.conf" check "D6 boot starts launcher" 'start-linux" --instance "ubuntu" --server "x11"' "$T/home/.termux/boot/start-linux-services.sh" @@ -314,7 +314,7 @@ bash -n "$T/home/.termux/boot/start-linux-services.sh" && pass=$((pass+1)) || { echo "===== D7: GNOME with both backends keeps the warning =====" fresh_env -printf '%s\n' 2 1 5 y 1 3 1 1 '' '' '' '' '' UTC '' 1 n n n n y 13 \ +printf '%s\n' 2 1 5 y 1 3 1 1 '' '' '' '' '' UTC '' 1 n 4 n n y 13 \ | bash "$REPO/install_linux.sh" > "$T/d7.log" 2>&1; rc=$?; [ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: run d7 exit $rc"; } check "D7 both saved" 'SERVER="both"' "$T/home/.config/linux-for-android/setup.conf" check "D7 gnome both warning" 'Both keeps VNC available too' "$T/d7.log" @@ -1011,7 +1011,7 @@ check "Q clean bye" 'Bye.' "$T/q.log" echo "===== R: proot-distro v5 image mode =====" fresh_env export PD_V5=1 -printf '%s\n' 2 8 4 '' v5alpine '' '' '' '' '' 1 n '' n n '' '' 13 \ +printf '%s\n' 2 8 4 '' v5alpine '' '' '' '' '' 1 n 4 n n '' '' 13 \ | bash "$REPO/install_linux.sh" > "$T/r.log" 2>&1; rc=$?; [ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: run r exit $rc"; } check_absent "R no plugin rejection" "knows no 'alpine'" "$T/r.log" check "R image install" 'STUB-PD-INSTALL-OK: install --name v5alpine alpine:latest' "$T/r.log" @@ -1029,7 +1029,7 @@ unset PD_V5 echo "===== S: software menu, pip/npm, browsers, Antigravity =====" fresh_env -printf '%s\n' 2 1 4 '1 2 3 6 7 8 9 10 11 12 13 14' softinst suser '' '' UTC softinst 1 n '' n n '' '' 13 \ +printf '%s\n' 2 1 4 '1 2 3 6 7 8 9 10 11 12 13 14' softinst suser '' '' UTC softinst 1 n 4 n n '' '' 13 \ | bash "$REPO/install_linux.sh" > "$T/s.log" 2>&1; rc=$?; [ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: run s exit $rc"; } S=$(setup_sh_of) check "S python pip" 'python3 python3-pip' "$S" @@ -1045,7 +1045,7 @@ check_absent "S antigravity placeholder" 'Terminal Edition' "$S" # On Debian/Kali, Firefox must use firefox-esr (no `firefox` package). fresh_env -printf '%s\n' 2 2 4 '7 8' debsoft '' '' '' UTC debsoft 1 n '' n n '' '' 13 \ +printf '%s\n' 2 2 4 '7 8' debsoft '' '' '' UTC debsoft 1 n 4 n n '' '' 13 \ | bash "$REPO/install_linux.sh" > "$T/s2.log" 2>&1; rc=$?; [ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: run s2 exit $rc"; } S=$(setup_sh_of) check "S debian firefox-esr" 'firefox-esr' "$S" @@ -1053,7 +1053,7 @@ check "S debian firefox-esr" 'firefox-esr' "$S" echo "===== T: Void bootstrap via proot-distro run =====" fresh_env export PD_V5=1 -printf '%s\n' 2 6 4 '' voidinst vuser '' '' UTC voidinst 1 n '' n n '' '' 13 \ +printf '%s\n' 2 6 4 '' voidinst vuser '' '' UTC voidinst 1 n 4 n n '' '' 13 \ | bash "$REPO/install_linux.sh" > "$T/t.log" 2>&1; rc=$?; [ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: run t exit $rc"; } check "T void bootstrap message" 'Bootstrapping Void base tools' "$T/t.log" check "T void uses run" 'STUB-PD-run-OK: run' "$T/t.log" @@ -1066,7 +1066,7 @@ check "U drops termux" '/data/data/*' "$T/prefix/tmp/lfa-real-feel.sh" echo "===== V: VNC correctness (TigerVNC 1.15, keepalive) =====" fresh_env export PD_V5=1 -printf '%s\n' 2 2 2 2 2 2 1 '' vnctest vncuser 123 123 UTC vnctest 1 n '' n n '' '' 13 \ +printf '%s\n' 2 2 2 2 2 2 1 '' vnctest vncuser 123 123 UTC vnctest 1 n 4 n n '' '' 13 \ | bash "$REPO/install_linux.sh" > "$T/v.log" 2>&1; rc=$?; [ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: run v exit $rc"; } VS=$(setup_sh_of) check "V both config dirs" 'mkdir -p /home/vncuser/.vnc /home/vncuser/.config/tigervnc' "$VS" @@ -1098,7 +1098,7 @@ check "V lxde wallpaper" 'wallpaper=/usr/share/backgrounds/lfa-default.jpg' "$VR echo "===== W: Alpine fastfetch/neofetch alias =====" fresh_env export PD_V5=1 -printf '%s\n' 2 8 4 '13' alpineapp auser '' '' UTC alpineapp 1 n '' n n '' '' 13 \ +printf '%s\n' 2 8 4 '13' alpineapp auser '' '' UTC alpineapp 1 n 4 n n '' '' 13 \ | bash "$REPO/install_linux.sh" > "$T/w.log" 2>&1; rc=$?; [ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: run w exit $rc"; } WA=$(setup_sh_of) check "W alpine fastfetch" 'fastfetch' "$WA" @@ -2106,8 +2106,8 @@ check "Y11 storage bind media" "$T/storage/CABC-1701:/media/CABC-1701" "$T/y11-s check "Y11 storage bind alias" "$T/storage/CABC-1701:/mnt/card" "$T/y11-storage-bind.log" check_absent "Y11 storage no internal bind" "$T/storage/emulated/0:/sdcard" "$T/y11-storage-bind.log" check_absent "Y11 storage no sdcard collision" ":/mnt/sdcard" "$T/y11-storage-bind.log" -check "Y11 storage launcher binds" 'LFA_STORAGE_BIND' "$T/prefix/bin/terminal-linux" -check "Y11 storage desktop binds" 'LFA_STORAGE_BIND' "$T/prefix/bin/start-linux" +check "Y11 storage launcher binds" 'lfa_storage_args' "$T/prefix/bin/terminal-linux" +check "Y11 storage desktop binds" 'lfa_storage_args' "$T/prefix/bin/start-linux" [ -d "$UROOT/mnt/card" ] && pass=$((pass+1)) \ || { fail=$((fail+1)); echo "FAIL: Y11 storage did not create /mnt/card"; } [ -d "$UROOT/media/CABC-1701" ] && pass=$((pass+1)) \ @@ -2252,6 +2252,233 @@ check "Y11b README command" 'lfa usb' "$REPO/README.md" check "Y11b docs index" 'USB.md' "$REPO/docs/README.md" check "Y11b incompatible points to guide" 'USB.md' "$REPO/docs/INCOMPATIBLE.md" +echo "===== Y12: custom rootfs tarball (known family) =====" +fresh_env +mkdir -p "$T/custom-deb/bin" "$T/custom-deb/etc" +printf '#!/bin/sh\n' > "$T/custom-deb/bin/sh" +chmod +x "$T/custom-deb/bin/sh" +printf 'ID=debian\nPRETTY_NAME="Test Debian"\n' > "$T/custom-deb/etc/os-release" +tar -czf "$T/custom-deb.tar.gz" -C "$T/custom-deb" . +timeout 90 bash "$REPO/install_linux.sh" --cli install \ + --rootfs "$T/custom-deb.tar.gz" -i customdeb --desktop none --user user \ + > "$T/y12.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y12 custom rootfs exit $rc"; } +check "Y12 completes" 'Installation complete!' "$T/y12.log" +check "Y12 detected name" 'Test Debian' "$T/y12.log" +CROOT="$T/prefix/var/lib/proot-distro/containers/customdeb/rootfs" +[ -d "$CROOT" ] || CROOT="$T/prefix/var/lib/proot-distro/installed-rootfs/customdeb" +[ -x "$CROOT/bin/sh" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y12 rootfs not extracted"; } +check "Y12 conf family" 'DISTRO="debian"' "$CROOT/etc/termux-linux-manager.conf" +check "Y12 conf name" 'CUSTOM_NAME="Test Debian"' "$CROOT/etc/termux-linux-manager.conf" +check "Y12 conf id" 'CUSTOM_ID="debian"' "$CROOT/etc/termux-linux-manager.conf" +check "Y12 conf source" 'CUSTOM_SOURCE="' "$CROOT/etc/termux-linux-manager.conf" +check_absent "Y12 no proot-distro install" 'install' "$T/home/pd-calls.log" +check "Y12 guest setup" 'apt-get install' "$(setup_sh_of)" + +echo "===== Y12b: custom rootfs, unknown package manager =====" +fresh_env +mkdir -p "$T/custom-unk/bin" "$T/custom-unk/etc" +printf '#!/bin/sh\n' > "$T/custom-unk/bin/sh" +chmod +x "$T/custom-unk/bin/sh" +printf 'ID=customos\nPRETTY_NAME="Test Custom"\n' > "$T/custom-unk/etc/os-release" +tar -czf "$T/custom-unk.tar.gz" -C "$T/custom-unk" . +timeout 90 bash "$REPO/install_linux.sh" --cli install \ + --rootfs "$T/custom-unk.tar.gz" -i customunk --desktop none --user user \ + > "$T/y12b.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y12b unknown rootfs exit $rc"; } +check "Y12b unknown notice" 'does not know this userland' "$T/y12b.log" +check "Y12b skipped setup" 'Skipping guest setup' "$T/y12b.log" +check "Y12b shell hint" 'lfa shell -i customunk --root' "$T/y12b.log" +CROOT="$T/prefix/var/lib/proot-distro/containers/customunk/rootfs" +[ -d "$CROOT" ] || CROOT="$T/prefix/var/lib/proot-distro/installed-rootfs/customunk" +check "Y12b conf family" 'DISTRO="custom"' "$CROOT/etc/termux-linux-manager.conf" +check "Y12b conf id" 'CUSTOM_ID="customos"' "$CROOT/etc/termux-linux-manager.conf" +check "Y12b conf name" 'CUSTOM_NAME="Test Custom"' "$CROOT/etc/termux-linux-manager.conf" +YS=$(setup_sh_of) +if [ -z "$YS" ] || [ ! -s "$YS" ]; then pass=$((pass+1)); else fail=$((fail+1)); echo "FAIL: Y12b generated a guest setup script"; fi + +echo "===== Y12c: custom live ISO (squashfs extraction) =====" +fresh_env +mkdir -p "$T/iso-root/bin" "$T/iso-root/etc" +printf '#!/bin/sh\n' > "$T/iso-root/bin/sh" +chmod +x "$T/iso-root/bin/sh" +printf 'ID=alpine\nPRETTY_NAME="Test Alpine"\n' > "$T/iso-root/etc/os-release" +: > "$T/fake.iso" +cat > "$T/fakebin/7z" < "\$out/live/filesystem.squashfs" ;; + *.squashfs) cp -a "$T/iso-root/." "\$out/" ;; + *) exit 1 ;; +esac +EOF +chmod +x "$T/fakebin/7z" +timeout 90 bash "$REPO/install_linux.sh" --cli install \ + --iso "$T/fake.iso" -i customiso --desktop none --user user \ + > "$T/y12c.log" 2>&1; rc=$? +rm -f "$T/fakebin/7z" +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y12c custom ISO exit $rc"; } +check "Y12c unpacks image" 'Unpacking fake.iso' "$T/y12c.log" +check "Y12c finds squashfs" 'Found filesystem.squashfs' "$T/y12c.log" +check "Y12c detected name" 'Test Alpine' "$T/y12c.log" +CROOT="$T/prefix/var/lib/proot-distro/containers/customiso/rootfs" +[ -d "$CROOT" ] || CROOT="$T/prefix/var/lib/proot-distro/installed-rootfs/customiso" +check "Y12c conf family" 'DISTRO="alpine"' "$CROOT/etc/termux-linux-manager.conf" + +echo "===== Y12d: custom rootfs with the wrong CPU architecture =====" +fresh_env +mkdir -p "$T/custom-bad/bin" "$T/custom-bad/etc" +case "$(uname -m)" in + aarch64|arm64) printf '\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3e\x00' > "$T/custom-bad/bin/sh" ;; + *) printf '\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb7\x00' > "$T/custom-bad/bin/sh" ;; +esac +printf 'ID=debian\nPRETTY_NAME="Wrong Arch"\n' > "$T/custom-bad/etc/os-release" +tar -czf "$T/custom-bad.tar.gz" -C "$T/custom-bad" . +timeout 90 bash "$REPO/install_linux.sh" --cli install \ + --rootfs "$T/custom-bad.tar.gz" -i custombad --desktop none \ + > "$T/y12d.log" 2>&1; rc=$? +[ "$rc" != "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y12d wrong arch was accepted"; } +check "Y12d refuses" 'proot does not emulate another CPU' "$T/y12d.log" +[ ! -e "$T/prefix/var/lib/proot-distro/containers/custombad" ] && \ +[ ! -e "$T/prefix/var/lib/proot-distro/installed-rootfs/custombad" ] && \ +pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y12d left a partial rootfs"; } + +echo "===== Y12e: custom source validation =====" +fresh_env +timeout 30 bash "$REPO/install_linux.sh" --cli install --distro custom -i nosrc \ + > "$T/y12e1.log" 2>&1; rc=$? +[ "$rc" = "2" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y12e missing source exit $rc"; } +check "Y12e missing source hint" 'needs --iso PATH or --rootfs PATH' "$T/y12e1.log" +timeout 30 bash "$REPO/install_linux.sh" --cli install --rootfs "$T/does-not-exist.tar.gz" -i nosrc \ + > "$T/y12e2.log" 2>&1; rc=$? +[ "$rc" != "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y12e bad path was accepted"; } +check "Y12e bad path message" 'Not found' "$T/y12e2.log" + +echo "===== Y12f: guided custom rootfs, unknown family =====" +fresh_env +mkdir -p "$T/guided/bin" "$T/guided/etc" +printf '#!/bin/sh\n' > "$T/guided/bin/sh" +chmod +x "$T/guided/bin/sh" +printf 'ID=customos\nPRETTY_NAME="Guided Custom"\n' > "$T/guided/etc/os-release" +tar -czf "$T/guided.tar.gz" -C "$T/guided" . +printf '%s\n' 2 9 "$T/guided.tar.gz" '' '' '' '' '' '' 1 4 n n y '' 13 13 \ + | timeout 90 bash "$REPO/install_linux.sh" > "$T/y12f.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y12f guided custom exit $rc"; } +check "Y12f summary userland" 'Guided Custom' "$T/y12f.log" +check "Y12f skipped setup" 'Skipping guest setup' "$T/y12f.log" +CROOT="$T/prefix/var/lib/proot-distro/containers/customos/rootfs" +[ -d "$CROOT" ] || CROOT="$T/prefix/var/lib/proot-distro/installed-rootfs/customos" +check "Y12f conf family" 'DISTRO="custom"' "$CROOT/etc/termux-linux-manager.conf" +check "Y12f conf name" 'CUSTOM_NAME="Guided Custom"' "$CROOT/etc/termux-linux-manager.conf" +[ -z "$(find "$T/prefix/var/lib/proot-distro" -maxdepth 1 -name '.lfa-custom-*' 2>/dev/null)" ] \ + && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y12f left a staging directory"; } + +echo "===== Y13: separate Android and external storage policies =====" +fresh_env +mkdir -p "$T/prefix/var/lib/proot-distro/installed-rootfs/stg/etc" "$T/prefix/var/lib/proot-distro/installed-rootfs/stg/var" +SCONF="$T/prefix/var/lib/proot-distro/installed-rootfs/stg/etc/termux-linux-manager.conf" +printf 'DISTRO="debian"\nDE="none"\nSERVER="none"\nSTORAGE_ANDROID="1"\nSTORAGE_EXTERNAL="1"\n' > "$SCONF" +bash "$REPO/install_linux.sh" --cli storage android disable -i stg > "$T/y13a.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13 android disable exit $rc"; } +check "Y13 android disable conf" 'STORAGE_ANDROID="0"' "$SCONF" +check "Y13 android disable notice" 'android storage: off' "$T/y13a.log" +bash "$REPO/install_linux.sh" --cli storage external disable -i stg > "$T/y13b.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13 external disable exit $rc"; } +check "Y13 external disable conf" 'STORAGE_EXTERNAL="0"' "$SCONF" +check "Y13 external disable notice" 'external storage: off' "$T/y13b.log" +bash "$REPO/install_linux.sh" --cli storage android enable -i stg > "$T/y13c.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13 android enable exit $rc"; } +check "Y13 android enable conf" 'STORAGE_ANDROID="1"' "$SCONF" +bash "$REPO/install_linux.sh" --cli storage status -i stg > "$T/y13s.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13 status exit $rc"; } +check "Y13 status android" 'android storage: on' "$T/y13s.log" +check "Y13 status external" 'external storage: off' "$T/y13s.log" + +echo "===== Y13b: guided storage policy menu =====" +fresh_env +printf '%s\n' 2 2 4 '' '' '' '' '' '' '' 1 n 4 n n '' '' 13 \ + | timeout 90 bash "$REPO/install_linux.sh" > "$T/y13g.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13b guided none exit $rc"; } +GCONF="$T/prefix/var/lib/proot-distro/installed-rootfs/debian/etc/termux-linux-manager.conf" +check "Y13b android off" 'STORAGE_ANDROID="0"' "$GCONF" +check "Y13b external off" 'STORAGE_EXTERNAL="0"' "$GCONF" +check "Y13b summary android" 'Android stg' "$T/y13g.log" +check "Y13b summary external" 'External stg' "$T/y13g.log" +check_absent "Y13b no host permission request" 'Requesting Android Storage Permission' "$T/y13g.log" + +echo "===== Y13c: CLI storage flags and login arguments =====" +fresh_env +timeout 90 bash "$REPO/install_linux.sh" --cli install --distro debian \ + --android-storage off --external-storage on -i stgcli --desktop none \ + > "$T/y13cli.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13c CLI storage exit $rc"; } +CCONF="$T/prefix/var/lib/proot-distro/installed-rootfs/stgcli/etc/termux-linux-manager.conf" +check "Y13c CLI android off" 'STORAGE_ANDROID="0"' "$CCONF" +check "Y13c CLI external on" 'STORAGE_EXTERNAL="1"' "$CCONF" +check "Y13c start launcher uses policy" 'lfa_storage_args' "$T/prefix/bin/start-linux" +check "Y13c terminal launcher uses policy" 'lfa_storage_args' "$T/prefix/bin/terminal-linux" +check "Y13c lib knows isolation" '--isolated' "$T/prefix/bin/lfa-lib.sh" +printf '%s\n' "$(LFA_STORAGE_BIND="/tmp/fake:/media/fake" \ + bash -c '. "$1/bin/lfa-lib.sh"; lfa_storage_args "$2"' _ "$T/prefix" stgcli)" \ + > "$T/y13args.log" +check "Y13c external-only isolated" '--isolated' "$T/y13args.log" +check "Y13c external-only bind" '/tmp/fake:/media/fake' "$T/y13args.log" +[ -d "$T/prefix/var/lib/proot-distro/installed-rootfs/stgcli/media/fake" ] \ + && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13c guest mountpoint missing"; } +sed -i 's/^STORAGE_ANDROID=.*/STORAGE_ANDROID="1"/' "$CCONF" +printf '%s\n' "$(LFA_STORAGE_BIND="/tmp/fake:/media/fake" \ + bash -c '. "$1/bin/lfa-lib.sh"; lfa_storage_args "$2"' _ "$T/prefix" stgcli)" \ + > "$T/y13both.log" +check_absent "Y13c both-on keeps defaults" '--isolated' "$T/y13both.log" +check "Y13c both-on keeps card bind" '/tmp/fake:/media/fake' "$T/y13both.log" +timeout 90 bash "$REPO/install_linux.sh" --cli install --distro debian \ + --no-android-storage --no-external-storage -i stgcli2 --desktop none \ + > "$T/y13cli2.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13c CLI none exit $rc"; } +C2CONF="$T/prefix/var/lib/proot-distro/installed-rootfs/stgcli2/etc/termux-linux-manager.conf" +check "Y13c CLI none android" 'STORAGE_ANDROID="0"' "$C2CONF" +check "Y13c CLI none external" 'STORAGE_EXTERNAL="0"' "$C2CONF" +printf '%s\n' "$(bash -c '. "$1/bin/lfa-lib.sh"; lfa_storage_args "$2"' _ "$T/prefix" stgcli2)" \ + > "$T/y13none.log" +check "Y13c none isolated" '--isolated' "$T/y13none.log" +check_absent "Y13c none has no bind" '--bind' "$T/y13none.log" +timeout 30 bash "$REPO/install_linux.sh" --cli install --distro debian \ + --android-storage maybe -i stgbad --desktop none > "$T/y13bad.log" 2>&1; rc=$? +[ "$rc" = "2" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13c invalid storage value exit $rc"; } +check "Y13c invalid storage message" 'use on or off' "$T/y13bad.log" + +echo "===== Y13d: storage policy across all instances =====" +fresh_env +for _inst in alpha beta; do + mkdir -p "$T/prefix/var/lib/proot-distro/installed-rootfs/$_inst/etc" \ + "$T/prefix/var/lib/proot-distro/installed-rootfs/$_inst/var" + printf 'DISTRO="debian"\nDE="none"\nSERVER="none"\nSTORAGE_ANDROID="1"\nSTORAGE_EXTERNAL="1"\n' \ + > "$T/prefix/var/lib/proot-distro/installed-rootfs/$_inst/etc/termux-linux-manager.conf" +done +ACONF="$T/prefix/var/lib/proot-distro/installed-rootfs/alpha/etc/termux-linux-manager.conf" +BCONF="$T/prefix/var/lib/proot-distro/installed-rootfs/beta/etc/termux-linux-manager.conf" +bash "$REPO/install_linux.sh" --cli storage android disable --all > "$T/y13d1.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13d android disable --all exit $rc"; } +check "Y13d android disable alpha" 'STORAGE_ANDROID="0"' "$ACONF" +check "Y13d android disable beta" 'STORAGE_ANDROID="0"' "$BCONF" +check "Y13d android disable notice alpha" 'alpha: android storage: off (new sessions)' "$T/y13d1.log" +check "Y13d android disable notice beta" 'beta: android storage: off (new sessions)' "$T/y13d1.log" +bash "$REPO/install_linux.sh" --cli storage external enable --all > "$T/y13d2.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13d external enable --all exit $rc"; } +check "Y13d external enable alpha" 'STORAGE_EXTERNAL="1"' "$ACONF" +check "Y13d external enable beta" 'STORAGE_EXTERNAL="1"' "$BCONF" +bash "$REPO/install_linux.sh" --cli storage android status --all > "$T/y13d3.log" 2>&1; rc=$? +[ "$rc" = "0" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13d status --all exit $rc"; } +check "Y13d status alpha" 'alpha: android storage: off' "$T/y13d3.log" +check "Y13d status beta" 'beta: android storage: off' "$T/y13d3.log" +bash "$REPO/install_linux.sh" --cli storage android enable --all -i alpha > "$T/y13d4.log" 2>&1; rc=$? +[ "$rc" = "2" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Y13d --all with -i exit $rc"; } +check "Y13d --all with -i refused" 'Use --all or -i NAME' "$T/y13d4.log" + echo "" echo "===== Z: documentation links =====" [ -s "$REPO/docs/TROUBLESHOOTING.md" ] && pass=$((pass+1)) || { fail=$((fail+1)); echo "FAIL: Z troubleshooting guide missing"; }