buildiso, buildpkg: use nice new pacman-mirrors features to set chroot branch

This commit is contained in:
udeved 2017-06-03 19:02:49 +02:00
parent 21dbbb3ff9
commit c3495083c9
8 changed files with 62 additions and 98 deletions

View file

@ -26,16 +26,20 @@ newroot=/mnt
hostcache=false hostcache=false
copykeyring=true copykeyring=true
copymirrorlist=true copymirrorlist=true
branch=stable
usage() { usage() {
echo "usage: ${0##*/} [options] root [packages...]" echo "usage: ${0##*/} [options] root [packages...]"
echo " -C config Use an alternate config file for pacman" echo " -C <config> Use an alternate config file for pacman"
echo " -c Use the package cache on the host, rather than the target" echo " -P <config> Use an alternate config file for pacman-mirrors"
echo " -d Allow installation to a non-mountpoint directory" echo " -B <branch> Use an alternate branch"
echo " -G Avoid copying the host's pacman keyring to the target" echo ' -U <url> Use a specific mirror'
echo " -i Avoid auto-confirmation of package selections" echo " -c Use the package cache on the host, rather than the target"
echo " -M Avoid copying the host's mirrorlist to the target" echo " -d Allow installation to a non-mountpoint directory"
echo " -h Print this help message" 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 ''
echo ' basestrap installs packages to the specified new root directory.' echo ' basestrap installs packages to the specified new root directory.'
echo ' If no packages are given, basestrap defaults to the "base" group.' echo ' If no packages are given, basestrap defaults to the "base" group.'
@ -51,16 +55,19 @@ usage() {
orig_argv=("$0" "$@") orig_argv=("$0" "$@")
opts=':C:cdGiM' opts=':C:P:cdGiM:B:U'
while getopts ${opts} arg; do while getopts ${opts} arg; do
case "${arg}" in case "${arg}" in
C) pacman_config=$OPTARG ;; C) pacman_config=$OPTARG ;;
P) mirrors_conf="$OPTARG" ;;
d) directory=true ;; d) directory=true ;;
c) hostcache=true ;; c) hostcache=true ;;
i) interactive=true ;; i) interactive=true ;;
G) copykeyring=false ;; G) copykeyring=false ;;
M) copymirrorlist=false ;; M) copymirrorlist=false ;;
B) branch="$OPTARG" ;;
U) mirror="$OPTARG" ;;
:) echo "invalid argument ${arg}:$OPTARG"; usage 1;; :) echo "invalid argument ${arg}:$OPTARG"; usage 1;;
?) usage 0 ;; ?) usage 0 ;;
esac esac
@ -78,6 +85,7 @@ ${hostcache} && pacman_args+=(--cachedir="$newroot/var/cache/pacman/pkg")
${interactive} && pacman_args+=(--noconfirm) ${interactive} && pacman_args+=(--noconfirm)
[[ -n $pacman_config ]] && pacman_args+=(--config="$pacman_config") [[ -n $pacman_config ]] && pacman_args+=(--config="$pacman_config")
[[ -n $mirrors_conf ]] && cp ${mirrors_conf} "$newroot/etc/pacman-mirrors.conf"
[[ -d $newroot ]] || die "%s is not a directory" "$newroot" [[ -d $newroot ]] || die "%s is not a directory" "$newroot"
@ -85,9 +93,23 @@ if ! mountpoint -q "$newroot" && ! ${directory}; then
die '%s is not a mountpoint!' "$newroot" die '%s is not a mountpoint!' "$newroot"
fi fi
mv "$working_dir/etc/locale.gen" "$working_dir/etc/locale.gen.bak"
mv "$working_dir/etc/locale.conf" "$working_dir/etc/locale.conf.bak"
printf '%s.UTF-8 UTF-8\n' en_US > "$working_dir/etc/locale.gen"
printf 'LANG=%s.UTF-8\n' en_US > "$working_dir/etc/locale.conf"
printf 'LC_MESSAGES=C\n' >> "$working_dir/etc/locale.conf"
pm_args=(-a -p "$newroot" -S "${branch}" -R)
[[ -n ${mirror} ]] && pm_args+=(-U "${mirror}" -n)
# create obligatory directories # create obligatory directories
create_min_fs "$newroot" create_min_fs "$newroot"
info "Configuring pacman-mirrors: %s" "${branch}"
pacman-mirrors "${pm_args[@]}"
# mount API filesystems # mount API filesystems
chroot_api_mount "$newroot" || die "failed to setup API filesystems in new root" chroot_api_mount "$newroot" || die "failed to setup API filesystems in new root"
@ -96,9 +118,6 @@ if ! pacman -r "$newroot" -Sy "${pacman_args[@]}"; then
die 'Failed to install packages to new root' die 'Failed to install packages to new root'
fi fi
# kill chroot process if needed (TODO: check if needed at all)
# kill_chroot_process "$newroot"
if ${copykeyring};then if ${copykeyring};then
copy_keyring "$newroot" copy_keyring "$newroot"
fi fi

View file

@ -41,13 +41,11 @@ prepare_build(){
pacman_conf="${DATADIR}/pacman-$pac_arch.conf" pacman_conf="${DATADIR}/pacman-$pac_arch.conf"
fi fi
local mirrors_conf=$(get_pac_mirrors_conf "${target_branch}") local mirrors_conf=${DATADIR}/pacman-mirrors.conf
iso_file=$(gen_iso_fn).iso iso_file=$(gen_iso_fn).iso
local mirror="${build_mirror}/${target_branch}" mkchroot_args+=(-C ${pacman_conf} -S ${mirrors_conf} -U "${build_mirror}" -B "${target_branch}")
mkchroot_args+=(-C ${pacman_conf} -S ${mirrors_conf} -B "${mirror}" -K)
work_dir=${chroots_iso}/${profile}/${target_arch} work_dir=${chroots_iso}/${profile}/${target_arch}
iso_dir="${cache_dir_iso}/${edition}/${profile}/${dist_release}" iso_dir="${cache_dir_iso}/${edition}/${profile}/${dist_release}"

View file

@ -111,11 +111,9 @@ prepare_build(){
[[ "$pac_arch" == 'multilib' ]] && target_arch='x86_64' [[ "$pac_arch" == 'multilib' ]] && target_arch='x86_64'
local mirror="${build_mirror}/${target_branch}" local mirrors_conf=${DATADIR}/pacman-mirrors.conf
local mirrors_conf=$(get_pac_mirrors_conf "${target_branch}") mkchroot_args+=(-C ${pacman_conf} -M ${makepkg_conf} -S ${mirrors_conf} -U ${build_mirror} -B "${target_branch}")
mkchroot_args+=(-C ${pacman_conf} -M ${makepkg_conf} -S ${mirrors_conf} -B ${mirror})
mkchrootpkg_args+=(-r ${work_dir}) mkchrootpkg_args+=(-r ${work_dir})

View file

@ -37,15 +37,13 @@ usage() {
echo ' -r <list> Bind mountargs ro' echo ' -r <list> Bind mountargs ro'
echo ' -w <list> Bind mountargs rw' echo ' -w <list> Bind mountargs rw'
echo ' List format [src1:target1 ... srcN:targetN]' echo ' List format [src1:target1 ... srcN:targetN]'
echo ' -B Use custom build mirror'
echo ' -K Keep mirrorlist (-B)'
echo ' -h This message' echo ' -h This message'
exit 1 exit 1
} }
orig_argv=("$0" "$@") orig_argv=("$0" "$@")
opts='hKC:M:S:c:r:w:B:f:s' opts='hC:M:S:c:r:w:f:s'
while getopts ${opts} arg; do while getopts ${opts} arg; do
case "${arg}" in case "${arg}" in
@ -57,8 +55,6 @@ while getopts ${opts} arg; do
s) nosetarch=true ;; s) nosetarch=true ;;
r) bindmounts_ro=("$OPTARG") ;; r) bindmounts_ro=("$OPTARG") ;;
w) bindmounts_rw=("$OPTARG") ;; w) bindmounts_rw=("$OPTARG") ;;
B) build_mirror="$OPTARG" ;;
K) keep_mirrors=true ;;
h|?) usage ;; h|?) usage ;;
*) error "invalid argument '$arg'"; usage ;; *) error "invalid argument '$arg'"; usage ;;
esac esac
@ -86,7 +82,6 @@ copy_hostconf () {
[[ -n $pac_conf ]] && cp $pac_conf "$1/etc/pacman.conf" [[ -n $pac_conf ]] && cp $pac_conf "$1/etc/pacman.conf"
[[ -n $makepkg_conf ]] && cp $makepkg_conf "$1/etc/makepkg.conf" [[ -n $makepkg_conf ]] && cp $makepkg_conf "$1/etc/makepkg.conf"
[[ -n $mirrors_conf ]] && cp ${mirrors_conf} "$1/etc/pacman-mirrors.conf"
local file local file
for file in "${files[@]}"; do for file in "${files[@]}"; do
@ -94,20 +89,6 @@ copy_hostconf () {
cp -T "$file" "$working_dir$file" cp -T "$file" "$working_dir$file"
done done
if [[ -n ${build_mirror} ]];then
local branch=$(pacman-mirrors -a --prefix "$1" -G)
if ${keep_mirrors}; then
info "Setting branch: %s" "${branch}"
pacman-mirrors -a -p "$1" -S "${branch}" -R
else
local mirror=${build_mirror}'/$repo/$arch'
echo "Server = ${mirror}" > "$1/etc/pacman.d/mirrorlist"
fi
else
info "Setting branch: %s" "${branch}"
pacman-mirrors -a -p "$1" -S "${branch}" -R
fi
sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i "$1/etc/pacman.conf" sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i "$1/etc/pacman.conf"
} }

View file

@ -25,6 +25,7 @@ build_locales=false
keep_mirrors=false keep_mirrors=false
keep_flag='' keep_flag=''
nosetarch=false nosetarch=false
branch=stable
usage() { usage() {
echo "Usage: ${0##*/} [options] working-dir package-list..." echo "Usage: ${0##*/} [options] working-dir package-list..."
@ -32,20 +33,18 @@ usage() {
echo ' -C <file> Location of a pacman config file' echo ' -C <file> Location of a pacman config file'
echo ' -M <file> Location of a makepkg config file' echo ' -M <file> Location of a makepkg config file'
echo ' -S <file> Location of a pacman-mirrors config file' echo ' -S <file> Location of a pacman-mirrors config file'
echo ' -B <branch> Set branch'
echo ' -U <url> Set a specific mirror'
echo ' -c <dir> Set pacman cache' echo ' -c <dir> Set pacman cache'
echo ' -f <file> Copy file from the host to the chroot' echo ' -f <file> Copy file from the host to the chroot'
echo ' -s Do not run setarch' echo ' -s Do not run setarch'
echo ' -L Use build locale.gen en/de'
echo ' -B Use custom build mirror'
echo ' -K Keep mirrorlist (-B)'
echo ' -x copy pacman.conf'
echo ' -h This message' echo ' -h This message'
exit 1 exit 1
} }
orig_argv=("$0" "$@") orig_argv=("$0" "$@")
opts='hLKC:M:S:c:B:f:s' opts='hC:M:S:c:f:s:U:B'
while getopts ${opts} arg; do while getopts ${opts} arg; do
case "${arg}" in case "${arg}" in
@ -55,9 +54,8 @@ while getopts ${opts} arg; do
c) cache_dir="$OPTARG" ;; c) cache_dir="$OPTARG" ;;
f) files+=("$OPTARG") ;; f) files+=("$OPTARG") ;;
s) nosetarch=true ;; s) nosetarch=true ;;
L) build_locales=true ;; B) branch="$OPTARG" ;;
B) build_mirror="$OPTARG" ;; U) mirror="$OPTARG" ;;
K) keep_mirrors=true; keep_flag='-K' ;;
h|?) usage ;; h|?) usage ;;
*) error "invalid argument '%s'" "$arg"; usage ;; *) error "invalid argument '%s'" "$arg"; usage ;;
esac esac
@ -90,11 +88,11 @@ umask 0022
lock 9 "${working_dir}.lock" "Locking chroot" lock 9 "${working_dir}.lock" "Locking chroot"
if is_btrfs "$working_dir"; then if is_btrfs "$working_dir"; then
rmdir "$working_dir" rmdir "$working_dir"
if ! btrfs subvolume create "$working_dir"; then if ! btrfs subvolume create "$working_dir"; then
die "Couldn't create subvolume for '%s'" "$working_dir" die "Couldn't create subvolume for '%s'" "$working_dir"
fi fi
chmod 0755 "$working_dir" chmod 0755 "$working_dir"
fi fi
for file in "${files[@]}"; do for file in "${files[@]}"; do
@ -102,44 +100,21 @@ for file in "${files[@]}"; do
cp "$file" "$working_dir$file" cp "$file" "$working_dir$file"
done done
# Workaround when creating a chroot in a branch different of the host basestrap_args=(-GMcd ${pac_conf:+-C "$pac_conf"} ${cache_dirs[@]/#/--cachedir=} -B ${branch:+-"$branch"} ${mirrors_conf:+-P "$mirrors_conf"})
if [[ -n $pac_conf ]] && [[ -n $mirrors_conf ]] && [[ -n ${build_mirror} ]]; then
url=${build_mirror}'/$repo/$arch'
info "mirror: %s" "$url"
pac_base="$working_dir/pacman-basestrap.conf"
sed "s#Include = /etc/pacman.d/mirrorlist#Server = ${url}#g" $pac_conf > $pac_base
_env=() [[ -n ${mirror} ]] && basestrap_args+=(-U "${mirror}")
while read -r varname; do
_env+=("$varname=${!varname}")
done < <(declare -x | sed -r 's/^declare -x ([^=]*)=.*/\1/' | grep -i '_proxy$')
env -i "${_env[@]}" \
basestrap -GMcd ${pac_base:+-C "$pac_base"} "$working_dir" \
"${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages'
[[ -f "$pac_base" ]] && rm "$pac_base" _env=()
else while read -r varname; do
_env=() _env+=("$varname=${!varname}")
while read -r varname; do done < <(declare -x | sed -r 's/^declare -x ([^=]*)=.*/\1/' | grep -i '_proxy$')
_env+=("$varname=${!varname}") env -i "${_env[@]}" \
done < <(declare -x | sed -r 's/^declare -x ([^=]*)=.*/\1/' | grep -i '_proxy$')
env -i "${_env[@]}" \ basestrap "${basestrap_args[@]}" "$working_dir" "$@" || die 'Failed to install all packages'
basestrap -GMcd ${pac_conf:+-C "$pac_conf"} "$working_dir" \
"${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages'
fi
echo "$version" > "$working_dir/.manjaro-tools" echo "$version" > "$working_dir/.manjaro-tools"
if ${build_locales};then chroot_args=(${pac_conf:+-C "$pac_conf"} ${makepkg_conf:+-M "$makepkg_conf"} ${cache_dir:+-c "$cache_dir"})
info "Using build locales ..."
mv "$working_dir/etc/locale.gen" "$working_dir/etc/locale.gen.bak"
mv "$working_dir/etc/locale.conf" "$working_dir/etc/locale.conf.bak"
printf '%s.UTF-8 UTF-8\n' en_US > "$working_dir/etc/locale.gen"
printf 'LANG=%s.UTF-8\n' en_US > "$working_dir/etc/locale.conf"
printf 'LC_MESSAGES=C\n' >> "$working_dir/etc/locale.conf"
fi
chroot_args=(${pac_conf:+-C "$pac_conf"} ${makepkg_conf:+-M "$makepkg_conf"} ${mirrors_conf:+-S "$mirrors_conf"} ${build_mirror:+-B "$build_mirror"} ${cache_dir:+-c "$cache_dir"} ${keep_flag})
${nosetarch} && chroot_args+=(${nosetarch:+-s}) ${nosetarch} && chroot_args+=(${nosetarch:+-s})
exec chroot-run \ exec chroot-run \

View file

@ -3,7 +3,7 @@
## ##
## Branch Pacman should use (stable, testing, unstable) ## Branch Pacman should use (stable, testing, unstable)
Branch = @branch@ Branch = stable
## Generation method ## Generation method
## 1) rank - rank mirrors depending on their access time ## 1) rank - rank mirrors depending on their access time

View file

@ -236,11 +236,11 @@ clean_up_image(){
} }
copy_from_cache(){ copy_from_cache(){
local list="${tmp_dir}"/mhwd-cache.list mirror="${build_mirror}/${target_branch}" local list="${tmp_dir}"/mhwd-cache.list
local mnt="$1"; shift local mnt="$1"; shift
chroot-run -B "$mirror" "$mnt" \ chroot-run "$mnt" \
pacman -v -Syw --noconfirm "$@" || return 1 pacman -v -Syw --noconfirm "$@" || return 1
chroot-run -B "$mirror" "$mnt" \ chroot-run "$mnt" \
pacman -v -Sp --noconfirm "$@" > "$list" pacman -v -Sp --noconfirm "$@" > "$list"
sed -ni '/.pkg.tar.xz/p' "$list" sed -ni '/.pkg.tar.xz/p' "$list"
sed -i "s/.*\///" "$list" sed -i "s/.*\///" "$list"

View file

@ -62,13 +62,6 @@ check_user_repos_conf(){
done done
} }
get_pac_mirrors_conf(){
local conf="$tmp_dir/pacman-mirrors-$1.conf"
cp "${DATADIR}/pacman-mirrors.conf" "$conf"
sed -e "s|@branch@|$1|" -i "$conf"
echo "$conf"
}
# $1: list_dir # $1: list_dir
show_build_lists(){ show_build_lists(){
local list temp local list temp
@ -319,14 +312,14 @@ show_config(){
read_build_list(){ read_build_list(){
local _space="s| ||g" _clean=':a;N;$!ba;s/\n/ /g' _com_rm="s|#.*||g" local _space="s| ||g" _clean=':a;N;$!ba;s/\n/ /g' _com_rm="s|#.*||g"
echo $(sed "$_com_rm" "$1.list" | sed "$_space" | sed "$_clean") build_list=$(sed "$_com_rm" "$1.list" | sed "$_space" | sed "$_clean")
} }
# $1: list_dir # $1: list_dir
# $2: build list # $2: build list
eval_build_list(){ eval_build_list(){
eval "case $2 in eval "case $2 in
$(show_build_lists $1)) is_build_list=true; build_list=$(read_build_list $1/$2) ;; $(show_build_lists $1)) is_build_list=true; read_build_list $1/$2 ;;
*) is_build_list=false ;; *) is_build_list=false ;;
esac" esac"
} }