2014-10-04 01:43:42 +02:00
|
|
|
#!/bin/bash
|
2014-11-18 19:20:53 +01:00
|
|
|
#
|
2014-10-04 15:41:22 +02:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; version 2 of the License.
|
2014-10-04 01:43:42 +02:00
|
|
|
#
|
2014-10-04 15:41:22 +02:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2014-10-04 01:43:42 +02:00
|
|
|
|
2014-10-08 13:14:28 +02:00
|
|
|
version=@version@
|
|
|
|
|
2014-10-04 15:41:22 +02:00
|
|
|
shopt -s extglob
|
2014-10-04 01:43:42 +02:00
|
|
|
|
2015-06-09 00:01:31 +02:00
|
|
|
LIBDIR='@libdir@'
|
|
|
|
|
|
|
|
[[ -r ${LIBDIR}/util-msg.sh ]] && source ${LIBDIR}/util-msg.sh
|
|
|
|
|
|
|
|
import ${LIBDIR}/util-mount.sh
|
2014-10-04 10:54:55 +02:00
|
|
|
|
2014-10-04 01:43:42 +02:00
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
|
|
|
usage: ${0##*/} chroot-dir [command]
|
|
|
|
|
|
|
|
-h Print this help message
|
|
|
|
|
|
|
|
If 'command' is unspecified, ${0##*/} will launch /bin/sh.
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ -z $1 || $1 = @(-h|--help) ]]; then
|
|
|
|
usage
|
|
|
|
exit $(( $# ? 0 : 1 ))
|
|
|
|
fi
|
|
|
|
|
|
|
|
(( EUID == 0 )) || die 'This script must be run with root privileges'
|
|
|
|
chrootdir=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
[[ -d $chrootdir ]] || die "Can't create chroot on non-directory %s" "$chrootdir"
|
|
|
|
|
2015-01-13 04:45:52 +01:00
|
|
|
chroot_api_mount "$chrootdir" || die "failed to setup API filesystems in chroot %s" "$chrootdir"
|
|
|
|
chroot_mount /etc/resolv.conf "$chrootdir/etc/resolv.conf" --bind
|
2014-10-04 01:43:42 +02:00
|
|
|
|
|
|
|
SHELL=/bin/sh chroot "$chrootdir" "$@"
|