2014-10-04 00:46:40 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# Assumptions:
|
|
|
|
# 1) User has partitioned, formatted, and mounted partitions on /mnt
|
|
|
|
# 2) Network is functional
|
|
|
|
# 3) Arguments passed to the script are valid pacman targets
|
|
|
|
# 4) A valid mirror appears in /etc/pacman.d/mirrorlist
|
|
|
|
#
|
|
|
|
|
2014-10-08 13:14:28 +02:00
|
|
|
version=@version@
|
|
|
|
|
2014-10-04 00:46:40 +02:00
|
|
|
shopt -s extglob
|
|
|
|
|
2015-12-08 12:33:28 +01:00
|
|
|
DATADIR='@datadir@'
|
2015-06-09 00:01:31 +02:00
|
|
|
LIBDIR='@libdir@'
|
2015-05-29 17:12:24 +02:00
|
|
|
|
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
|
2017-04-19 21:30:38 +02:00
|
|
|
import ${LIBDIR}/util-chroot.sh
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2015-05-29 17:12:24 +02:00
|
|
|
newroot=/mnt
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2015-05-29 17:12:24 +02:00
|
|
|
hostcache=false
|
|
|
|
copykeyring=true
|
|
|
|
copymirrorlist=true
|
2017-06-03 19:02:49 +02:00
|
|
|
branch=stable
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2015-05-29 17:12:24 +02:00
|
|
|
usage() {
|
|
|
|
echo "usage: ${0##*/} [options] root [packages...]"
|
2017-06-03 19:02:49 +02:00
|
|
|
echo " -C <config> Use an alternate config file for pacman"
|
|
|
|
echo " -P <config> Use an alternate config file for pacman-mirrors"
|
|
|
|
echo " -B <branch> Use an alternate branch"
|
|
|
|
echo ' -U <url> Use a specific mirror'
|
|
|
|
echo " -c Use the package cache on the host, rather than the target"
|
|
|
|
echo " -d Allow installation to a non-mountpoint directory"
|
|
|
|
echo " -G Avoid copying the host's pacman keyring to the target"
|
|
|
|
echo " -i Avoid auto-confirmation of package selections"
|
|
|
|
echo " -M Avoid copying the host's mirrorlist to the target"
|
|
|
|
echo " -h Print this help message"
|
2016-09-15 23:58:18 +02:00
|
|
|
echo ''
|
|
|
|
echo ' basestrap installs packages to the specified new root directory.'
|
|
|
|
echo ' If no packages are given, basestrap defaults to the "base" group.'
|
|
|
|
echo ''
|
|
|
|
echo ''
|
|
|
|
exit $1
|
2014-10-04 00:46:40 +02:00
|
|
|
}
|
|
|
|
|
2015-05-29 17:12:24 +02:00
|
|
|
# if [[ -z $1 || $1 = @(-h|--help) ]]; then
|
2017-04-19 15:29:12 +02:00
|
|
|
# usage
|
|
|
|
# exit $(( $# ? 0 : 1 ))
|
2015-05-29 17:12:24 +02:00
|
|
|
# fi
|
2017-04-19 15:29:12 +02:00
|
|
|
|
2017-04-19 08:58:04 +02:00
|
|
|
orig_argv=("$0" "$@")
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2017-06-03 19:02:49 +02:00
|
|
|
opts=':C:P:cdGiM:B:U'
|
2015-06-01 01:05:04 +02:00
|
|
|
|
2015-06-03 16:08:01 +02:00
|
|
|
while getopts ${opts} arg; do
|
2016-09-15 23:58:18 +02:00
|
|
|
case "${arg}" in
|
|
|
|
C) pacman_config=$OPTARG ;;
|
2017-06-03 19:02:49 +02:00
|
|
|
P) mirrors_conf="$OPTARG" ;;
|
2016-09-15 23:58:18 +02:00
|
|
|
d) directory=true ;;
|
|
|
|
c) hostcache=true ;;
|
|
|
|
i) interactive=true ;;
|
|
|
|
G) copykeyring=false ;;
|
|
|
|
M) copymirrorlist=false ;;
|
2017-06-03 19:02:49 +02:00
|
|
|
B) branch="$OPTARG" ;;
|
|
|
|
U) mirror="$OPTARG" ;;
|
2016-09-15 23:58:18 +02:00
|
|
|
:) echo "invalid argument ${arg}:$OPTARG"; usage 1;;
|
|
|
|
?) usage 0 ;;
|
|
|
|
esac
|
2014-10-04 00:46:40 +02:00
|
|
|
done
|
|
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
|
2017-04-19 08:58:04 +02:00
|
|
|
check_root
|
2015-05-29 17:12:24 +02:00
|
|
|
|
2014-10-04 00:46:40 +02:00
|
|
|
(( $# )) || die "No root directory specified"
|
|
|
|
newroot=$1; shift
|
|
|
|
pacman_args=("${@:-base}")
|
|
|
|
|
2015-06-01 01:35:03 +02:00
|
|
|
${hostcache} && pacman_args+=(--cachedir="$newroot/var/cache/pacman/pkg")
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2015-06-01 01:35:03 +02:00
|
|
|
${interactive} && pacman_args+=(--noconfirm)
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2015-06-01 01:35:03 +02:00
|
|
|
[[ -n $pacman_config ]] && pacman_args+=(--config="$pacman_config")
|
2017-06-03 19:02:49 +02:00
|
|
|
[[ -n $mirrors_conf ]] && cp ${mirrors_conf} "$newroot/etc/pacman-mirrors.conf"
|
2014-10-04 00:46:40 +02:00
|
|
|
|
|
|
|
[[ -d $newroot ]] || die "%s is not a directory" "$newroot"
|
2015-05-29 17:12:24 +02:00
|
|
|
|
|
|
|
if ! mountpoint -q "$newroot" && ! ${directory}; then
|
2017-04-19 15:29:12 +02:00
|
|
|
die '%s is not a mountpoint!' "$newroot"
|
2014-10-04 00:46:40 +02:00
|
|
|
fi
|
|
|
|
|
2017-06-03 19:02:49 +02:00
|
|
|
|
|
|
|
mv "$working_dir/etc/locale.gen" "$working_dir/etc/locale.gen.bak"
|
|
|
|
mv "$working_dir/etc/locale.conf" "$working_dir/etc/locale.conf.bak"
|
|
|
|
printf '%s.UTF-8 UTF-8\n' en_US > "$working_dir/etc/locale.gen"
|
|
|
|
printf 'LANG=%s.UTF-8\n' en_US > "$working_dir/etc/locale.conf"
|
|
|
|
printf 'LC_MESSAGES=C\n' >> "$working_dir/etc/locale.conf"
|
|
|
|
|
|
|
|
pm_args=(-a -p "$newroot" -S "${branch}" -R)
|
|
|
|
|
|
|
|
[[ -n ${mirror} ]] && pm_args+=(-U "${mirror}" -n)
|
|
|
|
|
2014-10-04 00:46:40 +02:00
|
|
|
# create obligatory directories
|
2015-05-29 17:12:24 +02:00
|
|
|
create_min_fs "$newroot"
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2017-06-03 19:02:49 +02:00
|
|
|
info "Configuring pacman-mirrors: %s" "${branch}"
|
|
|
|
pacman-mirrors "${pm_args[@]}"
|
|
|
|
|
2014-10-04 00:46:40 +02:00
|
|
|
# mount API filesystems
|
2015-01-13 04:45:52 +01:00
|
|
|
chroot_api_mount "$newroot" || die "failed to setup API filesystems in new root"
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2015-05-15 16:59:48 +02:00
|
|
|
msg2 'Installing packages to %s' "$newroot"
|
2014-10-04 00:46:40 +02:00
|
|
|
if ! pacman -r "$newroot" -Sy "${pacman_args[@]}"; then
|
2016-09-15 23:58:18 +02:00
|
|
|
die 'Failed to install packages to new root'
|
2014-10-04 00:46:40 +02:00
|
|
|
fi
|
|
|
|
|
2015-06-03 17:03:32 +02:00
|
|
|
if ${copykeyring};then
|
2016-09-15 23:58:18 +02:00
|
|
|
copy_keyring "$newroot"
|
2015-06-03 17:03:32 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ${copymirrorlist};then
|
2016-09-15 23:58:18 +02:00
|
|
|
copy_mirrorlist "$newroot"
|
2015-06-03 17:03:32 +02:00
|
|
|
fi
|
2014-10-04 00:46:40 +02:00
|
|
|
|