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
|
|
|
|
|
|
|
declare newroot=/mnt
|
|
|
|
|
2012-06-18 05:52:39 +08:00
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
|
|
|
usage: ${0##*/} [options]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-r root Install to 'root' (default: /mnt)
|
2012-06-18 11:45:46 +08:00
|
|
|
-d Allow installation to a non-mountpoint directory
|
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-06-18 11:45:46 +08:00
|
|
|
while getopts ':dr:' 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-18 03:17:10 +08:00
|
|
|
r)
|
|
|
|
newroot=$OPTARG
|
|
|
|
;;
|
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 ))
|
|
|
|
|
|
|
|
if (( $# )); then
|
|
|
|
packages=("$@")
|
|
|
|
else
|
|
|
|
packages=('base' 'base-devel')
|
|
|
|
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-06-22 21:33:11 +08:00
|
|
|
mkdir -p "$newroot/var/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-19 20:11:07 +08:00
|
|
|
if ! pacman -r "$newroot" -Sy --noconfirm "${packages[@]}"; then
|
|
|
|
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:
|