Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

fix(termux): make partial installs resumable on low memory

Rahman40d5cf9a3434
diff --git a/next.config.mjs b/next.config.mjs
index cddcb5e5..479a9dfb 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -12,6 +12,13 @@ const BUILD_ID =
// running build is current, different means a build is pending and the update panel
// offers the rebuild. Empty is fine and expected — scripts/verify-build.sh compiles
// a `git archive` export with no .git in it.
+const BUILD_CPUS_RAW = Number(process.env.MSO_BUILD_CPUS || "");
+const BUILD_CPUS =
+ Number.isInteger(BUILD_CPUS_RAW) && BUILD_CPUS_RAW > 0
+ ? BUILD_CPUS_RAW
+ : undefined;
+const LOW_MEMORY_BUILD = process.env.MSO_LOW_MEMORY_BUILD === "1";
+
const COMMIT_SHA =
process.env.NEXT_PUBLIC_COMMIT_SHA ||
(() => {
@@ -60,6 +67,21 @@ const nextConfig = {
: {}),
env: { NEXT_PUBLIC_BUILD_ID: BUILD_ID, NEXT_PUBLIC_COMMIT_SHA: COMMIT_SHA },
experimental: {
+ // Constrained Android/PRoot builders can opt into bounded worker fan-out.
+ // Normal VPS/CI builds are unchanged unless these environment variables exist.
+ ...(BUILD_CPUS
+ ? {
+ cpus: BUILD_CPUS,
+ staticGenerationMaxConcurrency: BUILD_CPUS,
+ }
+ : {}),
+ ...(LOW_MEMORY_BUILD
+ ? {
+ parallelServerCompiles: false,
+ parallelServerBuildTraces: false,
+ turbopackMemoryEviction: "auto",
+ }
+ : {}),
// proxy.ts clones request bodies; the default clone cap is 10MB, which
// silently truncated large /api/v1/fs/upload payloads. Raise it so big
// media uploads land intact (proxy* is the Next 16 name of the option).
diff --git a/scripts/install-termux.sh b/scripts/install-termux.sh
index fbab7a7a..425bdfd7 100755
--- a/scripts/install-termux.sh
+++ b/scripts/install-termux.sh
@@ -7,8 +7,12 @@ DISTRO="${MSO_TERMUX_DISTRO:-mso-ubuntu}"
GUEST_USER="${MSO_TERMUX_USER:-mso}"
IMAGE="${MSO_TERMUX_IMAGE:-ubuntu:24.04}"
INSTALL_URL="${MSO_TERMUX_INSTALL_URL:-https://raw.githubusercontent.com/rahmanef63/mso/main/scripts/install.sh}"
+GUEST_REF="${MSO_TERMUX_REF:-main}"
+BUILD_CPUS="${MSO_TERMUX_BUILD_CPUS:-1}"
+NODE_HEAP_MB="${MSO_TERMUX_NODE_HEAP_MB:-1536}"
TERMUX_BIN="${PREFIX:-/data/data/com.termux/files/usr}/bin"
GUEST_SYSTEM_PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
+INSTALL_LOG="${MSO_TERMUX_LOG:-$HOME/.mso/install-termux.log}"
info() { printf '· %s\n' "$*"; }
ok() { printf '✓ %s\n' "$*"; }
@@ -22,6 +26,18 @@ esac
# arbitrary shell source (the download URL is passed as a positional argument).
[[ "$DISTRO" =~ ^[a-zA-Z0-9][a-zA-Z0-9_-]*$ ]] || fail 'invalid distro name.'
[[ "$GUEST_USER" =~ ^[a-z_][a-z0-9_-]*$ ]] && [ "$GUEST_USER" != root ] || fail 'invalid non-root guest user.'
+[[ "$GUEST_REF" =~ ^[a-zA-Z0-9][a-zA-Z0-9._/-]*$ ]] || fail 'invalid MSO ref.'
+[[ "$BUILD_CPUS" =~ ^[1-9][0-9]*$ ]] || fail 'MSO_TERMUX_BUILD_CPUS must be a positive integer.'
+[[ "$NODE_HEAP_MB" =~ ^[1-9][0-9]*$ ]] || fail 'MSO_TERMUX_NODE_HEAP_MB must be a positive integer.'
+
+mkdir -p "$(dirname "$INSTALL_LOG")"
+touch "$INSTALL_LOG"
+chmod 600 "$INSTALL_LOG"
+if [ "${MSO_TERMUX_NO_TEE:-0}" != 1 ]; then
+ exec > >(tee -a "$INSTALL_LOG") 2>&1
+fi
+info "persistent install log: $INSTALL_LOG"
+info "Android-safe build limits: workers=$BUILD_CPUS node-heap=${NODE_HEAP_MB}MiB"
command -v apt >/dev/null 2>&1 || fail 'Termux apt is missing.'
info 'repairing/updating Termux packages'
@@ -70,10 +86,18 @@ info 'installing/updating MSO inside Ubuntu'
proot-distro login "$DISTRO" --user "$GUEST_USER" -- /usr/bin/env -i \
HOME="/home/$GUEST_USER" USER="$GUEST_USER" LOGNAME="$GUEST_USER" SHELL=/bin/bash \
PATH="/home/$GUEST_USER/.local/bin:/home/$GUEST_USER/.bun/bin:$GUEST_SYSTEM_PATH" \
- BUN_INSTALL="/home/$GUEST_USER/.bun" LANG=C.UTF-8 TERM="${TERM:-xterm-256color}" \
+ BUN_INSTALL="/home/$GUEST_USER/.bun" MSO_REF="$GUEST_REF" \
+ MSO_BUILD_CPUS="$BUILD_CPUS" MSO_LOW_MEMORY_BUILD=1 \
+ NODE_OPTIONS="--max-old-space-size=$NODE_HEAP_MB" MAKEFLAGS="-j$BUILD_CPUS" \
+ npm_config_jobs="$BUILD_CPUS" RAYON_NUM_THREADS="$BUILD_CPUS" \
+ LANG=C.UTF-8 TERM="${TERM:-xterm-256color}" \
/bin/bash --noprofile --norc -c '
set -Eeuo pipefail
cd "$HOME"
+ printf "· guest runtime: "
+ uname -m
+ grep "^MemTotal:" /proc/meminfo 2>/dev/null | sed "s/^/· guest memory: /" || true
+ df -h "$HOME" 2>/dev/null | tail -n 1 | sed "s/^/· guest storage: /" || true
# Refuse manually linked Android runtimes even on an otherwise clean PATH.
# Missing tools are installed by the normal Linux installer (NodeSource/Bun).
for runtime in node bun; do
@@ -90,6 +114,11 @@ proot-distro login "$DISTRO" --user "$GUEST_USER" -- /usr/bin/env -i \
command -v mso >/dev/null 2>&1
mso --version
mso -h >/dev/null
+
+ # Normal installs must end attached to main so future `mso update` calls work.
+ if [ "$MSO_REF" = main ] && [ -d "$HOME/mso/.git" ]; then
+ git -C "$HOME/mso" switch -C main origin/main >/dev/null
+ fi
' bash "$INSTALL_URL"
LAUNCHER="$TERMUX_BIN/mso"
diff --git a/scripts/install-termux.test.ts b/scripts/install-termux.test.ts
index 75d275a4..b3c6a16f 100644
--- a/scripts/install-termux.test.ts
+++ b/scripts/install-termux.test.ts
@@ -34,7 +34,7 @@ proot-distro() {
printf '%s\\0' "$@" > ${quote(root)}/"$user.args"
}
`;
- const env: NodeJS.ProcessEnv = { PATH: `/usr/bin:/bin`, HOME: root, PREFIX: prefix, TERM: "xterm-256color", NODE_ENV: "test" };
+ const env: NodeJS.ProcessEnv = { PATH: `/usr/bin:/bin`, HOME: root, PREFIX: prefix, TERM: "xterm-256color", NODE_ENV: "test", MSO_TERMUX_NO_TEE: "1" };
const run = spawnSync("/bin/bash", ["--noprofile", "--norc", "-c", `${mock}\nsource ${quote(installer)}`], { env, encoding: "utf8", timeout: 10000 });
expect(run.status, run.stderr).toBe(0);
const readArgs = (name: string) => fs.readFileSync(path.join(root, `${name}.args`), "utf8").split("\0").slice(0, -1);
@@ -70,7 +70,7 @@ describe("Termux PRoot Linux environment boundary", () => {
const result = probe(args, f.dirty);
expect(result.status, result.stderr).toBe(0);
expect(result.stdout).not.toContain(f.prefix);
- expect(result.stdout).not.toMatch(/TERMUX_VERSION=|NODE_PATH=|NODE_OPTIONS=|npm_config_|LD_PRELOAD=|LD_LIBRARY_PATH=|CFLAGS=|LDFLAGS=|BASH_ENV=|ENV=|BASH_FUNC_|function/);
+ expect(result.stdout).not.toMatch(/TERMUX_VERSION=|NODE_PATH=|npm_config_nodedir=|npm_config_prefix=|LD_PRELOAD=|LD_LIBRARY_PATH=|CFLAGS=|LDFLAGS=|BASH_ENV=|ENV=|BASH_FUNC_|function/);
expect(result.stderr).not.toContain("HOST_STARTUP_LEAK");
expect(result.stdout).toContain(`PATH=${name === "root" ? "" : "/home/mso/.local/bin:/home/mso/.bun/bin:"}${systemPath}\n`);
expect(result.stdout).toContain(`HOME=${name === "root" ? "/root" : "/home/mso"}\n`);