nix-tools/bin/basestrap.in

110 lines
2.7 KiB
Text
Raw Normal View History

2014-10-04 00:46:40 +02: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
#
2014-10-08 13:14:28 +02:00
version=@version@
2014-10-04 00:46:40 +02:00
shopt -s extglob
2015-12-08 12:33:28 +01:00
DATADIR='@datadir@'
2015-06-09 00:01:31 +02:00
LIBDIR='@libdir@'
2015-06-09 00:01:31 +02:00
[[ -r ${LIBDIR}/util-msg.sh ]] && source ${LIBDIR}/util-msg.sh
import ${LIBDIR}/util.sh
import ${LIBDIR}/util-mount.sh
2014-10-04 00:46:40 +02:00
newroot=/mnt
2014-10-04 00:46:40 +02:00
hostcache=false
copykeyring=true
copymirrorlist=true
2014-10-04 00:46:40 +02:00
usage() {
echo "usage: ${0##*/} [options] root [packages...]"
2016-09-15 23:58:18 +02:00
echo " -C config Use an alternate config file for pacman"
echo " -c Use the package cache on the host, rather than the target"
echo " -d Allow installation to a non-mountpoint directory"
echo " -G Avoid copying the host's pacman keyring to the target"
echo " -i Avoid auto-confirmation of package selections"
echo " -M Avoid copying the host's mirrorlist to the target"
echo " -h Print this help message"
echo ''
echo ' basestrap installs packages to the specified new root directory.'
echo ' If no packages are given, basestrap defaults to the "base" group.'
echo ''
echo ''
exit $1
2014-10-04 00:46:40 +02:00
}
# if [[ -z $1 || $1 = @(-h|--help) ]]; then
# usage
# exit $(( $# ? 0 : 1 ))
# fi
#
2014-10-04 00:46:40 +02:00
orig_argv=("$@")
2014-10-04 00:46:40 +02:00
opts=':C:cdGiM'
2015-06-03 16:08:01 +02:00
while getopts ${opts} arg; do
2016-09-15 23:58:18 +02:00
case "${arg}" in
2018-04-14 01:42:35 +02:00
c) hostcache=true ;;
2016-09-15 23:58:18 +02:00
C) pacman_config=$OPTARG ;;
d) directory=true ;;
G) copykeyring=false ;;
2018-04-14 01:42:35 +02:00
i) interactive=true ;;
2016-09-15 23:58:18 +02:00
M) copymirrorlist=false ;;
:) echo "invalid argument ${arg}:$OPTARG"; usage 1;;
?) usage 0 ;;
esac
2014-10-04 00:46:40 +02:00
done
shift $(( OPTIND - 1 ))
check_root "$0" "${orig_argv[@]}"
2014-10-04 00:46:40 +02:00
(( $# )) || die "No root directory specified"
newroot=$1; shift
pacman_args=("${@:-base}")
2015-06-01 01:35:03 +02:00
${hostcache} && pacman_args+=(--cachedir="$newroot/var/cache/pacman/pkg")
2014-10-04 00:46:40 +02:00
2015-06-01 01:35:03 +02:00
${interactive} && pacman_args+=(--noconfirm)
2014-10-04 00:46:40 +02:00
2015-06-01 01:35:03 +02:00
[[ -n $pacman_config ]] && pacman_args+=(--config="$pacman_config")
2014-10-04 00:46:40 +02:00
[[ -d $newroot ]] || die "%s is not a directory" "$newroot"
if ! mountpoint -q "$newroot" && ! ${directory}; then
2016-09-15 23:58:18 +02:00
die '%s is not a mountpoint!' "$newroot"
2014-10-04 00:46:40 +02:00
fi
# create obligatory directories
create_min_fs "$newroot"
2014-10-04 00:46:40 +02:00
# mount API filesystems
2015-01-13 04:45:52 +01:00
chroot_api_mount "$newroot" || die "failed to setup API filesystems in new root"
2014-10-04 00:46:40 +02:00
2015-05-15 16:59:48 +02:00
msg2 'Installing packages to %s' "$newroot"
2014-10-04 00:46:40 +02:00
if ! pacman -r "$newroot" -Sy "${pacman_args[@]}"; then
2016-09-15 23:58:18 +02:00
die 'Failed to install packages to new root'
2014-10-04 00:46:40 +02:00
fi
2015-01-11 10:23:21 +01:00
# kill chroot process if needed (TODO: check if needed at all)
kill_chroot_process "$newroot"
2018-04-14 00:07:43 +02:00
if ${copykeyring}; then
2016-09-15 23:58:18 +02:00
copy_keyring "$newroot"
2015-06-03 17:03:32 +02:00
fi
2018-04-14 00:07:43 +02:00
if ${copymirrorlist}; then
2016-09-15 23:58:18 +02:00
copy_mirrorlist "$newroot"
2015-06-03 17:03:32 +02:00
fi
2014-10-04 00:46:40 +02:00