manjaro-tools/lib/util-pkg-chroot.sh

166 lines
4.2 KiB
Bash
Raw Normal View History

2017-03-27 18:07:26 +02:00
#!/bin/bash
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
load_compiler_settings(){
local arch="$1" conf
conf=${make_conf_dir}/$arch.conf
2017-03-27 18:07:26 +02:00
[[ -f $conf ]] || return 1
info "Loading compiler settings: %s" "$arch"
2017-03-27 18:07:26 +02:00
source $conf
return 0
}
get_makepkg_conf(){
prepare_dir "${tmp_dir}"
local arch="$1"
local conf="${tmp_dir}/makepkg-${arch}.conf"
2017-03-27 18:07:26 +02:00
cp "${DATADIR}/makepkg.conf" "$conf"
load_compiler_settings "${arch}"
2017-03-27 18:07:26 +02:00
sed -i "$conf" \
-e "s|@CARCH[@]|$carch|g" \
-e "s|@CHOST[@]|$chost|g" \
-e "s|@CFLAGS[@]|$cflags|g"
echo "$conf"
}
check_build(){
local bdir="$1"
find_pkg "${bdir}"
[[ ! -f ${bdir}/PKGBUILD ]] && die "Directory must contain a PKGBUILD!"
2017-03-27 18:07:26 +02:00
}
find_pkg(){
local bdir="$1"
local result=$(find . -type d -name "${bdir}")
[[ -z $result ]] && die "%s is not a valid package or build list!" "${bdir}"
2017-03-27 18:07:26 +02:00
}
init_base_devel(){
if ${udev_root};then
local _multi _space="s| ||g" _clean=':a;N;$!ba;s/\n/ /g' _com_rm="s|#.*||g"
local file=${DATADIR}/base-devel-udev
2017-03-27 18:07:26 +02:00
# info "Loading custom group: %s" "$file"
2017-04-28 02:39:11 +02:00
_multi="s|>multilib.*||g"
${is_multilib} && _multi="s|>multilib||g"
2017-03-27 18:07:26 +02:00
base_packages=($(sed "$_com_rm" "$file" \
| sed "$_space" \
| sed "$_multi" \
| sed "$_clean"))
2017-03-27 18:07:26 +02:00
else
2017-04-28 02:39:11 +02:00
base_packages=('base-devel')
${is_multilib} && base_packages+=('multilib-devel')
2017-03-27 18:07:26 +02:00
fi
}
clean_up(){
# msg "Cleaning up ..."
2017-03-27 18:07:26 +02:00
msg2 "Cleaning [%s]" "${pkg_dir}"
find ${pkg_dir} -maxdepth 1 -name "*.*" -delete #&> /dev/null
if [[ -z $SRCDEST ]];then
msg2 "Cleaning [source files]"
find $PWD -maxdepth 1 -name '*.?z?' -delete #&> /dev/null
fi
}
sign_pkg(){
local pkg="$1"
su ${OWNER} -c "signfile ${pkg_dir}/${pkg}"
2017-03-27 18:07:26 +02:00
}
move_to_cache(){
prepare_dir "${log_dir}"
2017-03-27 18:07:26 +02:00
local src="$1"
[[ -n $PKGDEST ]] && src="$PKGDEST/$src"
2017-03-27 18:07:26 +02:00
[[ ! -f $src ]] && die
msg2 "Moving [%s] -> [%s]" "${src##*/}" "${pkg_dir}"
mv $src ${pkg_dir}/
${sign} && sign_pkg "${src##*/}"
# [[ -n $PKGDEST ]] && rm "$src"
2017-03-27 18:07:26 +02:00
user_own "${pkg_dir}" "-R"
}
archive_logs(){
local archive name="$1" ext=log.tar.xz ver src=${tmp_dir}/archives.list dest='.'
2017-03-27 18:07:26 +02:00
ver=$(get_full_version "$name")
archive="${name}-${ver}-${target_arch}"
if [[ -n $LOGDEST ]];then
dest=$LOGDEST
find ${dest} -maxdepth 1 -name "$archive*.log" -printf "%f\n" > $src
2017-03-27 18:07:26 +02:00
else
find ${dest} -maxdepth 1 -name "$archive*.log" > $src
2017-03-27 18:07:26 +02:00
fi
msg2 "Archiving log files [%s] ..." "$archive.$ext"
tar -cJf ${log_dir}/$archive.$ext -C "${dest}" -T $src
2017-03-27 18:07:26 +02:00
msg2 "Cleaning log files ..."
find ${dest} -maxdepth 1 -name "$archive*.log" -delete
2017-03-27 18:07:26 +02:00
}
post_build(){
source PKGBUILD
local ext='pkg.tar.xz' tarch ver src
for pkg in ${pkgname[@]};do
case $arch in
any) tarch='any' ;;
*) tarch=${target_arch}
esac
local ver=$(get_full_version "$pkg") src
src=$pkg-$ver-$tarch.$ext
move_to_cache "$src"
done
local name=${pkgbase:-$pkgname}
archive_logs "$name"
}
chroot_init(){
local timer=$(get_timer)
local dest="$1"
mkdir -p "${dest}"
setarch "${target_arch}" \
mkchroot "${mkchroot_args[@]}" \
"${dest}/root" \
"${base_packages[@]}" || abort
2017-03-27 18:07:26 +02:00
show_elapsed_time "${FUNCNAME}" "${timer}"
}
build_pkg(){
prepare_dir "${pkg_dir}"
user_own "${pkg_dir}"
${purge} && clean_up
2017-03-27 18:07:26 +02:00
setarch "${target_arch}" \
mkchrootpkg "${mkchrootpkg_args[@]}"
2017-03-27 18:07:26 +02:00
post_build
}
make_pkg(){
local pkg="$1"
check_build "${pkg}"
msg "Start building [%s]" "${pkg}"
cd ${pkg}
2017-03-27 18:07:26 +02:00
build_pkg
cd ..
msg "Finished building [%s]" "${pkg}"
2017-03-27 18:07:26 +02:00
show_elapsed_time "${FUNCNAME}" "${timer_start}"
}