For your amusement, I just made a silly converter from a format remotely
like that of OpenRC.  Note that unlike slew.rc which is largely
independent of any particular rc(1) feature, this converter depends on
rc(1)'s ability to handle variables with unconventional names (eg.
`timeout-kill' and `data/test') and to easily use dynamically named
variables (eg. `$$_name').  And seriously, if you really find a
single-file format necessary (for marketing reasons :(), I think a
shell-based format would be better than alternatives like systemd units
or immortal `run.yml' files.

-- 
My current OpenPGP key:
RSA4096/0x227E8CAAB7AA186C (expires: 2020.10.19)
7077 7781 B859 5166 AE07 0286 227E 8CAA B7AA 186C

#!/bin/rc -e

_wrap=/etc/slew/lib/wrap.rc
_base=/etc/slew/conv
if (~ $#* 0) exit 1
. $1
if (! ~ $#self 1 || ~ $self */*) exit 1
mkdir $self
cp $1 conv

for (_name in \
        type contents dependencies notification-fd nosetsid \
        timeout-up timeout-down timeout-kill timeout-finish \
        producer-for consumer-for pipeline-name \
) {
        if (! ~ $#$_name 0) {
                echo $$_name | tr -s ' ' '\n' > $self/$_name
        }
}

for (_name in $extra) {
        if (~ $_name */*) mkdir -p `{dirname $self/$_name}
        printf '%s' $$_name > $self/$_name
}

for (_name in up down run finish) {
        if (whatis $_name > /dev/null >[2=1])
        printf '#!/bin/execlineb -P\n%s %s %s\n' \
                $_wrap $_base/$self.rc $_name > $self/$_name
}

#!/bin/rc -e

. $1
$2

#!/bin/rc

self=hello
type=longrun
dependencies=(origin)
extra=(data/test)

data/test=''

fn run {
        echo Hello world
        exec cat >[2=1]
}

Reply via email to