2014-11-12 02:19:58 +01:00
|
|
|
#!/bin/bash
|
2014-11-18 19:20:53 +01:00
|
|
|
#
|
2014-11-12 02:19:58 +01: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.
|
|
|
|
#
|
|
|
|
# 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@
|
|
|
|
|
2015-06-09 00:01:31 +02:00
|
|
|
LIBDIR='@libdir@'
|
|
|
|
|
|
|
|
[[ -r ${LIBDIR}/util-msg.sh ]] && source ${LIBDIR}/util-msg.sh
|
|
|
|
|
|
|
|
import ${LIBDIR}/util.sh
|
|
|
|
import ${LIBDIR}/util-mount.sh
|
2014-11-13 13:33:38 +01:00
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
working_dir=''
|
2017-04-19 08:58:04 +02:00
|
|
|
files=()
|
2015-06-03 17:53:35 +02:00
|
|
|
keep_mirrors=false
|
2017-04-19 08:58:04 +02:00
|
|
|
nosetarch=false
|
2014-11-12 02:19:58 +01:00
|
|
|
|
|
|
|
usage() {
|
2016-09-15 23:58:18 +02:00
|
|
|
echo "Usage: ${0##*/} [options] working-dir [run arguments]"
|
|
|
|
echo "A wrapper around chroot. Provides support for pacman."
|
|
|
|
echo
|
|
|
|
echo ' options:'
|
|
|
|
echo ' -C <file> Location of a pacman config file'
|
|
|
|
echo ' -M <file> Location of a makepkg config file'
|
|
|
|
echo ' -c <dir> Set pacman cache'
|
2017-04-19 08:58:04 +02:00
|
|
|
echo ' -f <file> Copy file from the host to the chroot'
|
|
|
|
echo ' -s Do not run setarch'
|
2016-09-15 23:58:18 +02:00
|
|
|
echo ' -r <list> Bind mountargs ro'
|
|
|
|
echo ' -w <list> Bind mountargs rw'
|
2017-04-19 08:58:04 +02:00
|
|
|
echo ' List format [src1:target1 ... srcN:targetN]'
|
2016-09-15 23:58:18 +02:00
|
|
|
echo ' -h This message'
|
|
|
|
exit 1
|
2014-11-12 02:19:58 +01:00
|
|
|
}
|
|
|
|
|
2017-04-19 08:58:04 +02:00
|
|
|
orig_argv=("$0" "$@")
|
2014-11-12 02:19:58 +01:00
|
|
|
|
2017-06-04 23:07:16 +02:00
|
|
|
opts='hC:M:c:r:w:f:s'
|
2015-05-29 17:12:24 +02:00
|
|
|
|
|
|
|
while getopts ${opts} arg; do
|
2016-09-15 23:58:18 +02:00
|
|
|
case "${arg}" in
|
|
|
|
C) pac_conf="$OPTARG" ;;
|
|
|
|
M) makepkg_conf="$OPTARG" ;;
|
|
|
|
c) cache_dir="$OPTARG" ;;
|
2017-04-19 08:58:04 +02:00
|
|
|
f) files+=("$OPTARG") ;;
|
|
|
|
s) nosetarch=true ;;
|
|
|
|
r) bindmounts_ro=("$OPTARG") ;;
|
|
|
|
w) bindmounts_rw=("$OPTARG") ;;
|
2016-09-15 23:58:18 +02:00
|
|
|
h|?) usage ;;
|
|
|
|
*) error "invalid argument '$arg'"; usage ;;
|
|
|
|
esac
|
2014-11-12 02:19:58 +01:00
|
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
|
|
|
(( $# < 1 )) && die 'You must specify a directory.'
|
2017-04-19 08:58:04 +02:00
|
|
|
|
|
|
|
check_root
|
2014-11-12 02:19:58 +01:00
|
|
|
|
|
|
|
working_dir=$(readlink -f "$1")
|
|
|
|
shift 1
|
|
|
|
|
|
|
|
[[ -z $working_dir ]] && die 'Please specify a working directory.'
|
|
|
|
|
|
|
|
if [[ -z $cache_dir ]]; then
|
2016-09-15 23:58:18 +02:00
|
|
|
cache_dirs=($(pacman -v 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g'))
|
2014-11-12 02:19:58 +01:00
|
|
|
else
|
2016-09-15 23:58:18 +02:00
|
|
|
cache_dirs=("$cache_dir")
|
2014-11-12 02:19:58 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
copy_hostconf () {
|
2016-09-15 23:58:18 +02:00
|
|
|
cp -a /etc/pacman.d/gnupg "$1/etc/pacman.d"
|
2014-11-12 02:19:58 +01:00
|
|
|
|
2016-09-15 23:58:18 +02:00
|
|
|
[[ -n $pac_conf ]] && cp $pac_conf "$1/etc/pacman.conf"
|
2016-05-04 22:44:52 +02:00
|
|
|
|
2016-09-15 23:58:18 +02:00
|
|
|
[[ -n $makepkg_conf ]] && cp $makepkg_conf "$1/etc/makepkg.conf"
|
2015-05-29 17:12:24 +02:00
|
|
|
|
2017-04-19 08:58:04 +02:00
|
|
|
local file
|
|
|
|
for file in "${files[@]}"; do
|
|
|
|
mkdir -p "$(dirname "$working_dir$file")"
|
|
|
|
cp -T "$file" "$working_dir$file"
|
|
|
|
done
|
|
|
|
|
2016-09-15 23:58:18 +02:00
|
|
|
sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i "$1/etc/pacman.conf"
|
2014-11-12 02:19:58 +01:00
|
|
|
}
|
|
|
|
|
2017-04-19 08:58:04 +02:00
|
|
|
chroot_extra_mount() {
|
2016-09-15 23:58:18 +02:00
|
|
|
chroot_mount "/etc/resolv.conf" "$1/etc/resolv.conf" -B
|
|
|
|
chroot_mount "${cache_dirs[0]}" "$1${cache_dirs[0]}" -B
|
|
|
|
|
|
|
|
for cache_dir in ${cache_dirs[@]:1}; do
|
|
|
|
chroot_mount "$cache_dir" "$1${cache_dir}" -Br
|
|
|
|
done
|
|
|
|
|
2017-04-19 08:58:04 +02:00
|
|
|
for m in ${bindmounts_ro[@]}; do
|
|
|
|
chroot_mount "${m%%:*}" "$1${m##*:}" -Br
|
|
|
|
done
|
2016-09-15 23:58:18 +02:00
|
|
|
|
2017-04-19 08:58:04 +02:00
|
|
|
for m in ${bindmounts_rw[@]}; do
|
|
|
|
chroot_mount "${m%%:*}" "$1${m##*:}" -B
|
|
|
|
done
|
2014-11-17 05:44:56 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
umask 0022
|
|
|
|
|
|
|
|
# Sanity check
|
2014-12-05 23:49:28 +01:00
|
|
|
if [[ ! -f "$working_dir/.manjaro-tools" ]]; then
|
2016-09-15 23:58:18 +02:00
|
|
|
die "'%s' does not appear to be a Manjaro chroot." "$working_dir"
|
2014-12-05 23:49:28 +01:00
|
|
|
elif [[ $(cat "$working_dir/.manjaro-tools") != $version ]]; then
|
2016-09-15 23:58:18 +02:00
|
|
|
die "chroot '%s' is not at version %s. Please rebuild." "$working_dir" "$version"
|
2014-11-12 02:19:58 +01:00
|
|
|
fi
|
|
|
|
|
2015-01-13 04:45:52 +01:00
|
|
|
chroot_api_mount "${working_dir}" || die "failed to setup API filesystems in chroot %s" "${working_dir}"
|
2014-11-12 02:19:58 +01:00
|
|
|
|
2017-04-19 08:58:04 +02:00
|
|
|
chroot_extra_mount "${working_dir}"
|
2014-11-12 02:19:58 +01:00
|
|
|
|
2015-01-13 13:41:28 +01:00
|
|
|
copy_hostconf "${working_dir}"
|
2014-11-12 02:19:58 +01:00
|
|
|
|
|
|
|
eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf")
|
|
|
|
|
2017-04-19 08:58:04 +02:00
|
|
|
${nosetarch} && unset CARCH
|
|
|
|
|
2014-11-12 21:04:31 +01:00
|
|
|
${CARCH:+setarch "$CARCH"} chroot "${working_dir}" "$@"
|
2015-11-26 01:20:37 +01:00
|
|
|
|
2017-04-19 08:58:04 +02:00
|
|
|
# kill_chroot_process "${working_dir}"
|