From d31c5f60ad289f23a1062c85bcbc13dd5a459892 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 24 Jun 2025 20:18:39 -0400 Subject: [PATCH 1/3] host: add tmux, drop into tmux by default on console --- Containerfile | 6 ++++++ src/host/rootfs/etc/inittab | 5 +++-- src/host/rootfs/etc/profile | 1 + src/host/rootfs/etc/tmux.conf | 36 +++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/host/rootfs/etc/tmux.conf diff --git a/Containerfile b/Containerfile index 78dda97..932b008 100644 --- a/Containerfile +++ b/Containerfile @@ -71,6 +71,9 @@ FROM stagex/user-usbmuxd@sha256:90f687d2368328b76141badc382a21873a5b44d4ddccf851 FROM stagex/user-socat@sha256:990a70ae13462d8ba0a925fe959dd83070cbecdb3f91ff145caca5232171f3b8 AS user-socat FROM stagex/user-dhcpcd@sha256:60bd86d9e2fcb6341c1efaeda5d786b63ff92e9d0c729cd8f634a20ff54ee71e AS user-dhcpcd FROM stagex/user-guestctl@sha256:95ad9e34a003c7d1d01f5d427b5f79d2430f6e6634debde8e54f9a6f08749704 AS user-guestctl +FROM stagex/core-ncurses@sha256:6602a073bf9a408d1ed7c20ccc98fca974cd307fb8d1da6381fbca684a08169c AS core-ncurses +FROM stagex/user-libevent@sha256:1ba6f006f49cc327a5da84caeb0de7088da844f8021c5902fe387cd379732aec AS user-libevent +FROM stagex/user-tmux@sha256:57b63a27169a333edb073f1c6646a37ec6a9eee02ffdbc494a52bd6d670fc576 AS user-tmux FROM scratch AS base ARG VERSION development @@ -247,6 +250,9 @@ COPY --from=user-libzbar . initramfs COPY --from=user-keyfork . initramfs COPY --from=user-icepick . initramfs COPY --from=user-guestctl . initramfs +COPY --from=user-libevent . initramfs +COPY --from=core-ncurses . initramfs +COPY --from=user-tmux . initramfs COPY src/host/rootfs/ initramfs COPY <<-EOF initramfs/etc/environment export VERSION="$VERSION" diff --git a/src/host/rootfs/etc/inittab b/src/host/rootfs/etc/inittab index 56b8725..0c35acd 100644 --- a/src/host/rootfs/etc/inittab +++ b/src/host/rootfs/etc/inittab @@ -10,6 +10,7 @@ # Startup the system ::sysinit:/bin/mount -t devtmpfs devtmpfs /dev ::sysinit:/bin/mkdir -p /proc /run /dev/pts /dev/shm /sys +::sysinit:/bin/mount -t devpts devpts /dev/pts ::sysinit:/bin/mount -t sysfs sysfs /sys ::sysinit:/bin/mount -t proc proc /proc ::sysinit:/bin/mount -o remount,rw / @@ -21,8 +22,8 @@ null::sysinit:/bin/ln -sf /proc/self/fd/2 /dev/stderr # now run any rc scripts ::sysinit:/etc/init.d/rcS -# Put shells on the serial terminal and console -console::respawn:-/bin/bash +# Put a shell on serial and tmux on console +console::respawn:-/bin/bash -l -c /bin/tmux ttyS0::respawn:-/bin/bash # Stuff to do for the 3-finger salute diff --git a/src/host/rootfs/etc/profile b/src/host/rootfs/etc/profile index b3ae715..726b124 100644 --- a/src/host/rootfs/etc/profile +++ b/src/host/rootfs/etc/profile @@ -1,4 +1,5 @@ export EDITOR=/bin/vi +export SHELL=/bin/bash export PATH="/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin" export PS1="[\h \t] \\$ " export GNUPGHOME=/.gnupg diff --git a/src/host/rootfs/etc/tmux.conf b/src/host/rootfs/etc/tmux.conf new file mode 100644 index 0000000..cab552c --- /dev/null +++ b/src/host/rootfs/etc/tmux.conf @@ -0,0 +1,36 @@ +# Zero-based indexing is sure great in programming languages, +# but not so much in terminal multiplexers where that zero is +# all the way on the other side of the keyboard. +set-option -g base-index 1 + +set-option -g status on +set-option -g status-interval 1 + +# We should not have more than one session, but it's still possible. +# Therefore... +set-option -g status-left "[#S] " + +# Just so we can use `-ag` properly later +set-option -g status-right "" + +# The current power battery level +set-option -ag status-right '#(test -d /sys/class/power_supply/BAT0 && printf " [%%s%%%%]" "$(cat /sys/class/power_supply/BAT0/capacity)")' + +# Current date and time, in case it's relevant, and has drifted +set-option -ag status-right " [%Y-%m-%d %H:%M:%S]" + +# because cyan on black is cool, and pops out +set-option -g status-style "bg=color0 fg=color6" +set-option -g status-position bottom + +# we don't have much screen space, let's limit what's displayed +set-window-option -g window-status-bell-style "bold" +set-window-option -g window-status-current-format "#I:#W" +set-window-option -g window-status-format "#I:#W" + +# our "focused" window and pane is the brighter one +set-window-option -g window-status-style "fg=color6" +set-window-option -g window-status-current-style "fg=color14" +set-option -g pane-border-style "fg=color6" +set-option -g pane-active-border-style "fg=color14" +set-option -g message-style "fg=color6 bg=color0" From a372b606d00054bdee175c1aaf0c49524c76af86 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 25 Jun 2025 03:02:02 -0400 Subject: [PATCH 2/3] host/etc/profile: specify TERM=linux-16color when TERM like linux --- src/host/rootfs/etc/profile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/host/rootfs/etc/profile b/src/host/rootfs/etc/profile index 726b124..cb41b5e 100644 --- a/src/host/rootfs/etc/profile +++ b/src/host/rootfs/etc/profile @@ -1,3 +1,8 @@ +case "$TERM" in + linux|linux-*) + export TERM=linux-16color + ;; +esac export EDITOR=/bin/vi export SHELL=/bin/bash export PATH="/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin" From fc2dc900cca6cb0bf47629575787a4314d860378 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 25 Jun 2025 17:21:46 -0400 Subject: [PATCH 3/3] Makefile: add system-vm target and GUI=true option --- Makefile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Makefile b/Makefile index 5f35df0..6e00ce6 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ GIT_AUTHOR := $(shell git log -1 --format=%an) GIT_PUBKEY := $(shell git log -1 --format=%GK) GIT_TIMESTAMP := $(shell git log -1 --format=%cd --date=iso) EFI := false +GUI := false ,:=, export @@ -51,6 +52,32 @@ out/dev-shell.digest: Containerfile | out shell: out/dev-shell.digest docker run -it $(shell cat $<) /bin/sh +.PHONY: system-vm +system-vm: + qemu-system-x86_64 \ + -m 4G \ + -machine q35,kernel-irqchip=split \ + -usb \ + -device sdhci-pci \ + -device sd-card,drive=external \ + -drive id=external,if=none,format=raw,file=out/sdcard.img \ + -device usb-storage,drive=usbdrive \ + -device intel-iommu,intremap=on \ + -netdev user,id=net0 \ + -device e1000,netdev=net0 \ + -chardev socket,path=out/qga.sock,server=on,wait=off,id=qga0 \ + -device virtio-serial \ + -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \ + $(if $(filter $(EFI),true) ,\ + -bios /usr/share/ovmf/OVMF.fd \ + -drive id=boot$(,)if=virtio$(,)format=raw$(,)file=out/airgap.iso \ + ,\ + -drive id=usbdrive,if=none,format=raw,file=out/airgap.iso \ + -boot order=c \ + ) \ + $(if (,$(wildcard /dev/kvm)),-cpu host --accel kvm,) \ + $(if $(filter $(GUI),true),,-nographic) + .PHONY: vm vm: out/dev-shell.digest out/airgap.iso out/sdcard.img docker run -it -v ./out:/out $(shell cat $<) sh -c "\