2012-06-18 03:17:10 +08: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
|
|
|
|
#
|
|
|
|
|
2012-06-18 05:52:39 +08:00
|
|
|
shopt -s extglob
|
|
|
|
|
2012-06-18 17:07:37 +08:00
|
|
|
m4_include(common)
|
2012-06-18 03:17:10 +08:00
|
|
|
|
2012-07-14 21:33:46 +08:00
|
|
|
hostcache=0
|
2012-09-15 23:46:48 +08:00
|
|
|
copykeyring=1
|
|
|
|
copymirrorlist=1
|
2012-06-18 03:17:10 +08:00
|
|
|
|
2012-06-18 05:52:39 +08:00
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
2012-07-15 22:04:49 +08:00
|
|
|
usage: ${0##*/} [options] root [packages...]
|
2012-06-18 05:52:39 +08:00
|
|
|
|
|
|
|
Options:
|
2019-06-06 03:26:49 +08:00
|
|
|
-C <config> Use an alternate config file for pacman
|
2012-06-23 01:14:09 +08:00
|
|
|
-c Use the package cache on the host, rather than the target
|
2012-09-15 23:46:48 +08:00
|
|
|
-G Avoid copying the host's pacman keyring to the target
|
2019-01-06 00:19:30 +08:00
|
|
|
-i Prompt for package confirmation when needed (run interactively)
|
2012-09-15 23:46:48 +08:00
|
|
|
-M Avoid copying the host's mirrorlist to the target
|
2012-07-15 22:04:49 +08:00
|
|
|
|
2012-11-13 10:00:09 +08:00
|
|
|
-h Print this help message
|
|
|
|
|
2012-07-15 22:04:49 +08:00
|
|
|
pacstrap installs packages to the specified new root directory. If no packages
|
|
|
|
are given, pacstrap defaults to the "base" group.
|
2012-06-18 05:52:39 +08:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ -z $1 || $1 = @(-h|--help) ]]; then
|
|
|
|
usage
|
|
|
|
exit $(( $# ? 0 : 1 ))
|
|
|
|
fi
|
|
|
|
|
2012-06-19 20:12:20 +08:00
|
|
|
(( EUID == 0 )) || die 'This script must be run with root privileges'
|
|
|
|
|
2012-10-04 10:55:49 +08:00
|
|
|
while getopts ':C:cdGiM' flag; do
|
2012-06-18 03:17:10 +08:00
|
|
|
case $flag in
|
2012-10-04 10:55:49 +08:00
|
|
|
C)
|
|
|
|
pacman_config=$OPTARG
|
|
|
|
;;
|
2012-06-18 11:45:46 +08:00
|
|
|
d)
|
2017-11-19 00:04:03 +08:00
|
|
|
# retired flag. does nothing.
|
2012-06-18 11:45:46 +08:00
|
|
|
;;
|
2012-06-23 01:14:09 +08:00
|
|
|
c)
|
2012-07-14 21:33:46 +08:00
|
|
|
hostcache=1
|
2012-06-23 01:14:09 +08:00
|
|
|
;;
|
2012-07-27 07:57:11 +08:00
|
|
|
i)
|
|
|
|
interactive=1
|
|
|
|
;;
|
2012-09-15 23:46:48 +08:00
|
|
|
G)
|
|
|
|
copykeyring=0
|
|
|
|
;;
|
|
|
|
M)
|
|
|
|
copymirrorlist=0
|
|
|
|
;;
|
2012-06-18 22:05:40 +08:00
|
|
|
:)
|
|
|
|
die '%s: option requires an argument -- '\''%s'\' "${0##*/}" "$OPTARG"
|
|
|
|
;;
|
2012-06-18 03:17:10 +08:00
|
|
|
?)
|
|
|
|
die '%s: invalid option -- '\''%s'\' "${0##*/}" "$OPTARG"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
|
2012-07-15 22:04:49 +08:00
|
|
|
(( $# )) || die "No root directory specified"
|
|
|
|
newroot=$1; shift
|
|
|
|
pacman_args=("${@:-base}")
|
2012-06-23 01:14:09 +08:00
|
|
|
|
|
|
|
if (( ! hostcache )); then
|
|
|
|
pacman_args+=(--cachedir="$newroot/var/cache/pacman/pkg")
|
2012-06-18 03:17:10 +08:00
|
|
|
fi
|
|
|
|
|
2012-07-27 07:57:11 +08:00
|
|
|
if (( ! interactive )); then
|
|
|
|
pacman_args+=(--noconfirm)
|
|
|
|
fi
|
|
|
|
|
2012-10-04 10:55:49 +08:00
|
|
|
if [[ $pacman_config ]]; then
|
|
|
|
pacman_args+=(--config="$pacman_config")
|
|
|
|
fi
|
|
|
|
|
2012-06-18 11:45:46 +08:00
|
|
|
[[ -d $newroot ]] || die "%s is not a directory" "$newroot"
|
2012-06-18 03:17:10 +08:00
|
|
|
|
|
|
|
# create obligatory directories
|
|
|
|
msg 'Creating install root at %s' "$newroot"
|
pacstrap: try to copy the host keyring before installing packages
When there is no keyring in the new root, attempting to install e.g.
archlinux-keyring will result in the post-install script silently
failing to do anything (because there are no keys, and, critically, no
secret keys). The potentially very outdated keyring is then copied over
from the host, secret key and all, so subsequent pacman operations have
a trusted keyring that is at least as recent as the ISO or other host
system... but if there has been a keyring update between the date of the
ISO creation and the date of the install, those keys will continue to be
missing until the next keyring update, resulting in a bad out-of-the-box
experience.
This also means that if a thirdparty keyring package was scheduled to be
installed, it will not be populated at all; this affects downstream
archlinux32 build chroots.
There's no reason to delay this until after packages are installed -- we
aren't afraid of e.g. the mirrorlist resulting in file conflicts due to
a packaged pacman-mirrorlist, because the gnupg configuration should not
be getting packaged directly.
Fixes FS#61296 FS#61304 FS#61309 FS#61312 FS#62355
2018-12-05 06:32:50 +08:00
|
|
|
mkdir -m 0755 -p "$newroot"/var/{cache/pacman/pkg,lib/pacman,log} "$newroot"/{dev,run,etc/pacman.d}
|
2012-09-24 21:49:30 +08:00
|
|
|
mkdir -m 1777 -p "$newroot"/tmp
|
|
|
|
mkdir -m 0555 -p "$newroot"/{sys,proc}
|
2012-06-18 03:17:10 +08:00
|
|
|
|
|
|
|
# mount API filesystems
|
2014-12-17 12:15:17 +08:00
|
|
|
chroot_setup "$newroot" || die "failed to setup chroot %s" "$newroot"
|
2012-06-18 03:27:38 +08:00
|
|
|
|
2012-09-15 23:46:48 +08:00
|
|
|
if (( copykeyring )); then
|
|
|
|
# if there's a keyring on the host, copy it into the new root, unless it exists already
|
|
|
|
if [[ -d /etc/pacman.d/gnupg && ! -d $newroot/etc/pacman.d/gnupg ]]; then
|
|
|
|
cp -a /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"
|
|
|
|
fi
|
2012-06-20 02:30:08 +08:00
|
|
|
fi
|
2012-06-18 03:17:10 +08:00
|
|
|
|
pacstrap: try to copy the host keyring before installing packages
When there is no keyring in the new root, attempting to install e.g.
archlinux-keyring will result in the post-install script silently
failing to do anything (because there are no keys, and, critically, no
secret keys). The potentially very outdated keyring is then copied over
from the host, secret key and all, so subsequent pacman operations have
a trusted keyring that is at least as recent as the ISO or other host
system... but if there has been a keyring update between the date of the
ISO creation and the date of the install, those keys will continue to be
missing until the next keyring update, resulting in a bad out-of-the-box
experience.
This also means that if a thirdparty keyring package was scheduled to be
installed, it will not be populated at all; this affects downstream
archlinux32 build chroots.
There's no reason to delay this until after packages are installed -- we
aren't afraid of e.g. the mirrorlist resulting in file conflicts due to
a packaged pacman-mirrorlist, because the gnupg configuration should not
be getting packaged directly.
Fixes FS#61296 FS#61304 FS#61309 FS#61312 FS#62355
2018-12-05 06:32:50 +08:00
|
|
|
msg 'Installing packages to %s' "$newroot"
|
|
|
|
if ! pacman -r "$newroot" -Sy "${pacman_args[@]}"; then
|
|
|
|
die 'Failed to install packages to new root'
|
|
|
|
fi
|
|
|
|
|
2012-09-15 23:46:48 +08:00
|
|
|
if (( copymirrorlist )); then
|
|
|
|
# install the host's mirrorlist onto the new root
|
|
|
|
cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"
|
|
|
|
fi
|
2012-06-20 02:34:01 +08:00
|
|
|
|
2012-06-18 04:05:18 +08:00
|
|
|
# vim: et ts=2 sw=2 ft=sh:
|