2007-11-28 16:10:41 +01:00
|
|
|
#!/bin/bash
|
2017-03-28 22:13:18 +02:00
|
|
|
#
|
2021-06-10 19:16:22 +02:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2007-10-04 05:19:03 +02:00
|
|
|
|
2011-11-01 15:33:08 +01:00
|
|
|
m4_include(lib/common.sh)
|
2017-03-07 19:19:29 +01:00
|
|
|
m4_include(lib/archroot.sh)
|
2012-06-11 17:04:17 +02:00
|
|
|
|
2019-03-28 22:40:47 +01:00
|
|
|
# umask might have been changed in /etc/profile
|
|
|
|
# ensure that sane default is set again
|
|
|
|
umask 0022
|
|
|
|
|
2010-02-13 19:47:16 +01:00
|
|
|
working_dir=''
|
2019-09-04 00:40:00 +02:00
|
|
|
umode=''
|
2007-10-04 05:19:03 +02:00
|
|
|
|
2017-04-05 21:36:00 +02:00
|
|
|
files=()
|
2018-06-10 23:20:48 +02:00
|
|
|
nspawn_args=()
|
2017-04-05 21:36:00 +02:00
|
|
|
|
2010-02-13 19:47:16 +01:00
|
|
|
usage() {
|
2014-05-11 04:22:05 +02:00
|
|
|
echo "Usage: ${0##*/} [options] working-dir package-list..."
|
2010-02-13 19:47:16 +01:00
|
|
|
echo ' options:'
|
2019-09-04 00:40:00 +02:00
|
|
|
echo ' -U Use pacman -U to install packages'
|
2010-02-13 19:47:16 +01:00
|
|
|
echo ' -C <file> Location of a pacman config file'
|
|
|
|
echo ' -M <file> Location of a makepkg config file'
|
2012-06-12 08:17:58 +02:00
|
|
|
echo ' -c <dir> Set pacman cache'
|
2017-04-05 21:36:00 +02:00
|
|
|
echo ' -f <file> Copy file from the host to the chroot'
|
2017-04-05 21:36:01 +02:00
|
|
|
echo ' -s Do not run setarch'
|
2010-02-13 19:47:16 +01:00
|
|
|
echo ' -h This message'
|
2011-11-01 15:33:08 +01:00
|
|
|
exit 1
|
2007-10-04 05:19:03 +02:00
|
|
|
}
|
|
|
|
|
2019-09-04 00:40:00 +02:00
|
|
|
while getopts 'hUC:M:c:f:s' arg; do
|
2013-05-02 05:24:28 +02:00
|
|
|
case "$arg" in
|
2019-09-04 00:40:00 +02:00
|
|
|
U) umode=U ;;
|
2010-02-13 19:47:16 +01:00
|
|
|
C) pac_conf="$OPTARG" ;;
|
|
|
|
M) makepkg_conf="$OPTARG" ;;
|
2018-06-10 23:20:48 +02:00
|
|
|
c) cache_dirs+=("$OPTARG") ;;
|
2017-04-05 21:36:00 +02:00
|
|
|
f) files+=("$OPTARG") ;;
|
2017-04-05 21:36:01 +02:00
|
|
|
s) nosetarch=1 ;;
|
2012-11-13 03:25:30 +01:00
|
|
|
h|?) usage ;;
|
2017-04-02 10:09:55 +02:00
|
|
|
*) error "invalid argument '%s'" "$arg"; usage ;;
|
2010-02-13 19:47:16 +01:00
|
|
|
esac
|
2019-09-04 00:40:00 +02:00
|
|
|
if [[ $arg != U ]]; then
|
|
|
|
nspawn_args+=("-$arg")
|
|
|
|
[[ -v OPTARG ]] && nspawn_args+=("$OPTARG")
|
|
|
|
fi
|
2007-10-04 05:19:03 +02:00
|
|
|
done
|
2017-05-06 00:41:07 +02:00
|
|
|
shift $((OPTIND - 1))
|
2007-10-04 05:19:03 +02:00
|
|
|
|
2013-05-02 05:24:28 +02:00
|
|
|
(( $# < 2 )) && die 'You must specify a directory and one or more packages.'
|
2007-10-04 05:19:03 +02:00
|
|
|
|
2017-03-07 19:27:36 +01:00
|
|
|
check_root
|
2014-01-08 01:15:37 +01:00
|
|
|
|
2017-05-06 00:41:08 +02:00
|
|
|
working_dir="$(readlink -f "$1")"
|
2007-10-04 05:19:03 +02:00
|
|
|
shift 1
|
|
|
|
|
2011-12-02 08:33:33 +01:00
|
|
|
[[ -z $working_dir ]] && die 'Please specify a working directory.'
|
2007-10-04 05:19:03 +02:00
|
|
|
|
2018-06-10 23:20:48 +02:00
|
|
|
|
|
|
|
if (( ${#cache_dirs[@]} == 0 )); then
|
2021-03-05 21:11:34 +01:00
|
|
|
mapfile -t cache_dirs < <(pacman-conf CacheDir)
|
2010-02-13 09:06:59 +01:00
|
|
|
fi
|
|
|
|
|
2010-02-13 07:22:54 +01:00
|
|
|
umask 0022
|
2010-02-13 19:47:16 +01:00
|
|
|
|
2013-07-30 21:24:48 +02:00
|
|
|
[[ -e $working_dir ]] && die "Working directory '%s' already exists" "$working_dir"
|
2010-02-13 19:47:16 +01:00
|
|
|
|
2013-05-02 05:24:28 +02:00
|
|
|
mkdir -p "$working_dir"
|
2010-02-13 19:47:16 +01:00
|
|
|
|
2013-05-02 07:03:12 +02:00
|
|
|
lock 9 "${working_dir}.lock" "Locking chroot"
|
2010-02-13 19:47:16 +01:00
|
|
|
|
2017-03-07 19:55:05 +01:00
|
|
|
if is_btrfs "$working_dir"; then
|
2013-05-02 05:24:28 +02:00
|
|
|
rmdir "$working_dir"
|
|
|
|
if ! btrfs subvolume create "$working_dir"; then
|
2013-07-30 21:24:48 +02:00
|
|
|
die "Couldn't create subvolume for '%s'" "$working_dir"
|
2010-02-13 19:47:16 +01:00
|
|
|
fi
|
2013-05-02 05:24:28 +02:00
|
|
|
chmod 0755 "$working_dir"
|
|
|
|
fi
|
2010-02-13 19:47:16 +01:00
|
|
|
|
2017-04-05 21:36:00 +02:00
|
|
|
for file in "${files[@]}"; do
|
|
|
|
mkdir -p "$(dirname "$working_dir$file")"
|
|
|
|
cp "$file" "$working_dir$file"
|
|
|
|
done
|
|
|
|
|
2022-02-18 14:35:43 +01:00
|
|
|
unshare --mount pacstrap -${umode}Mcd ${pac_conf:+-C "$pac_conf"} "$working_dir" \
|
2019-04-02 09:32:43 +02:00
|
|
|
"${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages'
|
2010-02-13 19:47:16 +01:00
|
|
|
|
2022-05-27 04:45:06 +02:00
|
|
|
printf '%s.UTF-8 UTF-8\n' C en_US de_DE > "$working_dir/etc/locale.gen"
|
|
|
|
echo 'LANG=C.UTF-8' > "$working_dir/etc/locale.conf"
|
2013-05-02 05:24:28 +02:00
|
|
|
echo "$CHROOT_VERSION" > "$working_dir/.arch-chroot"
|
2011-11-06 10:27:55 +01:00
|
|
|
|
2016-05-27 22:16:09 +02:00
|
|
|
systemd-machine-id-setup --root="$working_dir"
|
|
|
|
|
2013-05-02 05:24:28 +02:00
|
|
|
exec arch-nspawn \
|
2018-06-10 23:20:48 +02:00
|
|
|
"${nspawn_args[@]}" \
|
2013-05-02 05:24:28 +02:00
|
|
|
"$working_dir" locale-gen
|