some improvements

This commit is contained in:
ston1th 2019-08-20 20:38:28 +02:00
commit d4c169aaa6
3 changed files with 66 additions and 59 deletions

View file

@ -11,7 +11,7 @@ openfiles=
mem=
usage() {
cat <<EOF
cat <<EOF
`basename ${0}` [options...] -c chroot_dir -x executable
-c - chroot directory
@ -25,25 +25,25 @@ usage() {
-m - memory usage
-h - show this help
EOF
exit 1
exit 1
}
errx() { echo "${1}">&2;exit 1; }
while getopts hc:x:u:g:dl:o:f:m: arg; do
case ${arg} in
h) usage ;;
c) chr=${OPTARG} ;;
x) bin=${OPTARG} ;;
u) user=${OPTARG} ;;
g) group=${OPTARG} ;;
d) devfs=1 ;;
l) listen=${OPTARG} ;;
o) out=${OPTARG} ;;
f) openfiles=${OPTARG} ;;
m) mem=${OPTARG} ;;
*) errx "use -h for help" ;;
esac
case ${arg} in
h) usage ;;
c) chr=${OPTARG} ;;
x) bin=${OPTARG} ;;
u) user=${OPTARG} ;;
g) group=${OPTARG} ;;
d) devfs=1 ;;
l) listen=${OPTARG} ;;
o) out=${OPTARG} ;;
f) openfiles=${OPTARG} ;;
m) mem=${OPTARG} ;;
*) errx "use -h for help" ;;
esac
done
shift $((${OPTIND}-1))
@ -84,8 +84,8 @@ userinfo ${user} || useradd -L ${user} -g ${user} -d /var/empty -s /sbin/nologin
rsync -aR $(ldd ${bin}|tail -n+4|awk '{print $7}') ${chr}
daemon=$(basename ${bin})
cat <<EOF> /etc/rc.d/${daemon}
base=$(basename ${bin})
cat <<EOF> /etc/rc.d/${base}
#!/bin/sh
daemon="/usr/bin/env -i /usr/sbin/chroot -u ${user} -g ${group} ${chr}"
@ -97,8 +97,8 @@ pexp="\${daemon_flags}"
rc_cmd \$1
EOF
chmod 0555 /etc/rc.d/${daemon}
chmod 0555 /etc/rc.d/${base}
rcctl enable ${daemon}
rcctl set ${daemon} flags "/bin/${daemon}"
rcctl start ${daemon}
rcctl enable ${base}
rcctl set ${base} flags "/bin/${base}"
rcctl start ${base}