7d8ef4c747
However, add a '-c' switch to use the host cache instead. The default is useful for when installing a system from an install media (which has possibly constrained storage), but the '-c' switch is useful when e.g. creating build-chroots. I considered doing this the other way around ('-c' being the default). However, I think it makes sense to default to the expected behavior for install both because a new user is less likely to know that they need to add a switch, and because the errormessage they'd get when they run out of space/memory is nonsensical and would cause lots of annoying questions. [dave: use proper array addition, nuke readlink, use arithmetic flag] Signed-off-by: Tom Gundersen <teg@jklm.no>
97 lines
2.2 KiB
Bash
97 lines
2.2 KiB
Bash
#!/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
|
|
#
|
|
|
|
shopt -s extglob
|
|
|
|
m4_include(common)
|
|
|
|
newroot=/mnt
|
|
hostcache=1
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
usage: ${0##*/} [options]
|
|
|
|
Options:
|
|
-r root Install to 'root' (default: /mnt)
|
|
-d Allow installation to a non-mountpoint directory
|
|
-c Use the package cache on the host, rather than the target
|
|
|
|
EOF
|
|
}
|
|
|
|
if [[ -z $1 || $1 = @(-h|--help) ]]; then
|
|
usage
|
|
exit $(( $# ? 0 : 1 ))
|
|
fi
|
|
|
|
(( EUID == 0 )) || die 'This script must be run with root privileges'
|
|
|
|
while getopts ':cdr:' flag; do
|
|
case $flag in
|
|
d)
|
|
directory=1
|
|
;;
|
|
r)
|
|
newroot=$OPTARG
|
|
;;
|
|
c)
|
|
hostcache=0
|
|
;;
|
|
:)
|
|
die '%s: option requires an argument -- '\''%s'\' "${0##*/}" "$OPTARG"
|
|
;;
|
|
?)
|
|
die '%s: invalid option -- '\''%s'\' "${0##*/}" "$OPTARG"
|
|
;;
|
|
esac
|
|
done
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
if (( $# )); then
|
|
pacman_args=("$@")
|
|
else
|
|
pacman_args=('base' 'base-devel')
|
|
fi
|
|
|
|
if (( ! hostcache )); then
|
|
pacman_args+=(--cachedir="$newroot/var/cache/pacman/pkg")
|
|
fi
|
|
|
|
[[ -d $newroot ]] || die "%s is not a directory" "$newroot"
|
|
if ! mountpoint -q "$newroot" && (( ! directory )); then
|
|
die '%s is not a mountpoint!' "$newroot"
|
|
fi
|
|
|
|
# create obligatory directories
|
|
msg 'Creating install root at %s' "$newroot"
|
|
mkdir -p "$newroot/var/lib/pacman" "$newroot"/{dev,proc,sys,run,tmp,etc}
|
|
|
|
# always call umount on quit after this point
|
|
trap 'api_fs_umount "$newroot" 2>/dev/null' EXIT
|
|
|
|
# mount API filesystems
|
|
api_fs_mount "$newroot" || die "failed to setup API filesystems in new root"
|
|
|
|
msg 'Installing packages to %s' "$newroot"
|
|
if ! pacman -r "$newroot" -Sy --noconfirm "${pacman_args[@]}"; then
|
|
die 'Failed to install packages to new root'
|
|
fi
|
|
|
|
# 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
|
|
|
|
# install the host's mirrorlist onto the new root
|
|
cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"
|
|
|
|
# vim: et ts=2 sw=2 ft=sh:
|