nix-tools/bin/manjaro-chroot.in

61 lines
1.5 KiB
Bash

#!/bin/bash
#
# 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.
#
# 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.
version=@version@
shopt -s extglob
LIBDIR='@libdir@'
[[ -r ${LIBDIR}/util-msg.sh ]] && source ${LIBDIR}/util-msg.sh
import ${LIBDIR}/util-mount.sh
import ${LIBDIR}/util.sh
automount=false
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
}
orig_argv=("$@")
opts=':ha'
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 ))
check_root "$0" "${orig_argv[@]}"
if ${automount};then
chrootdir=/mnt
chroot_mount_partitions $chrootdir
else
chrootdir=$1
shift
fi
[[ -d $chrootdir ]] || die "Can't create chroot on non-directory %s" "$chrootdir"
chroot_api_mount "$chrootdir" || die "failed to setup API filesystems in chroot %s" "$chrootdir"
chroot_mount /etc/resolv.conf "$chrootdir/etc/resolv.conf" --bind
SHELL=/bin/sh unshare --fork --pid chroot "$chrootdir" "$@"