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
|
|
|
|
|
2015-07-01 18:35:50 +02:00
|
|
|
import ${LIBDIR}/util.sh
|
2015-07-02 12:34:51 +02:00
|
|
|
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}"
|
2015-07-02 12:34:51 +02:00
|
|
|
|
|
|
|
msg "PATHS:"
|
|
|
|
msg2 "chrootdir: ${chrootdir}"
|
|
|
|
}
|
|
|
|
|
|
|
|
load_user_info
|
|
|
|
|
|
|
|
load_config "${USER_CONFIG}/manjaro-tools.conf"
|
|
|
|
load_config "${SYSCONFDIR}/manjaro-tools.conf"
|
2015-07-01 18:35:50 +02:00
|
|
|
|
|
|
|
automount=false
|
2015-07-02 12:34:51 +02:00
|
|
|
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'
|
2015-07-01 18:35:50 +02:00
|
|
|
echo ''
|
2015-07-04 20:24:49 +02:00
|
|
|
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 ''
|
2015-07-01 18:35:50 +02:00
|
|
|
exit $1
|
|
|
|
}
|
2014-10-04 01:43:42 +02:00
|
|
|
|
2015-07-01 18:35:50 +02:00
|
|
|
orig_argv=("$@")
|
2014-10-04 01:43:42 +02:00
|
|
|
|
2015-07-02 12:34:51 +02:00
|
|
|
opts=':haq'
|
2014-10-04 01:43:42 +02:00
|
|
|
|
2015-07-01 18:35:50 +02:00
|
|
|
while getopts ${opts} arg; do
|
|
|
|
case "${arg}" in
|
|
|
|
a) automount=true ;;
|
2015-07-02 12:34:51 +02:00
|
|
|
q) pretend=true ;;
|
2015-07-01 18:35:50 +02:00
|
|
|
h|?) usage 0 ;;
|
2015-07-04 20:24:49 +02:00
|
|
|
*) echo "invalid argument ${arg}"; usage 1 ;;
|
2015-07-01 18:35:50 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(( OPTIND - 1 ))
|
2014-10-04 01:43:42 +02:00
|
|
|
|
2015-07-01 18:35:50 +02:00
|
|
|
check_root "$0" "${orig_argv[@]}"
|
2014-10-04 01:43:42 +02:00
|
|
|
|
2015-07-01 18:35:50 +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
|
|
|
|
systemctl start lvm
|
|
|
|
else
|
|
|
|
rc-service lvm start
|
2015-07-06 00:14:30 +02:00
|
|
|
fi
|
|
|
|
|
2015-07-03 17:19:22 +02:00
|
|
|
os_list=$(detect)
|
|
|
|
select_os
|
2015-07-01 18:35:50 +02:00
|
|
|
else
|
|
|
|
chrootdir=$1
|
|
|
|
shift
|
2015-07-03 11:08:09 +02:00
|
|
|
run_args=$@
|
2015-07-03 21:50:08 +02:00
|
|
|
|
2015-07-02 15:53:25 +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
|
|
|
|
2015-07-02 15:53:25 +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}"
|