future-install-scripts/pacstrap
2012-06-17 17:52:39 -04:00

66 lines
1.3 KiB
Bash
Executable File

#!/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
source ./common
declare newroot=/mnt
usage() {
cat <<EOF
usage: ${0##*/} [options]
Options:
-r root Install to 'root' (default: /mnt)
EOF
}
if [[ -z $1 || $1 = @(-h|--help) ]]; then
usage
exit $(( $# ? 0 : 1 ))
fi
while getopts ':r:' flag; do
case $flag in
r)
newroot=$OPTARG
;;
?)
die '%s: invalid option -- '\''%s'\' "${0##*/}" "$OPTARG"
;;
esac
done
shift $(( OPTIND - 1 ))
if (( $# )); then
packages=("$@")
else
packages=('base' 'base-devel')
fi
rootdev=$(findmnt -runo SOURCE "$newroot") || die '%s is not a mountpoint!' "$newroot"
# create obligatory directories
msg 'Creating install root at %s' "$newroot"
mkdir -p "$newroot/var/lib/pacman" "/$newroot"/{dev,proc,sys,run,tmp,etc}
# mount API filesystems
api_fs_mount "$newroot" || die "failed to setup API filesystems in new root"
# always call umount on quit after this point
trap 'api_fs_umount "$newroot"' EXIT
msg 'Installing packages to %s' "$newroot"
pacman -r "$newroot" -Sy --noconfirm "${packages[@]}"
# vim: et ts=2 sw=2 ft=sh: