commit ffc9d939bfd955e56a408ce74a85c160ebcc0272
parent 24f47ba7852bfa753caee5ab939e00ffd8841f10
Author: torter <koubbamohamedrayan@gmail.com>
Date: Sat, 21 Nov 2026 23:54:53 +0000
dinitctl as a user goes through doas, enable and disable work without a running dinit; services for the common daemons; arch-chroot instead of chamesle-chroot
Diffstat:
24 files changed, 411 insertions(+), 59 deletions(-)
diff --git a/files/etc/dinit.d/acpid b/files/etc/dinit.d/acpid
@@ -0,0 +1,4 @@
+type = process
+command = /sbin/acpid -f
+depends-on = system
+smooth-recovery = true
diff --git a/files/etc/dinit.d/avahi-daemon b/files/etc/dinit.d/avahi-daemon
@@ -0,0 +1,4 @@
+type = process
+command = /usr/sbin/avahi-daemon -s
+depends-on = dbus
+smooth-recovery = true
diff --git a/files/etc/dinit.d/bluetoothd b/files/etc/dinit.d/bluetoothd
@@ -0,0 +1,4 @@
+type = process
+command = /usr/lib/bluetooth/bluetoothd -n
+depends-on = dbus
+smooth-recovery = true
diff --git a/files/etc/dinit.d/chronyd b/files/etc/dinit.d/chronyd
@@ -0,0 +1,4 @@
+type = process
+command = /usr/sbin/chronyd -n
+depends-on = system
+smooth-recovery = true
diff --git a/files/etc/dinit.d/connmand b/files/etc/dinit.d/connmand
@@ -0,0 +1,4 @@
+type = process
+command = /usr/sbin/connmand -n
+depends-on = dbus
+smooth-recovery = true
diff --git a/files/etc/dinit.d/crond b/files/etc/dinit.d/crond
@@ -0,0 +1,4 @@
+type = process
+command = /usr/lib/chamesle/foreground crond
+depends-on = system
+smooth-recovery = true
diff --git a/files/etc/dinit.d/cupsd b/files/etc/dinit.d/cupsd
@@ -0,0 +1,4 @@
+type = process
+command = /usr/sbin/cupsd -f
+depends-on = system
+smooth-recovery = true
diff --git a/files/etc/dinit.d/gdm b/files/etc/dinit.d/gdm
@@ -1,5 +1,5 @@
type = process
command = /usr/sbin/gdm
-depends-on = elogind
-waits-for = NetworkManager
+depends-on = dbus
+waits-for = elogind
restart = true
diff --git a/files/etc/dinit.d/greetd b/files/etc/dinit.d/greetd
@@ -0,0 +1,6 @@
+type = process
+command = /usr/sbin/greetd
+depends-on = system
+waits-for = seatd
+waits-for = elogind
+restart = true
diff --git a/files/etc/dinit.d/klogd b/files/etc/dinit.d/klogd
@@ -0,0 +1,4 @@
+type = process
+command = /usr/lib/chamesle/foreground klogd
+depends-on = rootfs
+smooth-recovery = true
diff --git a/files/etc/dinit.d/lightdm b/files/etc/dinit.d/lightdm
@@ -0,0 +1,5 @@
+type = process
+command = /usr/bin/lightdm
+depends-on = dbus
+waits-for = elogind
+restart = true
diff --git a/files/etc/dinit.d/ntpd b/files/etc/dinit.d/ntpd
@@ -0,0 +1,4 @@
+type = process
+command = /usr/lib/chamesle/foreground ntpd
+depends-on = system
+smooth-recovery = true
diff --git a/files/etc/dinit.d/sddm b/files/etc/dinit.d/sddm
@@ -0,0 +1,5 @@
+type = process
+command = /usr/bin/sddm
+depends-on = dbus
+waits-for = elogind
+restart = true
diff --git a/files/etc/dinit.d/seatd b/files/etc/dinit.d/seatd
@@ -0,0 +1,4 @@
+type = process
+command = /usr/bin/seatd -g video
+depends-on = system
+smooth-recovery = true
diff --git a/files/etc/dinit.d/sshd b/files/etc/dinit.d/sshd
@@ -0,0 +1,4 @@
+type = process
+command = /bin/sh -c "ssh-keygen -A && exec /usr/sbin/sshd -D -e"
+depends-on = system
+smooth-recovery = true
diff --git a/files/etc/dinit.d/syslogd b/files/etc/dinit.d/syslogd
@@ -0,0 +1,4 @@
+type = process
+command = /usr/lib/chamesle/foreground syslogd
+depends-on = rootfs
+smooth-recovery = true
diff --git a/files/etc/dinit.d/xdm b/files/etc/dinit.d/xdm
@@ -0,0 +1,4 @@
+type = process
+command = /usr/bin/xdm -nodaemon
+depends-on = system
+restart = true
diff --git a/files/usr/bin/arch-chroot b/files/usr/bin/arch-chroot
@@ -0,0 +1,290 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+shopt -s extglob
+
+use_systemd=0
+unshare=0
+keepresolvconf=0
+
+#!/hint/bash
+# SPDX-License-Identifier: GPL-2.0-only
+# shellcheck disable=SC2059 # $1 and $2 can contain the printf modifiers
+
+out() { printf "$1 $2\n" "${@:3}"; }
+error() { out "==> ERROR:" "$@"; } >&2
+warning() { out "==> WARNING:" "$@"; } >&2
+msg() { out "==>" "$@"; }
+die() { error "$@"; exit 1; }
+
+ignore_error() {
+ "$@" 2>/dev/null
+ return 0
+}
+
+chroot_add_mount() {
+ mount "$@" && CHROOT_ACTIVE_MOUNTS=("$2" "${CHROOT_ACTIVE_MOUNTS[@]}")
+}
+
+chroot_maybe_add_mount() {
+ local cond=$1; shift
+ if eval "$cond"; then
+ chroot_add_mount "$@"
+ fi
+}
+
+chroot_init() {
+ CHROOT_ACTIVE_MOUNTS=()
+ CHROOT_ACTIVE_LAZY=()
+ CHROOT_ACTIVE_FILES=()
+ [[ $(trap -p EXIT) ]] && die '(BUG): attempting to overwrite existing EXIT trap'
+ trap 'chroot_teardown' EXIT
+}
+
+chroot_teardown() {
+ if (( ${#CHROOT_ACTIVE_MOUNTS[@]} )); then
+ umount "${CHROOT_ACTIVE_MOUNTS[@]}"
+ fi
+ unset CHROOT_ACTIVE_MOUNTS
+
+ if (( ${#CHROOT_ACTIVE_LAZY[@]} )); then
+ umount --lazy "${CHROOT_ACTIVE_LAZY[@]}"
+ fi
+ unset CHROOT_ACTIVE_LAZY
+
+ if (( ${#CHROOT_ACTIVE_FILES[@]} )); then
+ rm "${CHROOT_ACTIVE_FILES[@]}"
+ fi
+ unset CHROOT_ACTIVE_FILES
+}
+
+chroot_setup() {
+ chroot_add_mount proc "$1/proc" -t proc -o nosuid,noexec,nodev &&
+ chroot_add_mount sys "$1/sys" -t sysfs -o nosuid,noexec,nodev,ro &&
+ ignore_error chroot_maybe_add_mount "[[ -d '$1/sys/firmware/efi/efivars' ]]" \
+ efivarfs "$1/sys/firmware/efi/efivars" -t efivarfs -o nosuid,noexec,nodev &&
+ chroot_add_mount udev "$1/dev" -t devtmpfs -o mode=0755,nosuid &&
+ chroot_add_mount devpts "$1/dev/pts" -t devpts -o mode=0620,gid=5,nosuid,noexec &&
+ chroot_add_mount shm "$1/dev/shm" -t tmpfs -o mode=1777,nosuid,nodev &&
+ chroot_add_mount /run "$1/run" --bind --make-private &&
+ chroot_add_mount tmp "$1/tmp" -t tmpfs -o mode=1777,strictatime,nodev,nosuid
+}
+
+chroot_add_mount_lazy() {
+ mount "$@" && CHROOT_ACTIVE_LAZY=("$2" "${CHROOT_ACTIVE_LAZY[@]}")
+}
+
+chroot_bind_device() {
+ touch "$2" && CHROOT_ACTIVE_FILES=("$2" "${CHROOT_ACTIVE_FILES[@]}")
+ chroot_add_mount "$1" "$2" --bind
+}
+
+chroot_add_link() {
+ ln -sf "$1" "$2" && CHROOT_ACTIVE_FILES=("$2" "${CHROOT_ACTIVE_FILES[@]}")
+}
+
+unshare_setup() {
+ chroot_add_mount_lazy "$1" "$1" --bind &&
+ chroot_add_mount proc "$1/proc" -t proc -o nosuid,noexec,nodev &&
+ chroot_add_mount_lazy /sys "$1/sys" --rbind &&
+ chroot_add_link /proc/self/fd "$1/dev/fd" &&
+ chroot_add_link /proc/self/fd/0 "$1/dev/stdin" &&
+ chroot_add_link /proc/self/fd/1 "$1/dev/stdout" &&
+ chroot_add_link /proc/self/fd/2 "$1/dev/stderr" &&
+ chroot_bind_device /dev/full "$1/dev/full" &&
+ chroot_bind_device /dev/null "$1/dev/null" &&
+ chroot_bind_device /dev/random "$1/dev/random" &&
+ chroot_bind_device /dev/tty "$1/dev/tty" &&
+ chroot_bind_device /dev/urandom "$1/dev/urandom" &&
+ chroot_bind_device /dev/zero "$1/dev/zero" &&
+ chroot_add_mount run "$1/run" -t tmpfs -o nosuid,nodev,mode=0755 &&
+ chroot_add_mount tmp "$1/tmp" -t tmpfs -o mode=1777,strictatime,nodev,nosuid
+}
+
+pid_unshare="unshare --fork --pid"
+mount_unshare="$pid_unshare --mount --map-auto --map-root-user --setuid 0 --setgid 0"
+
+# This outputs code for declaring all variables to stdout. For example, if
+# FOO=BAR, then running
+# declare -p FOO
+# will result in the output
+# declare -- FOO="bar"
+# This function may be used to re-declare all currently used variables and
+# functions in a new shell.
+declare_all() {
+ # Remove read-only variables to avoid warnings. Unfortunately, declare +r -p
+ # doesn't work like it looks like it should (declaring only read-write
+ # variables). However, declare -rp will print out read-only variables, which
+ # we can then use to remove those definitions.
+ declare -p | grep -Fvf <(declare -rp)
+ # Then declare functions
+ declare -pf
+}
+
+
+usage() {
+ cat <<EOF
+usage: ${0##*/} chroot-dir [command] [arguments...]
+
+ -h Print this help message
+ -S Perform chroot using systemd-run
+ -N Run in unshare mode as a regular user
+ -u <user>[:group] Specify non-root user and optional group to use
+ -r Do not change the resolv.conf within the chroot
+
+If 'command' is unspecified, ${0##*/} will launch /bin/bash.
+
+Note that when using arch-chroot, the target chroot directory *should* be a
+mountpoint. This ensures that tools such as pacman(8) or findmnt(8) have an
+accurate hierarchy of the mounted filesystems within the chroot.
+
+If your chroot target is not a mountpoint, you can bind mount the directory on
+itself to make it a mountpoint, i.e. 'mount --bind /your/chroot /your/chroot'.
+
+EOF
+}
+
+chroot_add_resolv_conf() {
+ local dest="$chrootdir/etc/resolv.conf"
+
+ # If we don't have a source resolv.conf file, there's nothing useful we can do.
+ [[ -e /etc/resolv.conf ]] || return 0
+
+ if [[ ! -e "$dest" && ! -L "$dest" ]]; then
+ # There may be no resolv.conf in the chroot. In this case, we'll just exit.
+ # The chroot environment must not be concerned with DNS resolution.
+ return 0
+ fi
+
+ chroot_add_mount /etc/resolv.conf "$dest" --bind -o X-mount.nocanonicalize=target
+}
+
+systemd_sanity_check() {
+ local systemd_ver
+
+ command -v systemd-run &>/dev/null || die 'systemd-run is not available'
+
+ IFS=' .-~^' read -r _ systemd_ver _ < <(SYSTEMD_COLORS=0 systemd-run --version)
+ (( systemd_ver >= 257 )) || die 'Unsupported systemd version: %s (requires >= 257)' "$systemd_ver"
+
+ [[ -d /run/systemd/system ]] || die 'System is not booted with systemd'
+}
+
+systemd_mode() {
+ local user=root group="" sd_args
+
+ systemd_sanity_check
+
+ # NB: we always have systemd spawn the service main process as root
+ # and call into setpriv later. The reason is two-fold:
+ # systemd resolves users using the host's passwd/groups database,
+ # while we want to resolve inside the chroot. Plus, setpriv
+ # does us a favor of clearing extraneous envvars from systemd,
+ # notably SYSTEMD_EXEC_PID which might confuse some programs.
+
+ if [[ $userspec ]]; then
+ IFS=':' read -r user group <<< "$userspec"
+ [[ $user ]] || die 'Invalid -u argument: %s' "$userspec"
+ fi
+
+ sd_args=(systemd-run --unit="arch-chroot-$$_$(systemd-escape --path "$chrootdir")"
+ --description="[arch-chroot] $chrootdir (as $user)"
+ --service-type=exec --collect
+ --pty --pipe --send-sighup
+ --expand-environment=no
+ -p RootDirectory="$chrootdir"
+ -p MountAPIVFS=yes
+ -p ProtectControlGroupsEx=private
+ -p BindLogSockets=no
+ -p BindReadOnlyPaths=/run/udev # https://github.com/archlinux/arch-install-scripts/pull/52
+ -p TemporaryFileSystem=/tmp
+ -p IgnoreSIGPIPE=no)
+
+ if ! [[ -t 0 && -t 1 ]]; then
+ sd_args+=(--quiet)
+ fi
+
+ sd_args+=(setpriv --reset-env --reuid="$user" --regid="${group:-"$user"}" --init-groups)
+
+ if [[ ! -v args ]]; then
+ args=(/bin/bash -i)
+ fi
+
+ "${sd_args[@]}" -- "${args[@]}"
+}
+
+offline_mode() {
+ local chroot_args=()
+
+ $setup "$chrootdir" || die "failed to setup chroot %s" "$chrootdir"
+
+ [[ $userspec ]] && chroot_args+=(--userspec "$userspec")
+
+ SHELL=/bin/bash SYSTEMD_IN_CHROOT=1 $pid_unshare chroot "${chroot_args[@]}" -- "$chrootdir" "${args[@]}"
+}
+
+arch-chroot() {
+ (( EUID == 0 )) || die 'This script must be run with root privileges'
+
+ [[ -d $chrootdir ]] || die "Can't create chroot on non-directory %s" "$chrootdir"
+
+ if ! mountpoint -q "$chrootdir"; then
+ warning "$chrootdir is not a mountpoint. This may have undesirable side effects."
+ fi
+
+ chroot_init
+ if (( ! keepresolvconf )); then
+ chroot_add_resolv_conf || die "failed to setup resolv.conf"
+ fi
+
+ if (( use_systemd )); then
+ systemd_mode
+ else
+ offline_mode
+ fi
+}
+
+while getopts ':hSNu:r' flag; do
+ case $flag in
+ h)
+ usage
+ exit 0
+ ;;
+ S)
+ use_systemd=1
+ ;;
+ N)
+ unshare=1
+ ;;
+ u)
+ userspec=$OPTARG
+ ;;
+ r)
+ keepresolvconf=1
+ ;;
+ :)
+ die '%s: option requires an argument -- '\''%s'\' "${0##*/}" "$OPTARG"
+ ;;
+ ?)
+ die '%s: invalid option -- '\''%s'\' "${0##*/}" "$OPTARG"
+ ;;
+ esac
+done
+shift $(( OPTIND - 1 ))
+
+(( $# )) || die 'No chroot directory specified'
+chrootdir=$1
+shift
+
+args=("$@")
+if (( unshare )); then
+ if (( use_systemd )); then
+ die 'systemd mode (-S) cannot be used in conjunction with unshare (-N)'
+ fi
+
+ setup=unshare_setup
+ $mount_unshare bash -c "$(declare_all); arch-chroot"
+else
+ setup=chroot_setup
+ arch-chroot
+fi
diff --git a/files/usr/lib/chamesle/foreground b/files/usr/lib/chamesle/foreground
@@ -0,0 +1,12 @@
+#!/bin/sh
+# foreground NAME ARGS...: crond, ntpd, syslogd or klogd in the foreground, busybox's or the real one; they spell it differently
+n=$1
+shift
+p=$(command -v "$n") || exit 127
+case $n:$(readlink -f "$p") in
+crond:*/busybox) exec "$p" -f "$@";;
+crond:*) exec "$p" -n "$@";;
+ntpd:*/busybox) exec "$p" -n "$@";;
+ntpd:*) exec "$p" -d "$@";;
+*) exec "$p" -n "$@";;
+esac
diff --git a/files/usr/sbin/dinitctl b/files/usr/sbin/dinitctl
@@ -0,0 +1,15 @@
+#!/bin/sh
+# dinitctl for the system's dinit. someone who is not root goes through doas, and where dinit is not running (a chroot,
+# a system being installed) enable and disable work on the files. -u or --user is left to a user's own dinit
+for a; do case $a in -u|--user|-p|--socket-path) exec /usr/bin/dinitctl "$@";; esac; done
+[ "$(id -u)" = 0 ] || exec doas /usr/bin/dinitctl "$@"
+if [ ! -S /run/dinitctl ]; then
+ for a; do
+ case $a in
+ enable|disable) exec /usr/bin/dinitctl --offline "$@";;
+ -*) ;;
+ *) echo "dinitctl: dinit is not running here, only enable and disable work" >&2; exit 1;;
+ esac
+ done
+fi
+exec /usr/bin/dinitctl "$@"
diff --git a/handbook/handbook.md b/handbook/handbook.md
@@ -63,7 +63,7 @@ Both are in `/etc/mag/repos`. A package is checked against the keys in `/etc/mag
| directory | what is in it |
|-----------|---------------|
-| `system/` | `tools/` (`chamesle-bootstrap`, `chamesle-chroot`, `chamesle-disk`, `chamesle-boot`, and `mkapk`, `mkrepo`, `mkpkgs` for the repo), `files/` (init, rc and the services), `pkg/`, `keys/`, `iso/`, this handbook |
+| `system/` | `tools/` (`chamesle-bootstrap`, `chamesle-disk`, `chamesle-boot`, and `mkapk`, `mkrepo`, `mkpkgs` for the repo), `files/` (init, rc and the services), `pkg/`, `keys/`, `iso/`, this handbook |
| `mag/` | `mag.c`, `c.h`, `build.sh` |
| `rifle/` | `rifle.c`, `build.sh`, `tests/run.sh` |
@@ -198,16 +198,16 @@ Packages after the target go in too. A ThinkPad with Intel wireless and graphics
chamesle-bootstrap -n t480 -f linux-firmware-intel /mnt vim
What `chamesle-base` brings: dinit and the files of chapter 6, mag, rifle, mksh, busybox for the tools rifle does not
-have, `agetty`, eudev, kmod, dhcpcd, e2fsprogs and curl.
+have, bash, `agetty`, eudev, kmod, dhcpcd, e2fsprogs, curl and `arch-chroot`.
### 3.4 Working inside the new root
- chamesle-chroot /mnt
- chamesle-chroot /mnt passwd root
+ arch-chroot /mnt
+ arch-chroot /mnt passwd root
-It mounts `proc`, `sys`, `dev`, `dev/pts` and a tmpfs on `run` under the directory, copies `/etc/resolv.conf` into it, runs
-`chroot` with an empty environment (`HOME=/root`, `TERM`, `PATH`) and takes the mounts away again when the command ends.
-Without a command it starts `/bin/mksh -l`. Inside, `mag install name` works as on the finished system.
+`arch-chroot` is Arch's, the same script. It mounts `proc`, `sys`, `dev`, `dev/pts`, `dev/shm`, `run` and `tmp` under
+the directory, puts the live system's `/etc/resolv.conf` in it, and takes the mounts away again when the command ends.
+Without a command it starts bash. Inside, `mag install name` works as on the finished system.
### 3.5 fstab
@@ -232,7 +232,7 @@ A root on ZFS gets no root line.
The host name is in `/mnt/etc/hostname`, from `-n`. Set the root password:
- chamesle-chroot /mnt passwd root
+ arch-chroot /mnt passwd root
The hash goes into `/etc/shadow`. The login shell of root is mksh.
@@ -279,12 +279,12 @@ A root on ZFS names the dataset; the initramfs needs the zfs module, which is se
Install limine into the new root, and use its files, not the ones of the live system; the two can differ in version, and
limine's BIOS stage only works with a `limine-bios.sys` of its own version:
- chamesle-chroot /mnt mag install limine
+ arch-chroot /mnt mag install limine
#### BIOS
cp /mnt/usr/share/limine/limine-bios.sys /mnt/boot/
- chamesle-chroot /mnt limine bios-install /dev/sda
+ arch-chroot /mnt limine bios-install /dev/sda
`limine bios-install` writes the loader to the start of the disk and into the BIOS boot partition, which a GPT disk
needs (3.1). `limine-bios.sys` on the FAT partition is the part it loads.
@@ -569,9 +569,10 @@ boot fails, dinit starts a root shell too.
### 6.2 Services
-A service is a file in `/etc/dinit.d` named after it. The base set has `dbus`, `dhcpcd`, `elogind`, `gdm`, `iwd`,
-`NetworkManager`, `wpa_supplicant` and the logins `tty1` to `tty6` and `ttyS0`, for when those packages are installed.
-`dinitctl` does the rest:
+A service is a file in `/etc/dinit.d` named after it. The base set has one for every common daemon, ready for when its
+package is installed: `dbus`, `elogind`, `seatd`, `dhcpcd`, `iwd`, `wpa_supplicant`, `NetworkManager`, `connmand`,
+`lightdm`, `sddm`, `gdm`, `xdm`, `greetd`, `sshd`, `chronyd`, `ntpd`, `crond`, `syslogd`, `klogd`, `acpid`, `cupsd`,
+`bluetoothd`, `avahi-daemon`, and the logins `tty1` to `tty6` and `ttyS0`. `dinitctl` does the rest:
dinitctl list every service that is loaded, and its state
dinitctl start iwd
@@ -582,7 +583,8 @@ A service is a file in `/etc/dinit.d` named after it. The base set has `dbus`, `
dinitctl disable dhcpcd not at boot any more
`enable` and `disable` make and remove a link in `/etc/dinit.d/boot.d`; that directory is the list of what starts
-at boot. A fresh install has `dhcpcd` and `tty1` to `tty6` in it. `service NAME start` and the rest still work and
+at boot. A fresh install has `dhcpcd` and `tty1` to `tty6` in it. As a user in `wheel`, `dinitctl` asks for your
+password through doas. Where dinit is not running, in `arch-chroot /mnt` for one, `enable` and `disable` still work. `service NAME start` and the rest still work and
run `dinitctl`.
A service whose process dies is started again, unless it dies over and over in a few seconds; then dinit gives up and
@@ -780,7 +782,7 @@ The live ISO has its own initramfs, made by `iso/mkinitramfs`, which mounts the
The ISO is a live system to work from. It boots on BIOS and UEFI machines with limine, from a disc or a stick, logs in as
root on every tty and has
-* mag, the keys and the repos, and `chamesle-bootstrap`, `chamesle-chroot`, `chamesle-disk`, `chamesle-boot`
+* mag, the keys and the repos, and `chamesle-bootstrap`, `chamesle-disk`, `chamesle-boot`, `arch-chroot`
* the disk tools: `cfdisk`, `sfdisk`, `lsblk`, `blkid`, `mkfs.ext4`, `mkfs.fat`, `zpool`, `zfs`, `limine`
* the network: `dhcpcd`, `iwd` with `iwctl`, `wpa_supplicant`, `curl`
* the Intel wireless firmware, vim, less, and this handbook in `/usr/share/doc/chamesle/handbook.md`
@@ -984,7 +986,6 @@ X writes `~/.local/share/xorg/Xorg.0.log`; `grep EE` in it shows the errors.
| path | what |
|------|------|
| `system/tools/chamesle-bootstrap` | puts the base into a root with mag |
-| `system/tools/chamesle-chroot` | chroot with the pseudo file systems mounted |
| `system/tools/chamesle-boot` | limine.conf and limine for the system in a directory |
| `system/tools/chamesle-disk` | cfdisk, vfat boot partition, ZFS root, mounted on `/mnt` |
| `system/tools/mkapk`, `mkrepo`, `mkpkgs` | packages, signed indexes, Chamesle's own repo |
@@ -1001,7 +1002,7 @@ X writes `~/.local/share/xorg/Xorg.0.log`; `grep EE` in it shows the errors.
### 11.3 Commands in short
chamesle-bootstrap [-a ARCH] [-n HOSTNAME] [-k KERNEL] [-f FIRMWARE] TARGET [PACKAGE]...
- chamesle-chroot DIR [COMMAND...]
+ arch-chroot DIR [COMMAND...]
chamesle-disk DISK
chamesle-boot [DIR]
mag [-nf] update|install|build|remove|upgrade|autoremove|list|info|search|files|owns|deps|rdeps|fetch
diff --git a/tools/chamesle-boot b/tools/chamesle-boot
@@ -27,9 +27,9 @@ if [ "$rootfs" = zfs ]; then
conf=$t/etc/mkinitfs/mkinitfs.conf
if ! grep -q '^features=.*zfs' "$conf"; then
echo "adding zfs to the initramfs"
- chamesle-chroot "$t" mag install zfs $(for k in $kernels; do echo zfs-$k; done) || die "mag install zfs failed"
+ arch-chroot "$t" mag install zfs $(for k in $kernels; do echo zfs-$k; done) || die "mag install zfs failed"
sed -i '/^features=/s/"$/ zfs"/' "$conf"
- for m in "$t"/lib/modules/*; do chamesle-chroot "$t" mkinitfs "${m##*/}" || die "mkinitfs failed"; done
+ for m in "$t"/lib/modules/*; do arch-chroot "$t" mkinitfs "${m##*/}" || die "mkinitfs failed"; done
fi
else
uuid=$(blkid -s UUID -o value "$rootdev") || die "no UUID for $rootdev"
@@ -55,7 +55,7 @@ G
exit 0
fi
-[ -e "$t/usr/share/limine/limine-bios.sys" ] || chamesle-chroot "$t" mag install limine || die "mag install limine failed"
+[ -e "$t/usr/share/limine/limine-bios.sys" ] || arch-chroot "$t" mag install limine || die "mag install limine failed"
c=$t/boot/limine.conf
[ -e "$c" ] && mv "$c" "$c.old" && echo "the old limine.conf is limine.conf.old"
@@ -78,6 +78,6 @@ disk=/dev/$(lsblk -no PKNAME "$bootdev" | head -1)
if [ "$(lsblk -dno PTTYPE "$disk")" = gpt ] && ! lsblk -no PARTTYPE "$disk" | grep -qi 21686148-6449-6e6f-744e-656564454649; then
echo "BIOS: $disk is GPT with no BIOS boot partition, so it boots by UEFI only"
else
- chamesle-chroot "$t" limine bios-install "$disk" >/dev/null || die "limine bios-install $disk failed"
+ arch-chroot "$t" limine bios-install "$disk" >/dev/null || die "limine bios-install $disk failed"
echo "BIOS: limine is on $disk"
fi
diff --git a/tools/chamesle-chroot b/tools/chamesle-chroot
@@ -1,34 +0,0 @@
-#!/bin/sh
-# chamesle-chroot DIR [COMMAND...]: chroot into DIR with /proc, /sys, /dev and /run in place, and take them away again afterwards.
-# chamesle-chroot /mnt
-# chamesle-chroot /mnt mag install vim
-[ $# -ge 1 ] || { echo "usage: chamesle-chroot DIR [COMMAND...]" >&2; exit 2; }
-dir=$1
-shift
-[ -d "$dir" ] || { echo "chamesle-chroot: $dir is not a directory" >&2; exit 1; }
-[ "$(id -u)" = 0 ] || { echo "chamesle-chroot: needs root" >&2; exit 1; }
-[ $# -gt 0 ] || set -- /bin/mksh -l
-
-mounted=
-cleanup() {
- for m in $mounted; do umount "$dir/$m" 2>/dev/null || umount -l "$dir/$m"; done
-}
-trap cleanup EXIT
-trap 'exit 1' HUP INT TERM
-
-# mnt PLACE MOUNT-ARGS...: mounts on $dir/PLACE, remembering it so cleanup undoes the last one first
-mnt() {
- place=$1
- shift
- mkdir -p "$dir/$place"
- mount "$@" "$dir/$place" || { echo "chamesle-chroot: cannot mount $dir/$place" >&2; exit 1; }
- mounted="$place $mounted"
-}
-
-mnt proc -t proc proc
-mnt sys -t sysfs sysfs
-mnt dev --bind /dev
-mnt dev/pts --bind /dev/pts
-mnt run -t tmpfs tmpfs
-[ -f /etc/resolv.conf ] && cp /etc/resolv.conf "$dir/etc/resolv.conf"
-env -i HOME=/root TERM="${TERM:-linux}" PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin chroot "$dir" "$@"
diff --git a/tools/mkpkgs b/tools/mkpkgs
@@ -16,7 +16,7 @@ mkdir -p "$tmp/mag/usr/bin"
install -m755 "$MAG" "$tmp/mag/usr/bin/mag"
mkapk -n mag -v "$("$MAG" --version | cut -d' ' -f2)" -d "the package manager" "$tmp/mag"
-deps="alpine-baselayout busybox busybox-binsh busybox-suid doas mksh agetty dinit dinit-shutdown eudev kmod dhcpcd e2fsprogs dosfstools curl mag"
+deps="alpine-baselayout busybox busybox-binsh busybox-suid doas mksh agetty bash mount umount findmnt util-linux-misc dinit dinit-shutdown eudev kmod dhcpcd e2fsprogs dosfstools curl mag"
if [ -n "$RIFLE" ]; then
mkdir -p "$tmp/rifle/usr/bin"
install -m755 "$RIFLE" "$tmp/rifle/usr/bin/rifle"
@@ -33,7 +33,7 @@ cp "$here/keys/"*.pub "$b/etc/mag/keys/"
ln -s ../mag/keys "$b/etc/apk/keys"
cp "$here/pkg/chamesle-base/repos" "$b/etc/mag/repos"
cp "$here/pkg/chamesle-base/os-release" "$here/pkg/chamesle-base/issue" "$b/etc/"
-for t in chamesle-bootstrap chamesle-chroot chamesle-disk chamesle-boot; do install -m755 "$here/tools/$t" "$b/usr/bin/$t"; done
+for t in chamesle-bootstrap chamesle-disk chamesle-boot; do install -m755 "$here/tools/$t" "$b/usr/bin/$t"; done
cp "$here/handbook/handbook.md" "$b/usr/share/doc/chamesle/handbook.md"
mkapk -n chamesle-base -v "$(date +%Y%m%d)-r${REL:-0}" -d "dinit's services, the files in /etc and the tools of Chamesle" \
-D "$deps" -s "$here/pkg/chamesle-base" "$b"