diff --git a/bin/buildpkg.in b/bin/buildpkg.in
index 744700a..8ac1183 100644
--- a/bin/buildpkg.in
+++ b/bin/buildpkg.in
@@ -50,7 +50,9 @@ display_settings(){
msg "ARGS:"
+ msg2 "create_first: %s" "${create_first}"
msg2 "clean_first: %s" "${clean_first}"
+ msg2 "update_first: %s" "${update_first}"
msg2 "wipe_clean: %s" "${wipe_clean}"
msg2 "namcap: %s" "${namcap}"
msg2 "sign: %s" "${sign}"
@@ -59,7 +61,7 @@ display_settings(){
msg "PATHS:"
msg2 "pkg_dir: %s" "${pkg_dir}"
- if ${clean_first};then
+ if ${create_first};then
msg "PKG:"
msg2 "base_packages: %s" "${base_packages[*]}"
fi
@@ -74,9 +76,8 @@ load_config "${MT_USERCONFDIR}/manjaro-tools.conf" || load_config "${SYSCONFDIR}
load_vars "${PAC_USERCONFDIR}/makepkg.conf" || load_vars "$USER_HOME/.makepkg.conf"
load_vars /etc/makepkg.conf
-install_pkgs=()
-
clean_first=false
+update_first=false
wipe_clean=false
namcap=false
pretend=false
@@ -84,6 +85,48 @@ is_build_list=false
sign=false
udev_root=false
is_multilib=false
+create_first=false
+
+mkchroot_args=()
+mkchrootpkg_args=()
+
+install_pkgs=()
+
+# $1: target_arch
+prepare_build(){
+ local arch="$1"
+ if ! is_valid_arch_pkg "${arch}";then
+ die "%s is not a valid arch!" "${arch}"
+ fi
+
+ local pac_arch='default'
+
+ if [[ "${arch}" == 'multilib' ]];then
+ pac_arch='multilib'
+ is_multilib=true
+ fi
+
+ local pacman_conf="${DATADIR}/pacman-$pac_arch.conf"
+
+ work_dir="${chroots_pkg}/${target_branch}/${arch}"
+ pkg_dir="${cache_dir_pkg}/${target_branch}/${arch}"
+
+ local makepkg_conf=$(get_makepkg_conf "${arch}")
+
+ [[ "$pac_arch" == 'multilib' ]] && target_arch='x86_64'
+
+ local mirror="${build_mirror}/${target_branch}"
+
+ local mirrors_conf=$(get_pac_mirrors_conf "${target_branch}")
+
+ mkchroot_args+=(-C ${pacman_conf} -M ${makepkg_conf} -S ${mirrors_conf} -B ${mirror})
+
+ mkchrootpkg_args+=(-r ${work_dir})
+
+ eval_build_list "${list_dir_pkg}" "${build_list_pkg}"
+
+ timer_start=$(get_timer)
+}
usage() {
echo "Usage: ${0##*/} [options]"
@@ -93,11 +136,13 @@ usage() {
echo ' -r
Chroots directory'
echo " [default: ${chroots_pkg}]"
echo ' -i Install packages into the working copy of the chroot'
- echo ' -c Recreate chroot'
+ echo ' -o Create chroot'
+ echo ' -c Clean chroot copy'
+ echo ' -u Update chroot copy'
echo ' -w Clean up cache and sources'
echo ' -n Install and run namcap check'
echo ' -s Sign packages'
- echo ' -u Udev base-devel group (no systemd)'
+ echo ' -d Udev base-devel group (no systemd)'
echo ' -q Query settings and pretend build'
echo ' -h This help'
echo ''
@@ -107,7 +152,7 @@ usage() {
orig_argv=("$0" "$@")
-opts='p:a:b:r:i:cwnsuqh'
+opts='p:a:b:r:i:cownsudqh'
while getopts "${opts}" arg; do
case "${arg}" in
@@ -115,12 +160,14 @@ while getopts "${opts}" arg; do
a) target_arch="$OPTARG" ;;
b) target_branch="$OPTARG" ;;
r) chroots_pkg="$OPTARG" ;;
- i) install_pkgs+=("$OPTARG"); mkchrootpkg_args+=(-I ${install_pkgs[*]}) ;;
- c) clean_first=true ;;
+ i) install_pkgs+=("$OPTARG"); mkchrootpkg_args+=(-I "${install_pkgs[*]}") ;;
+ o) create_first=true ;;
+ c) clean_first=true ; mkchrootpkg_args+=(-c) ;;
+ u) update_first=true ; mkchrootpkg_args+=(-u) ;;
w) wipe_clean=true ;;
n) namcap=true; mkchrootpkg_args+=(-n) ;;
s) sign=true ;;
- u) udev_root=true ;;
+ d) udev_root=true ;;
q) pretend=true ;;
h|?) usage 0 ;;
*) echo "invalid argument '${arg}'"; usage 1 ;;
@@ -131,32 +178,10 @@ shift $(($OPTIND - 1))
check_root
-prepare_dir "${log_dir}"
-
-prepare_dir "${tmp_dir}"
-
-prepare_conf "${target_arch}"
-
-mirrors_conf=$(get_pac_mirrors_conf "${target_branch}")
-
-mkchroot_args+=(-C ${pacman_conf} -M ${makepkg_conf} -S ${mirrors_conf} -B "${build_mirror}/${target_branch}")
-
-mkchrootpkg_args+=(-r ${work_dir})
-
-timer_start=$(get_timer)
-
-eval_build_list "${list_dir_pkg}" "${build_list_pkg}"
-
-prepare_dir "${pkg_dir}"
-
-user_own "${pkg_dir}"
-
-init_base_devel
+prepare_build "${target_arch}"
${pretend} && display_settings && exit
-${wipe_clean} && clean_up
-
-chroot_init
+${create_first} && chroot_init "${work_dir}"
run make_pkg "${build_list_pkg}"
diff --git a/bin/mkchrootpkg.in b/bin/mkchrootpkg.in
index 279cd2c..b64248f 100644
--- a/bin/mkchrootpkg.in
+++ b/bin/mkchrootpkg.in
@@ -55,7 +55,7 @@ usage() {
echo ''
echo 'The chroot "root" directory must be created via the following'
echo 'command:'
- echo ' mkarchroot /root base-devel'
+ echo ' mkchroot /root base-devel'
echo ''
echo 'This script reads {SRC,SRCPKG,PKG,LOG}DEST, MAKEFLAGS and PACKAGER'
echo 'from makepkg.conf(5), if those variables are not part of the'
@@ -324,7 +324,7 @@ main() {
# Canonicalize chrootdir, getting rid of trailing /
chrootdir=$(readlink -e "$passeddir")
[[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir"
- [[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir"
+ [[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkchroot %s/root base-devel" "$chrootdir"
if [[ ${copy:0:1} = / ]]; then
copydir=$copy
diff --git a/lib/util-pkg-chroot.sh b/lib/util-pkg-chroot.sh
index 3ea76c3..80202ba 100644
--- a/lib/util-pkg-chroot.sh
+++ b/lib/util-pkg-chroot.sh
@@ -22,11 +22,14 @@ load_compiler_settings(){
}
get_makepkg_conf(){
- local conf="${tmp_dir}/makepkg-$1.conf"
+ prepare_dir "${tmp_dir}"
+
+ local arch="$1"
+ local conf="${tmp_dir}/makepkg-${arch}.conf"
cp "${DATADIR}/makepkg.conf" "$conf"
- load_compiler_settings "$1"
+ load_compiler_settings "${arch}"
sed -i "$conf" \
-e "s|@CARCH[@]|$carch|g" \
@@ -36,48 +39,23 @@ get_makepkg_conf(){
echo "$conf"
}
-# $1: target_arch
-prepare_conf(){
- if ! is_valid_arch_pkg "$1";then
- die "%s is not a valid arch!" "$1"
- fi
-
- local pac_arch='default'
-
- if [[ "$1" == 'multilib' ]];then
- pac_arch='multilib'
- is_multilib=true
- fi
-
- pacman_conf="${DATADIR}/pacman-$pac_arch.conf"
-
- work_dir="${chroots_pkg}/${target_branch}/$1"
- pkg_dir="${cache_dir_pkg}/${target_branch}/$1"
-
- makepkg_conf=$(get_makepkg_conf "$1")
-
- [[ "$pac_arch" == 'multilib' ]] && target_arch='x86_64'
-}
-
check_build(){
- find_pkg $1
- [[ ! -f $1/PKGBUILD ]] && die "Directory must contain a PKGBUILD!"
+ local bdir="$1"
+ find_pkg "${bdir}"
+ [[ ! -f ${bdir}/PKGBUILD ]] && die "Directory must contain a PKGBUILD!"
}
find_pkg(){
- local result=$(find . -type d -name "$1")
- [[ -z $result ]] && die "%s is not a valid package or build list!" "$1"
+ local bdir="$1"
+ local result=$(find . -type d -name "${bdir}")
+ [[ -z $result ]] && die "%s is not a valid package or build list!" "${bdir}"
}
-load_group(){
- local _multi \
- _space="s| ||g" \
- _clean=':a;N;$!ba;s/\n/ /g' \
- _com_rm="s|#.*||g" \
- devel_group='' \
- file=${DATADIR}/base-devel-udev
+base_devel_udev(){
+ local _multi _space="s| ||g" _clean=':a;N;$!ba;s/\n/ /g' _com_rm="s|#.*||g"
+ local devel_group='' file=${DATADIR}/base-devel-udev
- info "Loading custom group: %s" "$file"
+ info "Loading custom group: %s" "$file"
if ${is_multilib}; then
_multi="s|>multilib||g"
@@ -90,12 +68,12 @@ load_group(){
| sed "$_multi" \
| sed "$_clean")
- echo ${devel_group}
+ echo ${devel_group}
}
init_base_devel(){
if ${udev_root};then
- base_packages=( "$(load_group)" )
+ base_packages=( "$(base_devel_udev)" )
else
if ${is_multilib};then
base_packages=('base-devel' 'multilib-devel')
@@ -105,38 +83,8 @@ init_base_devel(){
fi
}
-chroot_create(){
- msg "Creating chroot for [%s] (%s)..." "${target_branch}" "${target_arch}"
- mkdir -p "${work_dir}"
- mkchroot_args+=(-L)
- setarch "${target_arch}" \
- mkchroot ${mkchroot_args[*]} \
- "${work_dir}/root" \
- ${base_packages[*]} || abort
-}
-
-chroot_clean(){
- msg "Cleaning chroot for [%s] (%s)..." "${target_branch}" "${target_arch}"
- for root in "$1"/*; do
- [[ -d ${root} ]] || continue
- stat_busy "Deleting chroot copy %s ..." "${copy##*/}"
- lock 9 "%s.lock" "Locking chroot copy '%s'" "${root}" "${root}"
- subvolume_delete_recursive "${root}"
- rm -rf --one-file-system "${root}"
- done
- lock_close 9
- rm -rf --one-file-system "$1"
-}
-
-chroot_update(){
- msg "Updating chroot for [%s] (%s)..." "${target_branch}" "${target_arch}"
- chroot-run ${mkchroot_args[*]} \
- "${work_dir}/${OWNER}" \
- pacman -Syu --noconfirm || abort
-}
-
clean_up(){
- msg "Cleaning up ..."
+# msg "Cleaning up ..."
msg2 "Cleaning [%s]" "${pkg_dir}"
find ${pkg_dir} -maxdepth 1 -name "*.*" -delete #&> /dev/null
if [[ -z $SRCDEST ]];then
@@ -146,35 +94,38 @@ clean_up(){
}
sign_pkg(){
- su ${OWNER} -c "signfile ${pkg_dir}/$1"
+ local pkg="$1"
+ su ${OWNER} -c "signfile ${pkg_dir}/${pkg}"
}
move_to_cache(){
+ prepare_dir "${log_dir}"
+
local src="$1"
- [[ -n $PKGDEST ]] && src="$PKGDEST/$1"
+ [[ -n $PKGDEST ]] && src="$PKGDEST/$src"
[[ ! -f $src ]] && die
msg2 "Moving [%s] -> [%s]" "${src##*/}" "${pkg_dir}"
mv $src ${pkg_dir}/
${sign} && sign_pkg "${src##*/}"
- [[ -n $PKGDEST ]] && rm "$1"
+# [[ -n $PKGDEST ]] && rm "$src"
user_own "${pkg_dir}" "-R"
}
archive_logs(){
- local archive name="$1" ext=log.tar.xz ver src=${tmp_dir}/archives.list target='.'
+ local archive name="$1" ext=log.tar.xz ver src=${tmp_dir}/archives.list dest='.'
ver=$(get_full_version "$name")
archive="${name}-${ver}-${target_arch}"
if [[ -n $LOGDEST ]];then
- target=$LOGDEST
- find $target -maxdepth 1 -name "$archive*.log" -printf "%f\n" > $src
+ dest=$LOGDEST
+ find ${dest} -maxdepth 1 -name "$archive*.log" -printf "%f\n" > $src
else
- find $target -maxdepth 1 -name "$archive*.log" > $src
+ find ${dest} -maxdepth 1 -name "$archive*.log" > $src
fi
msg2 "Archiving log files [%s] ..." "$archive.$ext"
- tar -cJf ${log_dir}/$archive.$ext -C "$target" -T $src
+ tar -cJf ${log_dir}/$archive.$ext -C "${dest}" -T $src
msg2 "Cleaning log files ..."
- find $target -maxdepth 1 -name "$archive*.log" -delete
+ find ${dest} -maxdepth 1 -name "$archive*.log" -delete
}
post_build(){
@@ -195,28 +146,35 @@ post_build(){
chroot_init(){
local timer=$(get_timer)
- if ${clean_first} || [[ ! -d "${work_dir}" ]]; then
- chroot_clean "${work_dir}"
- chroot_create
- else
- chroot_update
- fi
+ local dest="$1"
+ init_base_devel
+ msg "Initialize chroot for [%s] (%s)..." "${target_branch}" "${target_arch}"
+ mkdir -p "${dest}"
+ setarch "${target_arch}" \
+ mkchroot "${mkchroot_args[@]}" \
+ "${dest}/root" \
+ "${base_packages[@]}" || abort
+
show_elapsed_time "${FUNCNAME}" "${timer}"
}
build_pkg(){
+ prepare_dir "${pkg_dir}"
+ user_own "${pkg_dir}"
+ ${wipe_clean} && clean_up
setarch "${target_arch}" \
- mkchrootpkg ${mkchrootpkg_args[*]}
+ mkchrootpkg "${mkchrootpkg_args[@]}"
post_build
}
make_pkg(){
- check_build "$1"
- msg "Start building [%s]" "$1"
- cd $1
+ local pkg="$1"
+ check_build "${pkg}"
+ msg "Start building [%s]" "${pkg}"
+ cd ${pkg}
build_pkg
cd ..
- msg "Finished building [%s]" "$1"
+ msg "Finished building [%s]" "${pkg}"
show_elapsed_time "${FUNCNAME}" "${timer_start}"
}