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-06-23 01:14:09 +08:00
|
|
|
newroot=/mnt
|
2012-07-14 21:33:46 +08:00
|
|
|
hostcache=0
|
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:
|
2012-06-23 01:14:09 +08:00
|
|
|
-c Use the package cache on the host, rather than the target
|
2012-07-15 22:04:49 +08:00
|
|
|
-d Allow installation to a non-mountpoint directory
|
|
|
|
|
|
|
|
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-07-15 22:04:49 +08:00
|
|
|
while getopts ':cd' flag; do
|
2012-06-18 03:17:10 +08:00
|
|
|
case $flag in
|
2012-06-18 11:45:46 +08:00
|
|
|
d)
|
|
|
|
directory=1
|
|
|
|
;;
|
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-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-06-18 11:45:46 +08:00
|
|
|
[[ -d $newroot ]] || die "%s is not a directory" "$newroot"
|
|
|
|
if ! mountpoint -q "$newroot" && (( ! directory )); then
|
|
|
|
die '%s is not a mountpoint!' "$newroot"
|
|
|
|
fi
|
2012-06-18 03:17:10 +08:00
|
|
|
|
|
|
|
# create obligatory directories
|
|
|
|
msg 'Creating install root at %s' "$newroot"
|
2012-07-23 08:08:56 +08:00
|
|
|
mkdir -p "$newroot"/var/{cache/pacman/pkg,lib/pacman} "$newroot"/{dev,proc,sys,run,tmp,etc}
|
2012-06-18 03:17:10 +08:00
|
|
|
|
2012-06-19 04:51:38 +08:00
|
|
|
# always call umount on quit after this point
|
|
|
|
trap 'api_fs_umount "$newroot" 2>/dev/null' EXIT
|
|
|
|
|
2012-06-18 03:17:10 +08:00
|
|
|
# mount API filesystems
|
2012-06-18 03:27:38 +08:00
|
|
|
api_fs_mount "$newroot" || die "failed to setup API filesystems in new root"
|
|
|
|
|
2012-06-18 03:17:10 +08:00
|
|
|
msg 'Installing packages to %s' "$newroot"
|
2012-06-23 01:14:09 +08:00
|
|
|
if ! pacman -r "$newroot" -Sy --noconfirm "${pacman_args[@]}"; then
|
2012-06-19 20:11:07 +08:00
|
|
|
die 'Failed to install packages to new root'
|
|
|
|
fi
|
|
|
|
|
2012-06-20 02:30:08 +08:00
|
|
|
# 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-18 03:17:10 +08:00
|
|
|
|
2012-06-20 02:34:01 +08:00
|
|
|
# install the host's mirrorlist onto the new root
|
|
|
|
cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"
|
|
|
|
|
2012-06-18 04:05:18 +08:00
|
|
|
# vim: et ts=2 sw=2 ft=sh:
|