some improvements
This commit is contained in:
parent
98057ae340
commit
d4c169aaa6
3 changed files with 66 additions and 59 deletions
42
mk_chroot.sh
42
mk_chroot.sh
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue