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,10 +26,14 @@ newroot=/mnt
hostcache=false
copykeyring=true
copymirrorlist=true
branch=stable
usage() {
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 " -P <config> Use an alternate config file for pacman-mirrors"
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"
@ -51,16 +55,19 @@ usage() {
orig_argv=("$0" "$@")
opts=':C:cdGiM'
opts=':C:P:cdGiM:B:U'
while getopts ${opts} arg; do
case "${arg}" in
C) pacman_config=$OPTARG ;;
P) mirrors_conf="$OPTARG" ;;
d) directory=true ;;
c) hostcache=true ;;
i) interactive=true ;;
G) copykeyring=false ;;
M) copymirrorlist=false ;;
B) branch="$OPTARG" ;;
U) mirror="$OPTARG" ;;
:) echo "invalid argument ${arg}:$OPTARG"; usage 1;;
?) usage 0 ;;
esac
@ -78,6 +85,7 @@ ${hostcache} && pacman_args+=(--cachedir="$newroot/var/cache/pacman/pkg")
${interactive} && pacman_args+=(--noconfirm)
[[ -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"
@ -85,9 +93,23 @@ if ! mountpoint -q "$newroot" && ! ${directory}; then
die '%s is not a mountpoint!' "$newroot"
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_min_fs "$newroot"
info "Configuring pacman-mirrors: %s" "${branch}"
pacman-mirrors "${pm_args[@]}"
# mount API filesystems
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'
fi
# kill chroot process if needed (TODO: check if needed at all)
# kill_chroot_process "$newroot"
if ${copykeyring};then
copy_keyring "$newroot"
fi

View file

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

View file

@ -111,11 +111,9 @@ prepare_build(){
[[ "$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} -B ${mirror})
mkchroot_args+=(-C ${pacman_conf} -M ${makepkg_conf} -S ${mirrors_conf} -U ${build_mirror} -B "${target_branch}")
mkchrootpkg_args+=(-r ${work_dir})

View file

@ -37,15 +37,13 @@ usage() {
echo ' -r <list> Bind mountargs ro'
echo ' -w <list> Bind mountargs rw'
echo ' List format [src1:target1 ... srcN:targetN]'
echo ' -B Use custom build mirror'
echo ' -K Keep mirrorlist (-B)'
echo ' -h This message'
exit 1
}
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
case "${arg}" in
@ -57,8 +55,6 @@ while getopts ${opts} arg; do
s) nosetarch=true ;;
r) bindmounts_ro=("$OPTARG") ;;
w) bindmounts_rw=("$OPTARG") ;;
B) build_mirror="$OPTARG" ;;
K) keep_mirrors=true ;;
h|?) usage ;;
*) error "invalid argument '$arg'"; usage ;;
esac
@ -86,7 +82,6 @@ copy_hostconf () {
[[ -n $pac_conf ]] && cp $pac_conf "$1/etc/pacman.conf"
[[ -n $makepkg_conf ]] && cp $makepkg_conf "$1/etc/makepkg.conf"
[[ -n $mirrors_conf ]] && cp ${mirrors_conf} "$1/etc/pacman-mirrors.conf"
local file
for file in "${files[@]}"; do
@ -94,20 +89,6 @@ copy_hostconf () {
cp -T "$file" "$working_dir$file"
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"
}

View file

@ -25,6 +25,7 @@ build_locales=false
keep_mirrors=false
keep_flag=''
nosetarch=false
branch=stable
usage() {
echo "Usage: ${0##*/} [options] working-dir package-list..."
@ -32,20 +33,18 @@ usage() {
echo ' -C <file> Location of a pacman config file'
echo ' -M <file> Location of a makepkg 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 ' -f <file> Copy file from the host to the chroot'
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'
exit 1
}
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
case "${arg}" in
@ -55,9 +54,8 @@ while getopts ${opts} arg; do
c) cache_dir="$OPTARG" ;;
f) files+=("$OPTARG") ;;
s) nosetarch=true ;;
L) build_locales=true ;;
B) build_mirror="$OPTARG" ;;
K) keep_mirrors=true; keep_flag='-K' ;;
B) branch="$OPTARG" ;;
U) mirror="$OPTARG" ;;
h|?) usage ;;
*) error "invalid argument '%s'" "$arg"; usage ;;
esac
@ -102,44 +100,21 @@ for file in "${files[@]}"; do
cp "$file" "$working_dir$file"
done
# Workaround when creating a chroot in a branch different of the host
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
basestrap_args=(-GMcd ${pac_conf:+-C "$pac_conf"} ${cache_dirs[@]/#/--cachedir=} -B ${branch:+-"$branch"} ${mirrors_conf:+-P "$mirrors_conf"})
_env=()
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'
[[ -n ${mirror} ]] && basestrap_args+=(-U "${mirror}")
[[ -f "$pac_base" ]] && rm "$pac_base"
else
_env=()
while read -r varname; do
_env=()
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_conf:+-C "$pac_conf"} "$working_dir" \
"${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages'
fi
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'
echo "$version" > "$working_dir/.manjaro-tools"
if ${build_locales};then
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})
chroot_args=(${pac_conf:+-C "$pac_conf"} ${makepkg_conf:+-M "$makepkg_conf"} ${cache_dir:+-c "$cache_dir"})
${nosetarch} && chroot_args+=(${nosetarch:+-s})
exec chroot-run \

View file

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

View file

@ -236,11 +236,11 @@ clean_up_image(){
}
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
chroot-run -B "$mirror" "$mnt" \
chroot-run "$mnt" \
pacman -v -Syw --noconfirm "$@" || return 1
chroot-run -B "$mirror" "$mnt" \
chroot-run "$mnt" \
pacman -v -Sp --noconfirm "$@" > "$list"
sed -ni '/.pkg.tar.xz/p' "$list"
sed -i "s/.*\///" "$list"

View file

@ -62,13 +62,6 @@ check_user_repos_conf(){
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
show_build_lists(){
local list temp
@ -319,14 +312,14 @@ show_config(){
read_build_list(){
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
# $2: build list
eval_build_list(){
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 ;;
esac"
}