consmirror.c: the BSD notice is replaced (Makronix's own file). Files with changes of other sessions pending are left for their commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
107 lines
4.0 KiB
Bash
Executable File
107 lines
4.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
#
|
|
# Assemble one device's system tree: the base's rootfs tar, the kernel
|
|
# modules, the files of base/<base>/rootfs, soc/<soc>/rootfs and
|
|
# soc/<soc>/rootfs-<base>, reboot2, fstab, the USB network profile and
|
|
# root's password. The tree is what /system/current holds
|
|
# (base/initramfs/init, docs/NEXT.md task B).
|
|
#
|
|
# Usage: assemble-rootfs.sh TREE ROOTFS.tar MODULESDIR RELEASE BASEDIR \
|
|
# SOCDIR BASE REBOOT2 PWHASH UUID MXRELEASE USERLAND
|
|
#
|
|
# TREE directory to fill; created if missing
|
|
# MODULESDIR the modules_install tree (…/lib/modules/<release>)
|
|
# RELEASE the kernel release those modules belong to
|
|
# BASEDIR base/<base> (its rootfs/ is copied over the tree)
|
|
# SOCDIR soc/<soc> (rootfs/ and rootfs-<base>/ likewise)
|
|
# REBOOT2 the static reboot2 binary (base/reboot2.c)
|
|
# PWHASH root's password as a SHA-512 crypt hash
|
|
# UUID the file system's UUID, written into /etc/fstab
|
|
# MXRELEASE the line for /etc/makronix-release, "Makronix 0.99.9
|
|
# Camouflage (unstable)" (tools/lib.sh makronix_version)
|
|
# USERLAND the NetBSD userland staged by tools/lib.sh userland_stage
|
|
# (may be empty): laid over the Void tree, so its programs
|
|
# replace Void's at the same paths
|
|
#
|
|
# Runs as root inside a user namespace (tools/mkrootimg.sh, mkroottar.sh):
|
|
# the tar's owners are 0 and must stay 0. Nothing here reads the host.
|
|
# POSIX sh; no root, no mount, no loop device.
|
|
|
|
set -eu
|
|
|
|
[ $# -eq 12 ] || {
|
|
echo "usage: $0 TREE ROOTFS.tar MODULESDIR RELEASE BASEDIR SOCDIR BASE REBOOT2 PWHASH UUID MXRELEASE USERLAND" >&2
|
|
exit 2
|
|
}
|
|
r=$1 tar=$2 mods=$3 release=$4 basedir=$5 socdir=$6 base=$7 \
|
|
reboot2=$8 pwhash=$9 uuid=${10} mxrelease=${11} userland=${12}
|
|
|
|
mkdir -p "$r"
|
|
tar -xpf "$tar" -C "$r"
|
|
|
|
# kernel modules; /lib is /usr/lib on both glibc bases
|
|
mkdir -p "$r/usr/lib/modules"
|
|
cp -R "$mods/$release" "$r/usr/lib/modules/"
|
|
|
|
# the NetBSD userland of mobile/userland over the Void packages: cat, kill,
|
|
# sleep ... and libstdc++ replace Void's files at the same paths
|
|
# (docs/NETBSD-USERLAND.md, A7); before base/ and soc/, whose files win
|
|
[ ! -d "$userland/usr" ] || cp -R "$userland/." "$r/"
|
|
|
|
# files of the base for every device (base/<base>/rootfs/), then of the SoC,
|
|
# then of the SoC for this base (a runit service on void):
|
|
# soc/<soc>/rootfs/ and soc/<soc>/rootfs-<base>/, copied over the tree as
|
|
# they are, symlinks included
|
|
for o in "$basedir/rootfs" "$socdir/rootfs" "$socdir/rootfs-$base"; do
|
|
[ ! -d "$o" ] || cp -R "$o/." "$r/"
|
|
done
|
|
|
|
# which Makronix this tree is: one line, the version the NetBSD side builds
|
|
# from (src/sys/conf/makronix-release, makronix-codename) and the channel
|
|
printf '%s\n' "$mxrelease" > "$r/etc/makronix-release"
|
|
|
|
mkdir -p "$r/usr/libexec/makronix"
|
|
cp "$reboot2" "$r/usr/libexec/makronix/reboot2"
|
|
chmod 755 "$r/usr/libexec/makronix/reboot2"
|
|
|
|
cat > "$r/etc/fstab" <<EOF
|
|
# <file system> <dir> <type> <options> <dump> <pass>
|
|
UUID=$uuid / ext4 defaults 0 1
|
|
tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
|
|
EOF
|
|
|
|
# USB network: the initramfs leaves the gadget up with 172.16.42.1 on usb0;
|
|
# this profile keeps that address once NetworkManager takes the interface,
|
|
# instead of a DHCP client on it.
|
|
d=$r/etc/NetworkManager/system-connections
|
|
mkdir -p "$d"
|
|
cat > "$d/usb0.nmconnection" <<EOF
|
|
[connection]
|
|
id=usb0
|
|
type=ethernet
|
|
interface-name=usb0
|
|
autoconnect=true
|
|
|
|
[ipv4]
|
|
method=manual
|
|
address1=172.16.42.1/24
|
|
|
|
[ipv6]
|
|
method=link-local
|
|
EOF
|
|
chmod 600 "$d/usb0.nmconnection"
|
|
|
|
# access: root with the password, on the console and over ssh
|
|
awk -F: -v OFS=: -v h="$pwhash" '$1 == "root" { $2 = h } { print }' \
|
|
"$r/etc/shadow" > "$r/etc/shadow.new"
|
|
cat "$r/etc/shadow.new" > "$r/etc/shadow"
|
|
rm "$r/etc/shadow.new"
|
|
mkdir -p "$r/etc/ssh/sshd_config.d"
|
|
printf 'PermitRootLogin yes\nPasswordAuthentication yes\n' \
|
|
> "$r/etc/ssh/sshd_config.d/makronix.conf"
|
|
|
|
# what the system calls itself, for tools/update-root.sh: the version of the
|
|
# tree is the file that names it, written by that tool (a file in the tree,
|
|
# not a runtime value)
|