nix-tools/bin/manjaro-chroot.in

62 lines
1.5 KiB
Text
Raw Normal View History

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
import ${LIBDIR}/util.sh
automount=false
2014-10-04 10:54:55 +02:00
2014-10-04 01:43:42 +02:00
usage() {
echo 'usage: ${0##*/} chroot-dir [command]'
echo '-a Automount detected linux system'
echo '-h Print this help message'
echo ''
echo "If 'command' is unspecified, ${0##*/} will launch /bin/sh."
exit $1
}
2014-10-04 01:43:42 +02:00
orig_argv=("$@")
2014-10-04 01:43:42 +02:00
opts=':ha'
2014-10-04 01:43:42 +02:00
while getopts ${opts} arg; do
case "${arg}" in
a) automount=true ;;
*) echo "invalid argument ${arg}"; usage 1;;
h|?) usage 0 ;;
esac
done
shift $(( OPTIND - 1 ))
2014-10-04 01:43:42 +02:00
check_root "$0" "${orig_argv[@]}"
2014-10-04 01:43:42 +02:00
if ${automount};then
chrootdir=/mnt
chroot_mount_partitions $chrootdir
else
chrootdir=$1
shift
fi
2014-10-04 01:43:42 +02:00
[[ -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 unshare --fork --pid chroot "$chrootdir" "$@"