chamesle

chamesle.org: the site of Chamesle, a small Linux distribution
git clone https://github.com/tortr-rs/chamesle
Log | Files | Refs | README

commit 8a3c7d62d2b20c57c8a77a060fb7da9a64b21b50
parent 20c0ca36036c364861d87c80ebe7fd72abd84785
Author: torter <koubbamohamedrayan@gmail.com>
Date:   Sun,  8 Nov 2026 00:57:12 +0000

jiggity: the console gets the keyboard that was picked (gb was us, so a password with @ or " didn't work at the sign-in screen), system usernames refused and a failed account stops the install, esc at the passphrase doesn't skip encryption, long errors don't crash the text screen

Diffstat:
Moverlay/usr/lib/jiggity/account.py | 31+++++++++++++++++++++++++++----
Moverlay/usr/lib/jiggity/choices.py | 26++++++++++++++++++++++++++
Moverlay/usr/lib/jiggity/disks.py | 3++-
Moverlay/usr/lib/jiggity/firstboot.py | 11++++++++++-
Moverlay/usr/lib/jiggity/install.py | 3++-
Moverlay/usr/lib/jiggity/text.py | 34+++++++++++++++++++++++++---------
6 files changed, 92 insertions(+), 16 deletions(-)

diff --git a/overlay/usr/lib/jiggity/account.py b/overlay/usr/lib/jiggity/account.py @@ -28,11 +28,29 @@ def username_from(name): return re.sub(r"[^a-z0-9_-]", "", name.split(" ")[0].lower()) +# names the system has, and ones the desktops add while jiggity installs them: useradd fails on any of these, and +# the computer would start with no account to sign in with +SYSTEM_NAMES = set("""root live daemon bin sys nobody admin adm wheel users user audio video input render kvm disk + tty utmp lp mail news uucp man games ftp www http sshd dbus polkitd sddm gdm lightdm colord avahi rtkit pulse + pipewire geoclue flatpak usbmux saned scanner optical storage network plugdev bluetooth cups dnsmasq ntp chrony + upower tss nm-openvpn nm-openconnect openvpn tor mpd postfix steam gamemode xbuilder _apt""".split()) + + +def taken(root="/"): + names = set(SYSTEM_NAMES) + for f in ("etc/passwd", "etc/group"): + try: + names |= {line.split(":")[0] for line in open(os.path.join(root, f))} + except OSError: + pass + return names + + # what's wrong with a username, or "" def bad_username(u): if u and not re.fullmatch(r"[a-z_][a-z0-9_-]{0,31}", u): return "A username is lowercase letters and numbers, starting with a letter." - if u in ("root", "live", "daemon", "bin", "nobody"): + if u in taken(): return "That username is taken by the system. Pick another one." return "" @@ -42,9 +60,14 @@ def make(zone, user, name, pw, host=None, root="/"): r = root.rstrip("/") inside = [] if root == "/" else ["chroot", root] groups = [g.split(":")[0] for g in open(r + "/etc/group")] - subprocess.run(inside + ["useradd", "-m", "-s", "/bin/bash", "-c", name, "-G", - ",".join(g for g in GROUPS if g in groups), user]) - subprocess.run(inside + ["chpasswd", "-c", "SHA512"], input="%s:%s\n" % (user, pw), text=True) + # a name the desktop's packages took after it was picked: say so, rather than finish with nobody to sign in as + for cmd, inp in ((["useradd", "-m", "-s", "/bin/bash", "-c", name, "-G", + ",".join(g for g in GROUPS if g in groups), user], None), + (["chpasswd", "-c", "SHA512"], "%s:%s\n" % (user, pw))): + p = subprocess.run(inside + cmd, input=inp, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + if p.returncode: + raise RuntimeError("making the account %s failed: %s" % (user, p.stdout.strip().splitlines()[-1:] and + p.stdout.strip().splitlines()[-1] or cmd[0])) subprocess.run(["ln", "-sf", "/usr/share/zoneinfo/" + zone, r + "/etc/localtime"]) with open(r + "/etc/timezone", "w") as f: f.write(zone + "\n") diff --git a/overlay/usr/lib/jiggity/choices.py b/overlay/usr/lib/jiggity/choices.py @@ -1,4 +1,5 @@ # what both installers offer: languages, keyboards, the install steps +import glob LANGUAGES = [ @@ -15,6 +16,31 @@ STEPS = ["Getting the drive ready", "Copying files", "Getting files ready for in "Installing the boot menu", "Finishing up"] +# the console's keymaps (kbd) aren't named like the xkb layouts: gb is uk, se is sv-latin1, and so on. one that +# doesn't exist leaves the console on us while the desktop gets the real layout, and a password with @ or " typed +# in jiggity doesn't work at the sign-in screen. not by name either: xkb's et is ethiopia, kbd's is estonia +CONSOLE = {"us": "us", "gb": "uk", "fr": "fr", "de": "de", "at": "de", "es": "es", "latam": "la-latin1", + "it": "it", "br": "br-abnt2", "pt": "pt-latin1", "nl": "nl", "be": "be-latin1", "pl": "pl", "tr": "trq", + "ru": "ru", "ua": "ua", "by": "by", "se": "sv-latin1", "no": "no-latin1", "dk": "dk-latin1", "fi": "fi", + "is": "is-latin1", "ie": "ie", "cz": "cz", "sk": "sk-qwertz", "hu": "hu", "ro": "ro", "gr": "gr", + "bg": "bg_bds-utf8", "mk": "mk", "rs": "sr-cy", "hr": "croat", "si": "slovene", "ee": "et", "lv": "lv", + "lt": "lt", "il": "il", "ir": "fa", "jp": "jp106", "ch": "sg", "ca": "cf", "kz": "kazakh", "kg": "kyrgyz", + "ge": "ge", "tj": "tj_alt-UTF8"} +CONSOLE_VARIANTS = {("us", "dvorak"): "dvorak", ("gb", "dvorak"): "dvorak-uk", ("es", "dvorak"): "dvorak-es", + ("fr", "dvorak"): "dvorak-fr", ("de", "nodeadkeys"): "de-latin1-nodeadkeys", + ("fr", "bepo"): "fr-bepo", ("ch", "fr"): "fr_CH", ("tr", "f"): "trf", + ("br", "nodeadkeys"): "br-abnt2", ("ru", "phonetic"): "ru"} + + +def console_keymap(layout, variant=""): + # the closest console keymap there is here, us when there's none (arabic, hindi, chinese...) + for name in (CONSOLE_VARIANTS.get((layout, variant)), CONSOLE.get(layout)): + if name and any(glob.glob("%s/**/%s.map*" % (d, name), recursive=True) + for d in ("/usr/share/kbd/keymaps", "/usr/share/keymaps")): + return name + return "us" + + def keyboards(): out, section = [], None try: diff --git a/overlay/usr/lib/jiggity/disks.py b/overlay/usr/lib/jiggity/disks.py @@ -19,7 +19,8 @@ def run(*cmd, input=None): if r.stdout: print(r.stdout.rstrip()) if r.returncode: - raise RuntimeError("%s failed: %s" % (cmd[0], (r.stdout or "").strip().splitlines()[-1:] or "")) + last = (r.stdout or "").strip().splitlines() + raise RuntimeError("%s failed: %s" % (cmd[0], last[-1] if last else "exit code %d" % r.returncode)) return r.stdout diff --git a/overlay/usr/lib/jiggity/firstboot.py b/overlay/usr/lib/jiggity/firstboot.py @@ -148,9 +148,18 @@ class FirstBoot(ui.SetupWindow): return box, [] def make_account(self): - account.make(self.zone, self.user.get_text(), self.name.get_text(), self.pw1.get_text()) + try: + account.make(self.zone, self.user.get_text(), self.name.get_text(), self.pw1.get_text()) + except Exception as e: + print("firstboot:", e) + GLib.idle_add(self.account_failed, str(e)) + return GLib.idle_add(Gtk.main_quit) + def account_failed(self, why): + self.show_page(2) + self.account_note.set_text("That didn't work (%s). Try another username." % why) + def show_page(self, n): super().show_page(n) if n == 1: diff --git a/overlay/usr/lib/jiggity/install.py b/overlay/usr/lib/jiggity/install.py @@ -9,6 +9,7 @@ import time import account import disks +from choices import console_keymap from disks import run SOURCE = "/run/chamesle/rootfs/" @@ -139,7 +140,7 @@ def install(row, passphrase, language, keyboard, progress, desktop=None, user=No f.write('Section "InputClass"\n Identifier "system-keyboard"\n MatchIsKeyboard "on"\n' ' Option "XkbLayout" "%s"\n Option "XkbVariant" "%s"\nEndSection\n' % (layout, variant or "")) with open(T + "/etc/vconsole.conf", "w") as f: - f.write("KEYMAP=%s\n" % (layout + ("-" + variant if variant else ""))) + f.write("KEYMAP=%s\n" % console_keymap(layout, variant)) if user: account.make(user["zone"], user["user"], user["name"], user["password"], user["host"], T) progress(2, 100) diff --git a/overlay/usr/lib/jiggity/text.py b/overlay/usr/lib/jiggity/text.py @@ -15,7 +15,7 @@ sys.path.insert(0, "/usr/lib/jiggity") import account import disks import install -from choices import LANGUAGES, STEPS, keyboards +from choices import LANGUAGES, STEPS, console_keymap, keyboards scr = None # the console font has latin letters only: these languages by their english names @@ -38,15 +38,17 @@ def frame(title, keys): def text(y, s): + # a long error message stops at the bottom of the screen instead of crashing it h, w = scr.getmaxyx() words, line = s.split(), "" for word in words: if len(line) + len(word) + 1 > w - 10: - scr.addstr(y, 4, line) + if y < h - 2: + scr.addstr(y, 4, line[:w - 8]) y, line = y + 1, "" line = (line + " " + word).strip() - if line: - scr.addstr(y, 4, line) + if line and y < h - 2: + scr.addstr(y, 4, line[:w - 8]) return y + 2 @@ -132,6 +134,11 @@ def yes(title, note): return False +# the passphrase and password are typed with the keyboard picked, the same one the boot and the desktop use +def use_keyboard(layout, variant): + subprocess.run(["loadkeys", console_keymap(layout, variant)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + def netinst(): try: return open("/usr/share/chamesle/edition").read().strip() == "netinst" @@ -235,9 +242,7 @@ def run_netinst(): if i is None: return False c["kb"] = i - layout, variant = kbds[i][1:] - subprocess.run(["loadkeys", layout + ("-" + variant if variant else "")], stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL) + use_keyboard(*kbds[i][1:]) return True def p_zone(): @@ -303,7 +308,8 @@ def run_netinst(): c["row"] = rows[i] break c["passphrase"] = None - if yes("Encrypt Chamesle?", "With a passphrase you type every time the computer starts. If you forget it, " + # esc at the passphrase goes back to the question, it doesn't quietly install without encryption + while c["passphrase"] is None and yes("Encrypt Chamesle?", "With a passphrase you type every time the computer starts. If you forget it, " "your files can't be recovered."): while True: p1 = ask("Encrypt Chamesle", "At least 8 characters.", "Passphrase:", True) @@ -420,6 +426,7 @@ def run_install(): kb = choose("Keyboard", "", [k[0] for k in kbds], us) if kb is None: kb = us + use_keyboard(*kbds[kb][1:]) while True: rows = disks.scan() if not rows: @@ -444,7 +451,8 @@ def run_install(): continue break passphrase = None - if yes("Encrypt Chamesle?", "With a passphrase you type every time the computer starts. If you forget it, your " + # esc at the passphrase goes back to the question, it doesn't quietly install without encryption + while passphrase is None and yes("Encrypt Chamesle?", "With a passphrase you type every time the computer starts. If you forget it, your " "files can't be recovered."): while True: p1 = ask("Encrypt Chamesle", "At least 8 characters.", "Passphrase:", True) @@ -466,6 +474,14 @@ def run_install(): def run_firstboot(): + while True: + try: + return firstboot_once() + except RuntimeError as e: + say("That didn't work", "%s. Press ENTER to try again." % str(e).rstrip(".")) + + +def firstboot_once(): zs = account.zones() names = [z.replace("_", " ").replace("/", " / ") for z in zs] while True: