manjaro-tools/bin/basestrap.in

113 lines
2.9 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@'
2017-06-11 16:12:30 +02:00
[[ -r ${MANJARO_MSG_LIB} ]] && source ${MANJARO_MSG_LIB}
2015-06-09 00:01:31 +02:00
import ${LIBDIR}/util.sh
import ${LIBDIR}/util-mount.sh
2017-04-19 21:30:38 +02:00
import ${LIBDIR}/util-chroot.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
branch=stable
2014-10-04 00:46:40 +02:00
usage() {
echo "usage: ${0##*/} [options] root [packages...]"
echo " -C <config> Use an alternate config file for pacman"
echo " -B <branch> Use an alternate branch"
echo ' -U <url> Use a specific mirror'
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"
2016-09-15 23:58:18 +02:00
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
}
orig_argv=("$0" "$@")
2014-10-04 00:46:40 +02:00
opts=':C:B:U: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
2017-06-06 17:58:43 +02:00
C) pacman_conf=$OPTARG ;;
2017-06-04 23:07:16 +02:00
B) branch="$OPTARG" ;;
U) mirror="$OPTARG" ;;
2016-09-15 23:58:18 +02:00
d) directory=true ;;
c) hostcache=true ;;
i) interactive=true ;;
G) copykeyring=false ;;
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
2014-10-04 00:46:40 +02:00
(( $# )) || die "No root directory specified"
newroot=$1; shift
pacman_args=("${@:-base}")
2017-06-04 23:07:16 +02:00
pm_args=(-a -p "$newroot" -S "${branch}")
2014-10-04 00:46:40 +02:00
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
2017-06-06 17:58:43 +02:00
[[ -n $pacman_conf ]] && pacman_args+=(--config="$pacman_conf")
2014-10-04 00:46:40 +02:00
2017-06-04 23:07:16 +02:00
[[ -n ${mirror} ]] && pm_args+=(-U "${mirror}")
2014-10-04 00:46:40 +02:00
[[ -d $newroot ]] || die "%s is not a directory" "$newroot"
if ! mountpoint -q "$newroot" && ! ${directory}; then
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
if [[ ! -f $newroot/etc/pacman-mirrors.conf ]]; then
2017-06-04 23:07:16 +02:00
pacman-mirrors "${pm_args[@]}"
fi
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-06-03 17:03:32 +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
if ${copymirrorlist};then
2016-09-15 23:58:18 +02:00
copy_mirrorlist "$newroot"
2015-06-03 17:03:32 +02:00
fi