#!/bin/execlineb elgetopt "be:u:c:" multisubstitute { importas -D "0" build ELGETOPT_b importas -D "" extra_mounts ELGETOPT_e importas -D "" user_arg ELGETOPT_u importas -D "" command_arg ELGETOPT_c importas -D "" dest 1 importas -i USER USER importas -i HOME HOME } shift elgetpositionals emptyenv -oP backtick -D "ash -l" command { ifelse { test -n $command_arg } { echo $command_arg } ifelse { test $# -gt 0 } { echo $@ } echo ash -l } importas -ui command command # TODO: add -s to that when not using `su` later backtick -D "" -E user { ifelse { test -n $user_arg } { echo $user_arg } echo $USER } backtick -D "" -E build_mounts { if { test $build = 1 } echo " ${HOME}/aports ${HOME}/packages ${HOME}/.abuild " } define -s -C bindpoints "/etc/resolv.conf ${build_mounts} ${extra_mounts}" ifelse -n { test -d $dest } { foreground { echo "no such file or directory: $dest" } exit 1 } ifelse -n { test -x ${dest}/bin/sh } { foreground { echo "$dest does not contain executable /bin/sh" } exit 1 } backtick -E uid { id -u } backtick -E -D "exec" sucmd { if { test $uid != 0 } echo doas } $sucmd unshare -m foreground { mount -t devtmpfs devtmpfs ${dest}/dev } foreground { mount -t tmpfs shm ${dest}/dev/shm } foreground { mount -t devpts devpts ${dest}/dev/pts } foreground { mount -t sysfs sysfs ${dest}/sys } foreground { mount -t proc proc ${dest}/proc } foreground { mount -t tmpfs tmpfs ${dest}/tmp } foreground { forx -E point { $bindpoints } # ensure $point exists in destination ifthenelse { test -f $point } { touch ${dest}${point} } { mkdir -p ${dest}${point} } mount --bind $point ${dest}${point} } chroot ${dest} su $user -c "$command"