Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,24 @@ One source per fact: the app ABI and the installed library's ABI (ADR-K2GO-571).
(`DeepOpService`), backup identity + name (`BackupEngine`), 64-bit-only module gate
(`ModuleCards.runsOn`), fresh-install arch (`SystemStateEvaluator.termuxArch`).

**Standard flow (K2GO-593): proot module install progress and download**
Maps (K2GO-394) and Forgejo use it; a new proot module follows it.

- `install/domain/`: `ModuleDownloadProgress` (the download bar state), `DownloadHold` (hold a box
download on mobile data with no consent or with Keep offline; reuses `NetworkPolicy`),
`ForgejoBinaryPin` (the version pin of one run). Pure JVM, unit-tested.
- `install/presentation/`: `ModuleDownload` owns one dash-node download job (start, pause, resume,
cancel, hold; "who stopped it" lives only here). `ModuleDownloadRepository` is the one source of
the download bar; `ModuleQueueRepository` stays the one source of the install bar.
`InstallService.postModuleStart` is the one rule: a role with a task table starts at 0% before its
download, so both bars show.
- `redesign/ModuleProgressPanel` + `view_k2go_module_progress`: install bar over download card, the
same on every install screen; it keeps no state.
- dash-node: the download runs before `pdsm stop` (the stop also stops dash-node); the box resolves
the URL and checks the file (`sockets/forgejo-bin.exec.ts`).
- A new module with a download: a dash-node job type, a pre-download step in `InstallService`, a
task table in `assets/runrole/`, and the panel in its screen.

**Legacy (NOT yet layered)**: the redesign retired the original god classes
`MainActivity` and `DeployFragment` (they no longer exist; DONE-slice seams above
that still name them are pre-redesign records). The current god-tier classes,
Expand Down
47 changes: 47 additions & 0 deletions controller/app/src/main/assets/runrole/forgejo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Assert that "forgejo_install is sameas true" (boolean not string etc)
Assert that "forgejo_enabled | type_debug == 'bool'" (boolean not string etc)
Install Forgejo if 'forgejo_installed' not defined, e.g. in /etc/iiab/iiab_state.yml
Assert forgejo_db_engine is a supported value ('sqlite' or 'mariadb')
Query Codeberg for the latest Forgejo release
Set forgejo_version from the latest release tag
Assert forgejo_version is a valid X.Y.Z release
Record (initial) disk space used
Stop existing Forgejo systemd service (if reinstalling, not proot)
Stop existing Forgejo via pdsm (if reinstalling, proot)
Ensure group 'forgejo' exists
Create user 'forgejo'
Create /library/forgejo directory structure
Make directories data, log, backups writable (0750)
Check whether Forgejo is already installed (app.ini present)
Detect the existing install's DB engine (engine-change guard)
Refuse an unsupported DB engine change on an existing install
Compute a backup timestamp (proot-safe, no fact dependency)
Back up Forgejo (forgejo dump) to /library/forgejo/backups before swapping the binary
Fail if we detect an unsupported CPU architecture
Verify the downloaded Forgejo binary against its GPG signature (fail closed)
Find installed Forgejo binaries in /library/forgejo/bin
mkdir /etc/forgejo (0770 root:forgejo)
Generate Forgejo secrets once (guarded by 'creates'), referenced by *_URI in app.ini
Secure the generated secret files (0640 root:forgejo)
Set 'mysql_install: True' and 'mysql_enabled: True'
MYSQL - run 'mysql' role
FAIL (STOP THE INSTALL) IF 'mysql_installed is undefined'
Create MySQL database for Forgejo: forgejo
Create MySQL username (forgejo) with password, for above database
Install /etc/forgejo/app.ini from template (0664 root:forgejo)
Install systemd unit /etc/systemd/system/forgejo.service (not proot)
Record (final) disk space used
Set 'forgejo_installed: True'
Add 'forgejo_installed: True' to /etc/iiab/iiab_state.yml
Enable/Disable Forgejo (systemd or pdsm) and NGINX
Enable & Restart 'forgejo' systemd service, if forgejo_enabled (not proot)
Disable & Stop 'forgejo' systemd service, if not forgejo_enabled (not proot)
Enable 'forgejo' via pdsm (proot)
Restart 'forgejo' via pdsm (proot)
Stop 'forgejo' via pdsm (proot)
Disable 'forgejo' via pdsm (proot)
Enable http://box/forgejo via NGINX, by installing /etc/nginx/conf.d/forgejo-nginx.conf from template
Disable http://box/forgejo via NGINX, by removing /etc/nginx/conf.d/forgejo-nginx.conf
Reload 'nginx' systemd service (not proot)
Restart 'nginx' via pdsm (proot)
Add 'forgejo' variable values to /etc/iiab/iiab.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* and the box read live elsewhere (redesign.DashboardVersion), so this stays a plain,
* unit-testable registry with no Android or network dependency.
*
* Forgejo needs the dashboard build that ships its repo status/refresh endpoints (1.3.7):
* an older dash-node makes "Install repos"/"Update repos" and the seed break silently, so
* installing Forgejo is HARD-blocked below that version. Code on the Go add-ons (K2GO-99)
* Forgejo needs the dashboard build that ships its repo status/refresh endpoints (1.3.7)
* and the forgejo-bin download job (1.6.5, K2GO-593): an older dash-node breaks the
* install, so installing Forgejo is HARD-blocked below that version. Code on the Go add-ons (K2GO-99)
* needs the dashboard build that ships the /addons/refresh endpoints (1.3.8), so the gallery
* can update, so it is HARD-blocked below that version too. Other modules have no hard minimum
* (a soft "update the dashboard" suggestion applies to all installs, handled in the gate).
Expand All @@ -25,7 +25,8 @@ private DashNodeRequirement() {}
/** {major, minor, patch} minimum dash-node for {@code moduleKey}, or null when it has no hard minimum. */
@Nullable
public static int[] minFor(@Nullable String moduleKey) {
if ("forgejo".equals(moduleKey)) return new int[]{1, 3, 7};
// K2GO-593: 1.6.5 has the forgejo-bin job, which downloads the binary before the install.
if ("forgejo".equals(moduleKey)) return new int[]{1, 6, 5};
if ("code_addons".equals(moduleKey)) return new int[]{1, 3, 8}; // K2GO-99: needs /addons/refresh
// K2GO-437: code_assets install (runrole) and browsing (WebView) do NOT use the dash-node
// refresh endpoints; only the "Update build assets" action does, and it degrades gracefully
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* ============================================================================
* Name : DownloadHold.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : K2GO-593. When the app must stop a module download on the box
* because of the network, and when it may continue it. Pure JVM.
* ============================================================================
*/
package org.appdevforall.k2go.install.domain;

import org.appdevforall.k2go.networkpolicy.domain.NetworkClass;
import org.appdevforall.k2go.networkpolicy.domain.NetworkPolicy;
import org.appdevforall.k2go.networkpolicy.domain.NetworkPolicyDecision;

/**
* The box downloads on the phone's default network, and its aria2 retry loop continues on mobile
* data after a Wi-Fi drop, with no question (seen on a Samsung A16 with 4G). The start gate
* (NetworkPolicyGate) asks only at the start. This rule is the in-flight half: hold the download while
* the network may not be used, and continue it when it may.
*
* <p>A pause by the user is the user's decision: a network event never continues it, and this rule
* never holds it again. No network at all is not a hold: the box reconnects on its own, and there is
* no traffic to stop.
*/
public final class DownloadHold {

private DownloadHold() {}

/** Who stopped the download, if somebody did. */
public enum StoppedBy { NOBODY, USER, NETWORK }

/** Why the download is held. */
public enum Reason { METERED_NO_CONSENT, KEPT_OFFLINE }

/** What the caller does now. */
public enum Action { NONE, HOLD, CONTINUE }

/**
* @param net cost class of the default network now
* @param meteredConsent the user allowed mobile data for this session
* @param onlineAllowed the user allows module installs to connect (online, or allowed this time)
* @param stoppedBy who stopped the download, if somebody did
*/
public static Action decide(NetworkClass net, boolean meteredConsent, boolean onlineAllowed,
StoppedBy stoppedBy) {
if (stoppedBy == StoppedBy.USER || net == NetworkClass.NONE) return Action.NONE;
boolean mayRun = reason(net, meteredConsent, onlineAllowed) == null;
if (stoppedBy == StoppedBy.NOBODY) return mayRun ? Action.NONE : Action.HOLD;
return mayRun ? Action.CONTINUE : Action.NONE;
}

/**
* Why the network may not be used now, or null when it may. The mobile data rule is the start
* gate's own rule (NetworkPolicy), so the start and the in-flight check cannot disagree.
*/
public static Reason reason(NetworkClass net, boolean meteredConsent, boolean onlineAllowed) {
if (!onlineAllowed) return Reason.KEPT_OFFLINE;
if (POLICY.decideHeavyStart(net, meteredConsent) == NetworkPolicyDecision.NEEDS_CONSENT) {
return Reason.METERED_NO_CONSENT;
}
return null;
}

private static final NetworkPolicy POLICY = new NetworkPolicy();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* ============================================================================
* Name : ForgejoBinaryPin.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : K2GO-593. The local_vars line that makes the forgejo role use
* the binary that dash-node downloaded. Pure JVM.
* ============================================================================
*/
package org.appdevforall.k2go.install.domain;

/**
* dash-node downloads the Forgejo binary to {@code /library/forgejo/bin/forgejo-<ver>} (job type
* {@code forgejo-bin}). The role resolves {@code forgejo_version: latest} on its own, so the app pins
* the version that dash-node got, and the role's get_url finds the file and skips its download. The
* role then still checks the GPG signature of the file.
*
* <p>The pin is for this one run: a later update must resolve the newest release again. So the line
* carries a marker, and {@link #UNPIN} removes only the marked line, never a pin the owner wrote.
* The version comes from the box, and it goes into a root shell command, so it is checked here first.
*/
public final class ForgejoBinaryPin {

private ForgejoBinaryPin() {}

/** The module that owns this download. */
public static final String MODULE = "forgejo";
/** The dash-node job type. */
public static final String JOB_TYPE = "forgejo-bin";

private static final String MARKER = "# k2go-forgejo-bin";
private static final String LOCAL_VARS = "/etc/iiab/local_vars.yml";

/** Removes the marked pin. Safe to run when there is none. */
public static final String UNPIN = "sed -i '/" + MARKER + "$/d' " + LOCAL_VARS;

/** The role's assert: X.Y.Z. */
public static boolean isVersion(String v) {
return v != null && v.matches("[0-9]+\\.[0-9]+\\.[0-9]+");
}

/**
* The forgejo_version that the owner wrote in local_vars (a line without the marker), or null when
* there is none or it is "latest". With an owner pin the app does not download: the role
* downloads the version the owner chose, as before.
*/
public static String ownerPin(java.util.List<String> localVarsLines) {
if (localVarsLines == null) return null;
String pin = null;
for (String raw : localVarsLines) {
if (raw == null || raw.trim().endsWith(MARKER)) continue;
java.util.regex.Matcher m = OWNER_LINE.matcher(raw);
if (m.matches()) pin = m.group(1); // the last one wins, as in YAML
}
return pin == null || "latest".equals(pin) ? null : pin;
}

private static final java.util.regex.Pattern OWNER_LINE = java.util.regex.Pattern.compile(
"^forgejo_version[ \\t]*:[ \\t]*[\"']?([^\"'#\\s]+)[\"']?[ \\t]*(#.*)?$");

/**
* The batch order with Forgejo first. Its download runs before the server stop, while its row
* already runs, so a module before it in the list would look done. The others keep their order.
*/
public static String[] downloadFirst(String[] modules) {
if (modules == null) return null;
java.util.List<String> out = new java.util.ArrayList<>(modules.length);
for (String m : modules) if (MODULE.equals(m)) out.add(m);
for (String m : modules) if (!MODULE.equals(m)) out.add(m);
return out.toArray(new String[0]);
}

/**
* The shell command that pins {@code version}, or null when the version is not X.Y.Z. A pin that a
* killed run left is removed first, so there is never more than one marked line.
*/
public static String pinCommand(String version) {
if (!isVersion(version)) return null;
return UNPIN + " && echo 'forgejo_version: \"" + version + "\" " + MARKER + "' >> " + LOCAL_VARS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* ============================================================================
* Name : ModuleDownloadProgress.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : K2GO-394, K2GO-593. The download that a module install does
* through dash-node before its role (maps base maps, the Forgejo
* binary), as the download bar needs it. Pure JVM.
* ============================================================================
*/
package org.appdevforall.k2go.install.domain;

/**
* A snapshot of a module's download for the download bar. The download runs as a dash-node job, so
* this is built from the REST poll fields ({@code RestContentClient.Listener}): a phase, a percent, a
* speed token, the time left and the reconnect counter. The rule for "which phase" lives here, not in
* the UI.
*/
public final class ModuleDownloadProgress {

/**
* The states the download bar shows. RECONNECTING is a network drop that the box rides out. HELD
* is a stop that the app made because the network may not be used now (mobile data with no
* consent, or Keep offline); it continues on Wi-Fi or after the user allows it.
*/
public enum Phase { NONE, ACTIVE, PAUSED, HELD, RECONNECTING, COMPLETE }

public final Phase phase;
/** The module key that owns the download ("maps", "forgejo"), or null for NONE. */
public final String module;
/** 0..100, or -1 when not known yet. */
public final int percent;
/** Display token for the rate WITHOUT the per-second suffix (e.g. "3.4 MB"); the UI appends "/s". */
public final String speed;
/** Seconds left, or -1 when not known. */
public final long etaSeconds;
/** Reconnect counter for "Reconnecting n of N"; both 0 when not reconnecting. */
public final int reconnectAttempt;
public final int reconnectTotal;
/** Why the download is HELD; null in the other phases. */
public final DownloadHold.Reason holdReason;

private ModuleDownloadProgress(Phase phase, String module, int percent, String speed, long eta,
int attempt, int total, DownloadHold.Reason holdReason) {
this.phase = phase;
this.module = module;
this.percent = percent < 0 ? -1 : Math.min(100, percent);
this.speed = speed != null ? speed : "";
this.etaSeconds = eta < 0 ? -1 : eta;
this.reconnectAttempt = Math.max(0, attempt);
this.reconnectTotal = Math.max(0, total);
this.holdReason = holdReason;
}

/** Nothing is downloading: before the job starts, or after it ends. */
public static ModuleDownloadProgress none() {
return new ModuleDownloadProgress(Phase.NONE, null, -1, "", -1, 0, 0, null);
}

/** A live download at {@code percent} moving at {@code speed} (a display token, no "/s"). */
public static ModuleDownloadProgress active(String module, int percent, String speed, long etaSeconds) {
return new ModuleDownloadProgress(Phase.ACTIVE, module, percent, speed, etaSeconds, 0, 0, null);
}

/** The user paused the download; the partial is kept and Resume continues from it. */
public static ModuleDownloadProgress paused(String module, int percent) {
return new ModuleDownloadProgress(Phase.PAUSED, module, percent, "", -1, 0, 0, null);
}

/** The app stopped the download for {@code reason}; the partial is kept. */
public static ModuleDownloadProgress held(String module, int percent, DownloadHold.Reason reason) {
return new ModuleDownloadProgress(Phase.HELD, module, percent, "", -1, 0, 0, reason);
}

/** The box lost the network and reconnects (attempt n of total), keeping the partial. */
public static ModuleDownloadProgress reconnecting(String module, int attempt, int total) {
return new ModuleDownloadProgress(Phase.RECONNECTING, module, -1, "", -1, attempt, total, null);
}

/** The download finished. */
public static ModuleDownloadProgress complete(String module) {
return new ModuleDownloadProgress(Phase.COMPLETE, module, 100, "", 0, 0, 0, null);
}

public boolean isActive() {
return phase == Phase.ACTIVE;
}

public boolean isPaused() {
return phase == Phase.PAUSED;
}

public boolean isHeld() {
return phase == Phase.HELD;
}

public boolean isReconnecting() {
return phase == Phase.RECONNECTING;
}

public boolean isComplete() {
return phase == Phase.COMPLETE;
}

/** Whether there is a download to show a bar for (active, paused, held or reconnecting). */
public boolean isRunning() {
return phase == Phase.ACTIVE || phase == Phase.PAUSED || phase == Phase.HELD
|| phase == Phase.RECONNECTING;
}

/** Whether this snapshot is the download of {@code moduleKey}. */
public boolean isFor(String moduleKey) {
return module != null && module.equals(moduleKey);
}
}
Loading
Loading