From 99c9256e89daa9c64fa2f3e416ee5949a380820e Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Fri, 13 Dec 2024 14:31:33 +0100 Subject: [PATCH] added autoenv --- README.md | 10 +++++++++ .../board/v86/rootfs_overlay/etc/inittab | 4 ++-- .../board/v86/rootfs_overlay/etc/profile.sh | 16 ++++---------- .../board/v86/rootfs_overlay/etc/profile.xrsh | 7 +++---- .../root/.config/autoenv/package | 1 + .../root/.config/autoenv/prompt_cd | 1 + .../board/v86/rootfs_overlay/root/.env | 1 + .../board/v86/rootfs_overlay/root/.profile | 21 ++++++++++++------- .../board/v86/rootfs_overlay/root/bin/.env | 1 + .../v86/rootfs_overlay/root/bin/annotate | 3 +++ .../board/v86/rootfs_overlay/root/fs/.env | 1 + .../board/v86/rootfs_overlay/root/hook.d/.env | 2 ++ .../application/zip/extract_and_run.sh | 4 ++-- .../hook.d/mimetype/text/detect.zip-package | 11 ++++++++++ .../board/v86/rootfs_overlay/root/manual.md | 12 ++++++++++- 15 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/.config/autoenv/package create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/.config/autoenv/prompt_cd create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/.env create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/bin/.env create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/bin/annotate create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/fs/.env create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/.env create mode 100755 buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.zip-package diff --git a/README.md b/README.md index 5393ab5..3be27b1 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,14 @@ filesystem overlay, and scripts necessary to build our distribution. ## Running ISO via qemu +first enable the vga console: + +```bash +echo "console::respawn:-/bin/sh # vga console" >> rootfs/etc/inittab +``` + +then run qemu: + ``` qemu-system-i386 -cdrom dist/v86-linux.iso ``` @@ -220,3 +228,5 @@ CONFIG_VIRTIO_PCI=y Now run `make` When it finishes, the built image is in `./output/images`. + +> to debug (gdb access) uncomment the debug-section in `buildroot_v86/configs/v86_defconfig`, run `make` and then `./run.sh` diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/inittab b/buildroot-v86/board/v86/rootfs_overlay/etc/inittab index e4a4170..8a3f477 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/etc/inittab +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/inittab @@ -26,8 +26,8 @@ ::sysinit:/etc/init.d/rcS # Put a getty on the serial port -#console::respawn:/sbin/getty -L console 0 vt100 # GENERIC_SERIAL -console::respawn:-/bin/sh # vga console +console::respawn:/sbin/getty -L console 0 vt100 # GENERIC_SERIAL +#console::respawn:-/bin/sh # vga console # Auto-login as root on ttyS0 ::respawn:/sbin/getty ttyS0 38400 xterm -n -l /bin/sh diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh index eb34d2e..92a3954 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh @@ -22,24 +22,16 @@ alert(){ confirm(){ test -z "$1" && { echo "usage: confirm "; return 0; } - if test -n "$BROWSER"; then - jsh confirm "$1" - else - read -p "$(printf "\033[0m")[?] $1 [y/n] $(printf "\033[0m")" y - fi - test $y = y && echo true && return 0 - test $y = y || echo false + read -p "$(printf "\033[0m")[?] $1 [y/n] $(printf "\033[0m")" y + test $y = "y" && echo true && return 0 + test $y = "y" || echo false hook confirm $1 $y } prompt(){ test -z "$1" && { echo "usage: prompt [answer_default]"; return 0; } test -n "$2" && answer="[$2] " && answer_fallback="$2" - if test -n "$BROWSER"; then - jsh prompt "$1" "$answer_fallback" - else - read -p "$(printf "\033[0m")[?] $1: $answer $(printf "\033[0m")" answer - fi + read -p "$(printf "\033[0m")[?] $1: $answer $(printf "\033[0m")" answer test -z "$answer" && answer="$answer_fallback" echo "$answer" hook prompt $1 $answer diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh index c8c9d6a..8142976 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh @@ -51,8 +51,8 @@ test -d /dev/browser || { } setup_listen_homedir(){ - sleep 4 # wait for inode of /mnt/root to become live (due to move_root_to_9pfs) - /mnt/root/bin/watchfs & + sleep 4 + /root/bin/watchfs & } setup_mounts(){ @@ -67,8 +67,7 @@ test -d /dev/browser || { setup_links setup_network setup_overlayfs + setup_listen_homedir & setup_incoming_cmds & - setup_listen_homedir setup_mounts - cat /etc/motd } diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/.config/autoenv/package b/buildroot-v86/board/v86/rootfs_overlay/root/.config/autoenv/package new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/.config/autoenv/package @@ -0,0 +1 @@ +1 diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/.config/autoenv/prompt_cd b/buildroot-v86/board/v86/rootfs_overlay/root/.config/autoenv/prompt_cd new file mode 100644 index 0000000..573541a --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/.config/autoenv/prompt_cd @@ -0,0 +1 @@ +0 diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/.env b/buildroot-v86/board/v86/rootfs_overlay/root/.env new file mode 100644 index 0000000..e3b4d57 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/.env @@ -0,0 +1 @@ +echo "$(pwd): the project root-directory" diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/.profile b/buildroot-v86/board/v86/rootfs_overlay/root/.profile index 8d06047..f1b576a 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/root/.profile +++ b/buildroot-v86/board/v86/rootfs_overlay/root/.profile @@ -8,14 +8,19 @@ alias curl="wget -q -O - " alias make="mim" # minimalist autoenv version [https://github.com/hyperupcall/autoenv] -#cd(){ -# test -f $(pwd)/.env.leave && source $(pwd)/.env.leave # cleanup environment -# command cd ${1:+"$@"} && { -# hook cd "$@" -# test -f $(pwd)/.env && source $(pwd)/.env # setup environment / run scripts e.g. -# ls # list directories -# } -#} +cd(){ + test -f $(pwd)/.env.leave && source $(pwd)/.env.leave # cleanup environment + command cd ${1:+"$@"} && { + hook cd "$@" + test -f $(pwd)/.env && { # setup environment / run scripts e.g. + test "$(cat ~/.config/autoenv/prompt_cd)" = 1 && { + if "$(confirm ".env detected, execute?")" = false; then return 0; fi + } + source $(pwd)/.env + } + ls # list directories + } +} # start index.js if /dev/browser/js filesize is not great than 0 if [ ! -s /dev/browser/js ]; then diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/.env b/buildroot-v86/board/v86/rootfs_overlay/root/bin/.env new file mode 100644 index 0000000..d4609af --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/.env @@ -0,0 +1 @@ +echo "$(pwd): projectspecific cli utilities" diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/bin/annotate b/buildroot-v86/board/v86/rootfs_overlay/root/bin/annotate new file mode 100755 index 0000000..9f7168a --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/bin/annotate @@ -0,0 +1,3 @@ +#!/bin/sh +# simple directory annotator [via autoenv] +echo "echo \"$(pwd): $*\"" >> .env diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/fs/.env b/buildroot-v86/board/v86/rootfs_overlay/root/fs/.env new file mode 100644 index 0000000..ed3311a --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/fs/.env @@ -0,0 +1 @@ +echo "$(pwd): 'fusescript' filesystems https://codeberg.org/coderofsalvation/fusescript" diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/.env b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/.env new file mode 100644 index 0000000..db871fb --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/.env @@ -0,0 +1,2 @@ +echo "$(pwd): polyglot hooks https://xrsh.isvery.ninja/#Unixy%20event%20hooks" + diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/application/zip/extract_and_run.sh b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/application/zip/extract_and_run.sh index 8d8fb5c..37f4677 100755 --- a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/application/zip/extract_and_run.sh +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/application/zip/extract_and_run.sh @@ -9,8 +9,8 @@ mkdir -p "/root/$dir" cd "/root/$dir" unzip "$file" -test -x .env && { +test -f .env && test "$(cat ~/.config/autoenv/package)" = 1 && { logger "$0: detected $(pwd)/.env [autoenv]" logger "$0: running $(pwd)/.env" - source .env + sh .env } diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.zip-package b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.zip-package new file mode 100755 index 0000000..657bdfc --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/hook.d/mimetype/text/detect.zip-package @@ -0,0 +1,11 @@ +#!/bin/sh +# this detects when a zip-url is copy/pasted to the clipboard +# and forwards it the zip mimetype hook +test -f /etc/profile.sh && source /etc/profile.sh +file="$1" + +grep -E '^http.*\.zip$' "$file" &>/dev/null && { + file="$(cat $file)" + zip="${file/.*\/\//}" + wget "$zip" && hook clipboard $(pwd)/$(basename "$zip") application/zip +} diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/manual.md b/buildroot-v86/board/v86/rootfs_overlay/root/manual.md index d72ac4c..4f2e9f4 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/root/manual.md +++ b/buildroot-v86/board/v86/rootfs_overlay/root/manual.md @@ -111,7 +111,17 @@ It can be loaded in various ways into [your own instance of] https://xrsh.isvery The package follows the popular `autoenv`-paradigm (a file called `.env` is automatically executed). Currently, '.env' links to 'bin/app.sh', but there are also other scriptinglanguages it could link to as well (see bin-folder). -> see example package at https://xrsh.isvery.ninja/package.zip +> see example package at https://xrsh.isvery.ninja/package.zip, and an filesystem overlay-zip +> at https://xrsh.isvery.ninja/package.overlayfs.zip + +# Autoenv (.env) + +When a directory contains an .env-file, it is automatically sourced. + +* run echo 0 > ~/.config/autoenv/package to disable auto-execution of zip-packages +* run echo 1 > ~/.config/autoenv/prompt_cd to trigger a confirmation when cd-ing into a directory. + +> TIP: check out `~/bin/annotate` to annotate directories using the power of autoenv # Hooks