From 2222061c0ba11f3363ccfd58d79312ea8578a565 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Wed, 11 Sep 2024 14:58:31 +0200 Subject: [PATCH] main: work in progress [might break] --- .gitignore | 1 - README.md | 10 +++ build.sh | 14 ++++- .../board/v86/rootfs_overlay/etc/motd | 16 +++++ .../board/v86/rootfs_overlay/etc/profile | 45 +++++++++++++ .../board/v86/rootfs_overlay/etc/profile.js | 6 ++ .../board/v86/rootfs_overlay/etc/profile.sh | 57 +++++++++++++++++ .../board/v86/rootfs_overlay/etc/profile.xrsh | 63 +++++++++++++++++++ .../board/v86/rootfs_overlay/root/.screenrc | 43 +++++++++++++ .../board/v86/rootfs_overlay/root/foo | 1 + .../board/v86/rootfs_overlay/root/manual.md | 39 ++++++++++++ .../board/v86/rootfs_overlay/root/manual.txt | 1 + edit.sh | 1 + 13 files changed, 294 insertions(+), 3 deletions(-) create mode 100644 buildroot-v86/board/v86/rootfs_overlay/etc/motd create mode 100644 buildroot-v86/board/v86/rootfs_overlay/etc/profile create mode 100644 buildroot-v86/board/v86/rootfs_overlay/etc/profile.js create mode 100644 buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh create mode 100644 buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/.screenrc create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/foo create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/manual.md create mode 100644 buildroot-v86/board/v86/rootfs_overlay/root/manual.txt diff --git a/.gitignore b/.gitignore index 849ddff..e69de29 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +0,0 @@ -dist/ diff --git a/README.md b/README.md index 1dcc82c..2f49819 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,14 @@ We define a `v86` buildroot "board" via the following files and directories: If you need or want to update these config files, do the following: +## method 1 (auto-guide via shellscript) + +``` +$ ./build.sh --edit +``` + +## method 2 (manually) + ```bash $ make BR2_EXTERNAL=/buildroot-v86 v86_defconfig $ make menuconfig @@ -85,6 +93,8 @@ $ make savedefconfig $ make linux-menuconfig ... $ make linux-savedefconfig +$ mkdir output/legal-info && touch output/legal-info/{host-licenses,licenses,buildroot.config} +$ make ``` ## Configuration Notes diff --git a/build.sh b/build.sh index 5b11d10..4aa1e24 100755 --- a/build.sh +++ b/build.sh @@ -1,12 +1,22 @@ #!/usr/bin/env bash -docker build -t buildroot . +test "$1" = "--edit" && { + EDIT="-ti -v $PWD/edit.sh:/root/edit.sh --entrypoint bash" +} +#-v $PWD/cache:/root/buildroot-2021.02-rc2/output + + +test -d dist || mkdir dist +test -d cache || mkdir cache +rm -rf cache/* + +docker images | grep buildroot || docker build -t buildroot . docker run \ --rm \ --name build-v86 \ -v $PWD/dist:/build \ - -v $PWD/buildroot-v86/:/buildroot-v86 \ + -v $PWD/buildroot-v86/:/buildroot-v86 ${EDIT} \ buildroot echo "See ./dist for built ISO" diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/motd b/buildroot-v86/board/v86/rootfs_overlay/etc/motd new file mode 100644 index 0000000..8ed4fc0 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/motd @@ -0,0 +1,16 @@ + . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + . . ____ _____________ ________. ._. ._. . . . . . . . . + . . _\ \/ /\______ \/ _____// | \. . . . . . . . + . . _ \ / | _/\_____ \/ ~ \ . . . . . . . + _ _ / \ | | \/ \ Y / _ _ _ _ _ _ _ + . . /___/\ \ |____|_ /_______ /\___|_ /. . . . . . . . + . . . . . .\_/. . . . \/ . . . .\/ . . _ \/ . . . . . . . . + ▬▬▬▬ https://xrsh.isvery.ninja ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ + + Open, local-first, unix hackable & selfcontained XR apps. + + credits: NLnet | @nlnet@nlnet.nl https://nlnet.nl/project + all FOSS devs | copy.sh (v86) aframe.io (AFRAME) + Leon van Kammen | @lvk@mastodon.online + Fabien Benetou | @utopiah@mastodon.pirateparty.be + diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/profile b/buildroot-v86/board/v86/rootfs_overlay/etc/profile new file mode 100644 index 0000000..e5f5acb --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/profile @@ -0,0 +1,45 @@ +# source URL data from v86 (file created by v86 during boot) +test -f /etc/profile.browser && source /etc/profile.browser + +# source xrsh env +source /etc/profile.xrsh + +# source shell functions +source /etc/profile.sh + +# source js functions +./.profile.js + +## forward not-found commands to javascript (via jsh) +command_not_found_handle(){ + echo "[!] '$1' not found, did you mean $1(...) (javascript?)" + test -n "$ONBOARDING" && echo "[i] type 'help' for handy commands" + test -n "$ONBOARDING" || help +} + +help(){ + echo "" + echo 'TIPS' + echo '----' + echo 'js run ' "type 'js 'alert(\"hello\")'" + echo 'js console.log: ' "type 'console document.baseURI" + echo 'js function as cmd: ' "type 'alias $1=\"jsh $1\"' to run '$1 yo' as $1('yo')" + echo 'js inspect: ' "type 'js \"return document.baseURI\"'" + echo 'js console disable: ' "type 'echo 0 > /dev/browser/console.tty' to enable" + echo 'js capture console: ' "type 'tail -f /dev/browser/console'" + echo 'jsh<->sh hooks: ' "type 'chmod +x ~/hook.d/*/* && alert helloworld'" + echo 'include file into page' "type 'require '" + echo 'create AFRAME a-entity' "type 'a_entity [...]" + echo '' + echo 'type "man -l /root/manual.md" to read the full manual"' + ONBOARDING=1 +} + +resize +test $HOSTNAME = localhost || clear +cat /etc/motd +export PATH=$PATH:/etc:~/bin +export TERM=xterm-256color +export PS1="\n\[\033[38;5;57m\]x\[\033[38;5;93m\]r\[\033[38;5;129m\]s\[\033[38;5;165m\]h \[\033[38;5;201m\]# \[\033[0m\]" + +pidof screen || screen -T screen-256color -c /root/.screenrc diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.js b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.js new file mode 100644 index 0000000..794b8ca --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.js @@ -0,0 +1,6 @@ +#!/bin/js + +window.helloworld = function(){ + alert("hello world") + return "hello world" +} diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh new file mode 100644 index 0000000..f61432a --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.sh @@ -0,0 +1,57 @@ +hook(){ + test -z "$1" && { echo "usage: hook [args]"; return 0; } + cmd=$1 + shift + test -d ~/hook.d/$cmd && { + find ~/hook.d/$cmd/ -type f -executable | while read hook; do + { $hook "$@" || true; } | awk '{ gsub(/\/root\/\//,"",$1); $1 = sprintf("%-40s", $1)} 1' + done + } +} + +alert(){ + test -z "$1" && { echo "usage: alert <message>"; return 0; } + title=$1 + test -z "$1" || shift + msg="$*" + printf "%s \033[0m%s\n" "$title" "$msg" + hook alert $title "$msg" +} + +confirm(){ + test -z "$1" && { echo "usage: confirm <question>"; return 0; } + 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 <question> [answer_default]"; return 0; } + test -n "$2" && answer="[$2] " && answer_fallback="$2" + read -p "$(printf "\033[0m")[?] $1: $answer $(printf "\033[0m")" answer + test -z "$answer" && answer="$answer_fallback" + echo "$answer" + hook prompt $1 $answer +} + +console(){ + js 'return '$1 +} + +require(){ + file=$(basename "$1") + js '(async () => { + await AFRAME.utils.require({"'$file'": "'$1'"}) + })()' +} + +a_entity(){ + code="let el = document.createElement('a-entity')" + for i in "$@"; do + code="$code;\nel.setAttribute('$i','')\n"; + done + code="document.querySelector('a-scene').appendChild(el)" + echo "$code" + js "$code" +} diff --git a/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh new file mode 100644 index 0000000..2115b3f --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/etc/profile.xrsh @@ -0,0 +1,63 @@ +#!/bin/sh + +test -d /dev/browser || { + + setup_binaries(){ + for bin in /mnt/js* /mnt/v86pipe /mnt/xrsh; do + chmod +x $bin + ln -s $bin /bin/. + done + } + + setup_links(){ + ln -s /mnt/profile ~/.profile + ln -s /mnt/profile.js ~/.profile.js + ln -s /mnt/profile.browser ~/.profile.browser + ln -s /mnt/profile.sh ~/.profile.sh + ln -s /mnt/motd ~/.motd + ln -s ~/.profile.js ~/index.js + chmod +x ~/.profile.js + } + + setup_browser_dev(){ + mkdir -p /mnt/dev/browser + touch /mnt/dev/browser/js + touch /mnt/console.tty + ln -s /mnt/dev/browser /dev/browser + # emulator.write_file() only writes to /mnt/. :( + # should be in /proc, but v86 gives 'no such file or dir' when creating it there + ln -s /mnt/console.tty /dev/browser/console.tty + echo 1 > /dev/browser/console.tty + touch /mnt/console && ln -s /mnt/console /dev/browser/console + touch /mnt/index.html && ln -s /mnt/index.html /dev/browser/index.html + ln -s /dev/browser/index.html ~/index.html + + test -f /etc/profile && rm /etc/profile + ln -s /mnt/profile /etc/profile + } + + setup_hook_dirs(){ # see /mnt/hook for usage + mkdir ~/bin + mkdir -p ~/hook.d/alert + echo -e "#!/bin/sh\necho hook.d/alert/yo: yo \$*" > ~/hook.d/alert/yo + echo -e "#!/bin/js\nstr = \"hook.d/alert/yo.js yo \"+args.slice(1).join(' ')\nalert(str)\nreturn str" > ~/hook.d/alert/yo.js + echo -e "#!/usr/bin/env lua\nprint(\"hook.d/alert/yo.lua: yo \" .. arg[1])" > ~/hook.d/alert/yo.lua + echo -e "#!/usr/bin/awk -f\nBEGIN{\n\tprint \"hook.d/alert/yo.awk: yo \" ARGV[1]\n}" > ~/hook.d/alert/yo.awk + echo -e "#!/bin/sh\necho hello \$*" > ~/bin/hello + chmod +x ~/bin/hello + } + + setup_network(){ + test -n "$BROWSER" || return 0 + #mount -a + udhcpc 1>>/var/log/network.log 2>>/var/log/network.log & + echo 0 > /proc/sys/kernel/printk + } + + setup_binaries + setup_browser_dev + setup_hook_dirs + setup_links + setup_network + +} diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/.screenrc b/buildroot-v86/board/v86/rootfs_overlay/root/.screenrc new file mode 100644 index 0000000..7783caa --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/.screenrc @@ -0,0 +1,43 @@ +# look and feel +#caption always "%{i0}^{=}" #"%{= bb}%n%{+b w}%t %{= db} ${USER}@xrsh.iso" +#hardstatus alwayslastline "%-Lw%{= BW} %{=B}%t%{-B} %{-}%+Lw%<" +#caption always "%{= bb}%{+b w}%n %t %h %=%l %H %c" +hardstatus alwayslastline "%{= Bb}%-Lw%{= BW}%50> %t %{-}<" + +# skip the startup message +startup_message off + +# go to home dir +chdir + +# Automatically detach on hangup. +autodetach on + +# Change default scrollback value for new windows +defscrollback 10000 + +# start with visual bell as default +vbell on +vbell_msg "bell on %t (%n)" + + +bind x # Do not lock screen +bind ^x # Idem + +activity "activity in %t(%n)" + +shelltitle "xrsh" +shell -$SHELL + +# correct colors +attrcolor b ".I" # allow bold colors - necessary for some reason +termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm' # tell screen how to set colors. AB = background, AF=foreground +term xterm-256color +defbce on # use current bg color for erased chars + +# setup windows +screen -t jsconsole 0 tail -f /dev/browser/console +screen -t xrsh 1 +If you want it to start with a particular window active, you can add a line like the following: + +select 1 diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/foo b/buildroot-v86/board/v86/rootfs_overlay/root/foo new file mode 100644 index 0000000..5716ca5 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/foo @@ -0,0 +1 @@ +bar diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/manual.md b/buildroot-v86/board/v86/rootfs_overlay/root/manual.md new file mode 100644 index 0000000..b546ed5 --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/manual.md @@ -0,0 +1,39 @@ +XRSH Manual +=========== + +# Multiple terminals [GNU screen] + +## From the cmdline + +``` +xrsh # screen –DR # list of detached screen +xrsh # screen –r PID # attach detached screen ses­sion +xrsh # screen –dmS Myses # start a detached screen ses­sion +xrsh # screen –r MySes #attach screen ses­sion with name MySession +``` + +## Basics + +``` +ctrl a c -> create new window +ctrl a A -> set win­dow name +ctrl a w -> show all win­dow +ctrl a 1|2|3|… -> switch to win­dow n +ctrl a " -> choose win­dow +ctrl a ctrl a -> switch between win­dow +ctrl a d -> detach win­dow +ctrl a ? -> help +ctrl a [ -> start copy, move cur­sor to the copy loca­tion, press ENTER, select the chars, press ENTER to copy the selected char­ac­ters to the buffer +ctrl a ] -> paste from buffer +``` + +## Advanced + +``` +ctrl a S -> cre­ate split screen +ctrl a TAB -> switch between split screens +ctrl a Q -> Kill all regions but the cur­rent one. +ctrl a X -> remove active win­dow from split screen +ctrl a O -> logout active win­dow (dis­able out­put) +ctrl a I -> login active win­dow (enable output) +``` diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/manual.txt b/buildroot-v86/board/v86/rootfs_overlay/root/manual.txt new file mode 100644 index 0000000..1e0ca6a --- /dev/null +++ b/buildroot-v86/board/v86/rootfs_overlay/root/manual.txt @@ -0,0 +1 @@ +# diff --git a/edit.sh b/edit.sh index 5138ce7..9b78ec4 100755 --- a/edit.sh +++ b/edit.sh @@ -3,6 +3,7 @@ set -e make BR2_EXTERNAL=/buildroot-v86 v86_defconfig mkdir output/legal-info && touch output/legal-info/{host-licenses,licenses,buildroot.config} make menuconfig +make busybox-meuconfig make linux-menuconfig make savedefconfig make linux-savedefconfig