linux-qubasis
linux oasis port as a qubes template
git clone https://9o.is/git/linux-qubasis.git
commit 5245c6e6fec26b331685791effc95d312e58db23 parent 6ffe46bec27aa409b32001046b0a56168ba3f048 Author: Jul <jul@9o.is> Date: Wed, 17 Sep 2025 19:59:49 +0800 set up sinit/perp/getty/tinylog in example template Diffstat:
| M | ninja/fspec.sh | | | 16 | +++++++++------- |
| M | ninja/functions.sh | | | 24 | ++++++++++++++++-------- |
| M | ninja/qubes-install.sh | | | 2 | +- |
| M | ninja/rules.ninja | | | 2 | +- |
| M | tpl/example/etc/group | | | 1 | + |
| M | tpl/example/etc/passwd | | | 1 | + |
| A | tpl/example/etc/perp/.boot/rc.perp | | | 2 | ++ |
| A | tpl/example/etc/perp/.default/rc.log | | | 13 | +++++++++++++ |
| A | tpl/example/etc/perp/.getty/rc.main | | | 4 | ++++ |
| M | tpl/example/etc/rc.init | | | 5 | +---- |
| M | tpl/example/etc/rc.shutdown | | | 9 | +++++---- |
| M | tpl/example/etc/shadow | | | 1 | + |
| M | tpl/example/gen.sh | | | 18 | +++++++++++++----- |
13 files changed, 68 insertions(+), 30 deletions(-)
diff --git a/ninja/fspec.sh b/ninja/fspec.sh @@ -6,22 +6,24 @@ out="$1" path="$2" type="$3" mode="$4" -src="${5-}" +uid="$5" +gid="$6" +src="${7-}" case $type in reg) - printf '%s\ntype=reg\nmode=%s\nsource=%s\n\n' \ - "$path" "$mode" "$src" > $out.tmp + printf '%s\ntype=reg\nmode=%s\nuid=%s\ngid=%s\nsource=%s\n\n' \ + "$path" "$mode" "$uid" "$gid" "$src" > $out.tmp $hostdir/fspec-hash <$out.tmp > $out rm -f $out.tmp ;; sym) - printf '%s\ntype=sym\nmode=%s\ntarget=%s\n\n' \ - "$path" "$mode" "$src" > $out + printf '%s\ntype=sym\nmode=%s\nuid=%s\ngid=%s\ntarget=%s\n\n' \ + "$path" "$mode" "$uid" "$gid" "$src" > $out ;; dir) - printf '%s\ntype=dir\nmode=%s\n\n' \ - "$path" "$mode" > $out + printf '%s\ntype=dir\nmode=%s\nuid=%s\ngid=%s\n\n' \ + "$path" "$mode" "$uid" "$gid" > $out ;; *) printf "error: unknown fspec type '$type'" >&2 diff --git a/ninja/functions.sh b/ninja/functions.sh @@ -67,7 +67,7 @@ yacc() { bin() { _fn=${1##*/} _out=$outdir/$_fn - _ninja_fspec /bin/$_fn reg 0755 $_out + _ninja_fspec /bin/$_fn reg 0755 0 0 $_out case $1 in \$*) build copy $_out $1;; @@ -75,22 +75,25 @@ bin() { } dir() { - _ninja_fspec $1 dir ${2-0755} + _own=${3-0:0} + _uid=${_own%:*} + _gid=${_own#*:} + _ninja_fspec $1 dir ${2-0755} $_uid $_gid } sym() { - _ninja_fspec $2 sym 0777 $1 + _ninja_fspec $2 sym 0777 0 0 $1 } reg() { _out=$outdir/${1##*/} - _ninja_fspec $2 reg ${3-0644} $_out + _ninja_fspec $2 reg ${3-0644} 0 0 $_out } etc() { _ninja_prefix _src $etcdir $1 _out=$outdir/_files/etc/$1 - _ninja_fspec /etc/$1 ${3-reg} ${2-0644} $_out + _ninja_fspec /etc/$1 ${3-reg} ${2-0644} 0 0 $_out build copy $_out $_src } @@ -117,7 +120,7 @@ man() { _rule=copy fi - _ninja_fspec $MANDIR/man$_sec/${_out##*/} reg 0644 $_out + _ninja_fspec $MANDIR/man$_sec/${_out##*/} reg 0644 0 0 $_out build $_rule $_out $_src ${_rule_dep-} } @@ -366,7 +369,8 @@ _ninja_build() { } _ninja_fspec() { - _ninja_buffer_fspec="$_ninja_buffer_fspec$PREFIX$1 $2 $3 ${4-}\n" + # path type mode uid gid src + _ninja_buffer_fspec="$_ninja_buffer_fspec$PREFIX$1 $2 $3 ${4-0} ${5-0} ${6-}\n" } _ninja_fspec_file() { @@ -711,7 +715,9 @@ _ninja_flush_fspec() { path=$1 type=$2 mode=$3 - src=${4-} + uid=$4 + gid=$5 + src=${6-} out=$outdir/_fspec/$(printf ${path#/} | tr '/' '-') dep='| $basedir/ninja/fspec.sh $hostdir/fspec-hash' @@ -725,6 +731,8 @@ _ninja_flush_fspec() { bind path $path bind type $type bind mode $mode + bind uid $uid + bind gid $gid if [ $type = sym ]; then bind target $src diff --git a/ninja/qubes-install.sh b/ninja/qubes-install.sh @@ -46,7 +46,7 @@ create_image() { mkdir -p $mnt sudo mount $loop $mnt - zstd -d --stdout $tar | sudo $hostdir/pax -r -s ",^[^/]*,$mnt," + zstd -d --stdout $tar | sudo $hostdir/pax -r -p e -s ",^[^/]*,$mnt," sudo umount $mnt sudo losetup -d $loop diff --git a/ninja/rules.ninja b/ninja/rules.ninja @@ -54,7 +54,7 @@ rule rsp rspfile_content = $in_newline rule fspec - command = sh $basedir/ninja/fspec.sh $out $path $type $mode $in $target >/dev/null + command = sh $basedir/ninja/fspec.sh $out $path $type $mode $uid $gid $in $target >/dev/null description = FSPEC $out rule fspec-tar diff --git a/tpl/example/etc/group b/tpl/example/etc/group @@ -1,2 +1,3 @@ root:x:0:root +log:x:100: user:x:1000:user diff --git a/tpl/example/etc/passwd b/tpl/example/etc/passwd @@ -1,2 +1,3 @@ root:x:0:0:root:/root:/bin/rc +log:x:100:100:Logging daemon:/var/empty:/bin/false user:x:1000:1000:user:/home/user:/bin/rc diff --git a/tpl/example/etc/perp/.boot/rc.perp b/tpl/example/etc/perp/.boot/rc.perp @@ -0,0 +1,2 @@ +#!/bin/rc +exec perpd $PERP_BASE diff --git a/tpl/example/etc/perp/.default/rc.log b/tpl/example/etc/perp/.default/rc.log @@ -0,0 +1,13 @@ +#!/bin/rc -e + +if(~ $#* 0) *=(start perpd) +if(! ~ $1 start) exit + +dir=/var/log/$2 + +if(! test -d $dir) { + mkdir -p $dir + chown log:log $dir +} + +exec runuid log tinylog -k 8 -s 33554432 -t $dir diff --git a/tpl/example/etc/perp/.getty/rc.main b/tpl/example/etc/perp/.getty/rc.main @@ -0,0 +1,4 @@ +#!/bin/rc +if(! ~ $1 start) exit +dev=/dev/`{echo $2 | cut -d @ -f 2} +exec getty -a $dev diff --git a/tpl/example/etc/rc.init b/tpl/example/etc/rc.init @@ -11,7 +11,4 @@ mkdir /dev/pts mkdir /dev/shm mount -a - -rc -swapoff /dev/xvdc1 -exec shutdown +exec perpboot /etc/perp diff --git a/tpl/example/etc/rc.shutdown b/tpl/example/etc/rc.shutdown @@ -3,11 +3,12 @@ path=/bin args=() + switch($1) { - case poweroff - args=-p - case reboot - args=-r +case poweroff + args=-p +case reboot + args=-r } exec /bin/shutdown $args diff --git a/tpl/example/etc/shadow b/tpl/example/etc/shadow @@ -1,2 +1,3 @@ root:::::::: +log:!::::::: user:::::::: diff --git a/tpl/example/gen.sh b/tpl/example/gen.sh @@ -1,9 +1,10 @@ -template oasis-example black 12M +template oasis-example black 20M dir /bin dir /dev dir /etc dir /home +dir /home/user 0755 1000:1000 dir /lib dir /mnt dir /proc @@ -18,8 +19,8 @@ dir /var dir /rw dir /mnt/removable dir /lib/modules -sym ../bin /sbin -sym ../ /usr +sym bin /sbin +sym . /usr etc fstab etc rc.init 0755 @@ -27,18 +28,25 @@ etc rc.shutdown 0755 etc passwd etc group etc shadow 0000 +etc perp/.boot/rc.perp 0755 +etc perp/.default/rc.log 0755 +etc perp/.getty/rc.main 0755 +dir /etc/perp/getty@hvc0 1755 +sym ../.default/rc.log /etc/perp/.boot/rc.log +sym ../.getty/rc.main /etc/perp/getty@hvc0/rc.main -pkg sinit pkg oksh +pkg perp pkg rc pkg sbase +pkg sinit pkg ubase pkg mandoc " + /bin/mandoc /bin/apropos /bin/makewhatis /bin/man - /bin/mandoc /bin/whatis /share/man/man1/apropos.1.gz /share/man/man8/makewhatis.8.gz