manjaro-tools/bin/manjaro-chroot.in

104 lines
2.3 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@'
2015-12-03 23:08:43 +01:00
SYSCONFDIR='@sysconfdir@'
2015-06-09 00:01:31 +02:00
[[ -r ${LIBDIR}/util-msg.sh ]] && source ${LIBDIR}/util-msg.sh
import ${LIBDIR}/util.sh
import ${LIBDIR}/util-mount.sh
display_settings(){
show_version
show_config
msg "ARGS:"
msg2 "automount: ${automount}"
2015-07-03 11:08:09 +02:00
msg2 "run_args: ${run_args}"
msg "PATHS:"
msg2 "chrootdir: ${chrootdir}"
}
load_user_info
load_config "${USER_CONFIG}/manjaro-tools.conf"
load_config "${SYSCONFDIR}/manjaro-tools.conf"
automount=false
pretend=false
2014-10-04 10:54:55 +02:00
2014-10-04 01:43:42 +02:00
usage() {
2015-07-03 21:50:08 +02:00
echo "usage: ${0##*/} -a [or] ${0##*/} chroot-dir [command]"
echo ' -a Automount detected linux system'
echo ' -q Query settings and pretend'
echo ' -h Print this help message'
echo ''
echo " If 'command' is unspecified, ${0##*/} will launch /bin/sh."
echo ''
echo " If 'automount' is true, ${0##*/} will launch /bin/bash"
echo " and ${chroots_dir}/manjaro-chroot."
2015-07-03 21:50:08 +02:00
echo ''
echo ''
exit $1
}
2014-10-04 01:43:42 +02:00
orig_argv=("$@")
2014-10-04 01:43:42 +02:00
opts=':haq'
2014-10-04 01:43:42 +02:00
while getopts ${opts} arg; do
case "${arg}" in
a) automount=true ;;
q) pretend=true ;;
h|?) usage 0 ;;
*) echo "invalid argument ${arg}"; usage 1 ;;
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
2015-07-02 22:54:24 +02:00
chrootdir=${chroots_dir}/manjaro-chroot
prepare_dir ${chrootdir}
2015-07-03 11:08:09 +02:00
run_args=/bin/bash
2015-07-03 21:50:08 +02:00
2015-07-03 17:36:06 +02:00
${pretend} && display_settings && exit 1
2015-07-03 21:50:08 +02:00
2015-07-14 18:38:41 +02:00
if [[ -d /run/systemd ]]; then
2015-11-30 01:46:45 +01:00
systemctl start lvm2-lvmetad
2015-07-14 18:38:41 +02:00
else
rc-service lvm start
fi
2015-07-03 17:19:22 +02:00
os_list=$(detect)
select_os
else
chrootdir=$1
shift
2015-07-03 11:08:09 +02:00
run_args=$@
2015-07-03 21:50:08 +02:00
[[ -d ${chrootdir} ]] || die "Can't create chroot on non-directory %s" "${chrootdir}"
2015-07-02 22:54:24 +02:00
2015-07-03 17:36:06 +02:00
${pretend} && display_settings && exit 1
2015-07-03 21:50:08 +02: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
fi
2015-07-03 11:08:09 +02:00
SHELL=/bin/sh unshare --fork --pid chroot "${chrootdir}" "${run_args}"