commit 8b41855dcf5eb207eb1877f4d8723a53cd8ae0c2
parent 649058290141a67fb39f46987005b0e6d28d9c6f
Author: torter <koubbamohamedrayan@gmail.com>
Date: Wed, 28 Oct 2026 11:49:13 -0400
netinst: downloads by curl (chamesle-get), slow mirrors dropped and retried, one percentage for all of it. firmware for this computer's hardware now, the rest later in the background. 0.7.0
Diffstat:
3 files changed, 172 insertions(+), 8 deletions(-)
diff --git a/VERSION b/VERSION
@@ -1 +1 @@
-0.6.0
+0.7.0
diff --git a/overlay/usr/bin/chamesle-desktop b/overlay/usr/bin/chamesle-desktop
@@ -24,15 +24,27 @@ NAME=$(sed -n 's/^name=//p' "$D/$ED/edition")
BASEPKGS=$D/base.packages; [ "$(val desktop-packages)" = no ] && BASEPKGS=
pkgs=$(sed 's/#.*//' $BASEPKGS $(for e in $EDS; do echo "$D/$e/packages"; done) | tr ' \t' '\n\n' | grep -v '^$' | sort -u)
echo "chamesle-desktop: $NAME, $(echo "$pkgs" | wc -l) packages and what they need"
-prog=; [ -n "${CHAMESLE_PROGRESS:-}" ] && prog="--progress-fd $CHAMESLE_PROGRESS"
-# the netinst came without most of the firmware: all of it, now that there's a disk to put it on
+# the netinst came without most of the firmware. now: what this computer's graphics and processor need.
+# the rest (wi-fi chips it doesn't have, phones...) comes later in the background, chamesle-refresh does that
+now=
if [ -s /etc/chamesle/trimmed ]; then
- apk fix --no-interactive $prog --reinstall $(cat /etc/chamesle/trimmed)
- rm /etc/chamesle/trimmed
+ v=$(cat /sys/bus/pci/devices/*/vendor 2>/dev/null; grep -m1 vendor_id /proc/cpuinfo)
+ for f in $(cat /etc/chamesle/trimmed); do
+ case $f in
+ linux-firmware) now="$now $f";;
+ linux-firmware-amd) echo "$v" | grep -qiE '0x1002|AuthenticAMD' && now="$now $f";;
+ linux-firmware-intel) echo "$v" | grep -qiE '0x8086|GenuineIntel' && now="$now $f";;
+ intel-ucode) echo "$v" | grep -qi GenuineIntel && now="$now $f";;
+ linux-firmware-nvidia) echo "$v" | grep -qi '0x10de' && now="$now $f";;
+ esac
+ done
+ for f in $now; do sed -i "/^$f\$/d" /etc/chamesle/trimmed; done
+ [ -s /etc/chamesle/trimmed ] || rm /etc/chamesle/trimmed
fi
-# what came from an older iso: as new as the repo, kernel and all
-apk upgrade --no-interactive $prog
-apk add --no-interactive $prog '!runit' '!runit-void' $pkgs
+# what came from an older iso: as new as the repo, kernel and all. curl does the downloading, with one
+# percentage for all of it (chamesle-get)
+fix=; [ -n "$now" ] && fix="fix --reinstall$now"
+/usr/libexec/chamesle-get ${fix:+"$fix"} "upgrade" "add !runit !runit-void $(echo $pkgs)"
fp=$(val flatpaks)
if [ -n "$fp" ]; then
diff --git a/overlay/usr/libexec/chamesle-get b/overlay/usr/libexec/chamesle-get
@@ -0,0 +1,152 @@
+#!/usr/bin/python3
+# chamesle-get "APK ARGS" ...: apk commands, with the downloads done by curl first.
+# apk's own downloader waits forever on a slow mirror; curl gives up on one and tries again. the files land in
+# a local copy of the repo (the signed index and the packages it needs), then apk runs from that, offline.
+# CHAMESLE_PROGRESS=FD gets "done/1000" lines for the whole thing: downloading is the first 80%, installing the rest
+# chamesle-get "fix --reinstall linux-firmware-amd" "upgrade" "add kde-plasma"
+import os, re, shutil, subprocess, sys, threading, time
+
+LOCAL = "/var/cache/chamesle-get"
+DL = LOCAL + "/x86_64"
+DOWN = 800
+
+fd = os.environ.get("CHAMESLE_PROGRESS")
+out = os.fdopen(int(fd), "w", buffering=1) if fd else None
+last = [-1]
+
+
+def say(n):
+ n = max(0, min(1000, int(n)))
+ if out and n != last[0]:
+ last[0] = n
+ out.write("%d/1000\n" % n)
+
+
+def repo():
+ for line in open("/etc/apk/repositories"):
+ p = line.split()
+ if p and not line.startswith("#") and p[-1].startswith("http"):
+ return p[-1].rstrip("/")
+ sys.exit("chamesle-get: no http repo in /etc/apk/repositories")
+
+
+def curl(url, path, size=0):
+ # under 300 KB/s for 8 s: that mirror crawls, drop it and go again where it left off. the redirect picks
+ # another one most times. the last tries take anything
+ for i in range(12):
+ slow = "300000" if i < 9 else "1000"
+ r = subprocess.run(["curl", "-fsSL", "-C", "-", "--connect-timeout", "15", "--speed-limit", slow,
+ "--speed-time", "8", "-o", path + ".part", url])
+ if r.returncode == 0 and (not size or os.path.getsize(path + ".part") == size):
+ os.replace(path + ".part", path)
+ return True
+ if r.returncode == 33 or (size and os.path.exists(path + ".part") and os.path.getsize(path + ".part") > size):
+ os.remove(path + ".part")
+ time.sleep(2)
+ return False
+
+
+def apk(args, progress=None):
+ cmd = ["apk", "--repositories-file", LOCAL + "/repositories", "--no-interactive"] + args
+ if progress is None:
+ return subprocess.run(cmd, capture_output=True, text=True)
+ r, w = os.pipe()
+ p = subprocess.Popen(cmd[:1] + ["--progress-fd", str(w)] + cmd[1:], pass_fds=(w,))
+ os.close(w)
+ with os.fdopen(r) as f:
+ for line in f:
+ d, _, t = line.strip().partition("/")
+ if d.isdigit() and t.isdigit() and int(t):
+ progress(int(d) / int(t))
+ return p.wait()
+
+
+def sizes():
+ # name-version -> file size, from the index
+ got, name, ver = {}, None, None
+ dump = subprocess.run(["apk", "adbdump", DL + "/Packages.adb"], capture_output=True, text=True).stdout
+ for line in dump.splitlines():
+ if line.startswith(" - name: "):
+ name, ver = line[10:].strip(), None
+ elif line.startswith(" version: "):
+ ver = line[13:].strip()
+ elif line.startswith(" file-size: ") and name and ver:
+ got["%s-%s" % (name, ver)] = int(line[15:])
+ return got
+
+
+def main():
+ steps = [s.split() for s in sys.argv[1:]]
+ if not steps:
+ sys.exit("usage: chamesle-get \"APK ARGS\" ...")
+ url = repo()
+ os.makedirs(DL, exist_ok=True)
+ with open(LOCAL + "/repositories", "w") as f:
+ f.write("v3 %s\n" % LOCAL)
+ say(0)
+ if not curl(url + "/x86_64/Packages.adb", DL + "/Packages.adb"):
+ sys.exit("chamesle-get: can't get the package list from %s" % url)
+ size = sizes()
+
+ # what apk would fetch, from a dry run of every step
+ want = {}
+ for s in steps:
+ r = apk(["--simulate"] + s)
+ if r.returncode:
+ sys.stderr.write(r.stdout + r.stderr)
+ sys.exit("chamesle-get: apk %s won't work" % " ".join(s))
+ for line in r.stdout.splitlines():
+ m = re.match(r"\(\s*\d+/\d+\) (Installing|Upgrading|Downgrading|Replacing|Reinstalling) (\S+) \((?:.* -> )?(\S+)\)", line)
+ if m:
+ pv = "%s-%s" % (m.group(2), m.group(3))
+ want[pv] = size.get(pv, 0)
+
+ total = sum(want.values()) or 1
+ done = {pv: n for pv, n in want.items() if os.path.exists("%s/%s.apk" % (DL, pv)) and os.path.getsize("%s/%s.apk" % (DL, pv)) == n}
+ todo = [pv for pv in want if pv not in done]
+ print("chamesle-get: %d packages, %d MB to download" % (len(want), sum(want[p] for p in todo) // 1048576), file=sys.stderr)
+ bad, lock = [], threading.Lock()
+
+ def worker():
+ while True:
+ with lock:
+ if not todo:
+ return
+ pv = todo.pop(0)
+ if curl("%s/x86_64/%s.apk" % (url, pv), "%s/%s.apk" % (DL, pv), want[pv]):
+ with lock:
+ done[pv] = want[pv]
+ else:
+ with lock:
+ bad.append(pv)
+ threads = [threading.Thread(target=worker, daemon=True) for _ in range(6)]
+ for t in threads:
+ t.start()
+ while any(t.is_alive() for t in threads):
+ part = 0
+ for pv in want:
+ if pv not in done:
+ try:
+ part += os.path.getsize("%s/%s.apk.part" % (DL, pv))
+ except OSError:
+ pass
+ with lock:
+ have = sum(done.values())
+ say(DOWN * (have + part) / total)
+ time.sleep(0.5)
+ if bad:
+ sys.exit("chamesle-get: couldn't download %s" % ", ".join(bad))
+ say(DOWN)
+
+ # now apk, offline, each step its share of the last 20%
+ share = (1000 - DOWN) / len(steps)
+ for i, s in enumerate(steps):
+ base = DOWN + i * share
+ if apk(s, lambda f, base=base: say(base + f * share)):
+ sys.exit("chamesle-get: apk %s failed" % " ".join(s))
+ say(1000)
+ shutil.rmtree(LOCAL, ignore_errors=True)
+
+
+if __name__ == "__main__":
+ main()