Merge branch 'master' of github.com:manjaro/manjaro-tools

This commit is contained in:
udeved 2017-03-28 17:55:13 +02:00
commit feda1e7659
7 changed files with 309 additions and 278 deletions

View file

@ -42,8 +42,7 @@ BIN_PKG = \
bin/buildtree
LIBS_PKG = \
lib/util-pkg.sh \
lib/util-pkgtree.sh
$(wildcard lib/util-pkg*.sh)
SHARED_PKG = \
data/makepkg.conf \

View file

@ -21,6 +21,7 @@ SYSCONFDIR='@sysconfdir@'
import ${LIBDIR}/util.sh
import ${LIBDIR}/util-pkg.sh
import ${LIBDIR}/util-pkg-chroot.sh
show_pkg(){
check_build "$1"

View file

@ -15,22 +15,7 @@ LIBDIR='@libdir@'
[[ -r ${LIBDIR}/util-msg.sh ]] && source ${LIBDIR}/util-msg.sh
# $1: sofile
# $2: soarch
process_sofile() {
# extract the library name: libfoo.so
local soname="${1%.so?(+(.+([0-9])))}".so
# extract the major version: 1
soversion="${1##*\.so\.}"
if [[ "$soversion" = "$1" ]] && (($IGNORE_INTERNAL)); then
continue
fi
if ! in_array "${soname}=${soversion}-$2" ${soobjects[@]}; then
# libfoo.so=1-64
msg "${soname}=${soversion}-$2"
soobjects+=("${soname}=${soversion}-$2")
fi
}
import ${LIBDIR}/util-pkg.sh
set -e
shopt -s extglob

View file

@ -43,24 +43,6 @@ prepare_boot_extras(){
cp $1/usr/share/licenses/common/GPL2/license.txt $2/memtest.COPYING
}
configure_grub(){
local default_args="misobasedir=${iso_name} misolabel=${iso_label}" \
video_args="nouveau.modeset=1 i915.modeset=1 radeon.modeset=1" \
boot_args=(quiet)
[[ $2 == 'systemd' ]] && boot_args+=(systemd.show_status=1)
local mhwd_args="nonfree=$4"
sed -e "s|@DIST_NAME@|${dist_name}|g" \
-e "s|@ARCH@|${target_arch}|g" \
-e "s|@DEFAULT_ARGS@|${default_args}|g" \
-e "s|@VIDEO_ARGS@|${video_args}|g" \
-e "s|@BOOT_ARGS@|${boot_args[@]}|g" \
-e "s|@MHWD_ARGS@|${mhwd_args}|g" \
-e "s|@PROFILE@|$3|g" \
-i $1
}
prepare_grub(){
local platform=i386-pc img='core.img' grub=$2/boot/grub efi=$2/efi/boot \
data=$1/usr/share/grub lib=$1/usr/lib/grub prefix=/boot/grub
@ -100,14 +82,14 @@ prepare_grub(){
prepare_dir ${grub}/themes
cp -r ${data}/themes/${iso_name}-live ${grub}/themes/
cp ${data}/unicode.pf2 ${grub}
cp -r ${data}/{locales,tz} ${grub}
cp -r ${data}/{locales,tz,video} ${grub}
local size=8M mnt="${mnt_dir}/efiboot" efi_img="$2/efi.img"
msg2 "Creating fat image of %s ..." "${size}"
truncate -s ${size} "${efi_img}"
mkfs.fat -n MISO_EFI "${efi_img}" &>/dev/null
prepare_dir "${mnt}"
mount_img "${efi_img}" "${mnt}"
mount_img "${efi_img}" "${mnt}"
prepare_dir ${mnt}/efi/boot
msg2 "Building %s ..." "${img}"
grub-mkimage -d ${grub}/${platform} -o ${mnt}/efi/boot/${img} -O ${platform} -p ${prefix} iso9660

View file

@ -166,27 +166,50 @@ assemble_iso(){
iso_publisher="$(get_osname) <$(get_disturl)>"
iso_app_id="$(get_osname) Live/Rescue CD"
# xorriso -as mkisofs \
# --protective-msdos-label \
# -volid "${iso_label}" \
# -appid "${iso_app_id}" \
# -publisher "${iso_publisher}" \
# -preparer "Prepared by manjaro-tools/${0##*/}" \
# -e /efi.img \
# -b boot/grub/i386-pc/eltorito.img \
# -c boot.catalog \
# -no-emul-boot \
# -boot-load-size 4 \
# -boot-info-table \
# -graft-points \
# --grub2-boot-info \
# --grub2-mbr ${iso_root}/boot/grub/i386-pc/boot_hybrid.img \
# --sort-weight 0 / --sort-weight 1 /boot \
# -isohybrid-gpt-basdat \
# -eltorito-alt-boot \
# -output "${iso_dir}/${iso_file}" \
# "${iso_root}/"
xorriso -as mkisofs \
--protective-msdos-label \
-volid "${iso_label}" \
-appid "${iso_app_id}" \
-publisher "${iso_publisher}" \
-preparer "Prepared by manjaro-tools/${0##*/}" \
-e /efi.img \
-b boot/grub/i386-pc/eltorito.img \
-c boot.catalog \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-graft-points \
--grub2-boot-info \
--grub2-mbr ${iso_root}/boot/grub/i386-pc/boot_hybrid.img \
--sort-weight 0 / --sort-weight 1 /boot \
-isohybrid-gpt-basdat \
-eltorito-alt-boot \
-output "${iso_dir}/${iso_file}" \
"${iso_root}/"
--protective-msdos-label \
-volid "${iso_label}" \
-appid "${iso_app_id}" \
-publisher "${iso_publisher}" \
-preparer "Prepared by manjaro-tools/${0##*/}" \
-b boot/grub/i386-pc/eltorito.img \
-c boot.catalog \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-graft-points \
--grub2-boot-info \
--grub2-mbr ${iso_root}/boot/grub/i386-pc/boot_hybrid.img \
--sort-weight 0 / --sort-weight 1 /boot \
-eltorito-alt-boot \
-efi-boot-part --efi-boot-image \
-e efi.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
-output "${iso_dir}/${iso_file}" \
"${iso_root}/"
}
# Build ISO
@ -344,7 +367,7 @@ make_image_boot() {
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
msg "Prepare [/iso/boot]"
local boot="${iso_root}/boot"
mkdir -p ${boot}
cp ${work_dir}/rootfs/boot/vmlinuz* ${boot}/vmlinuz-${target_arch}
@ -372,16 +395,29 @@ make_image_boot() {
fi
}
configure_grub(){
local default_args="misobasedir=${iso_name} misolabel=${iso_label}" \
boot_args=('quiet')
[[ ${initsys} == 'systemd' ]] && boot_args+=('systemd.show_status=1')
sed -e "s|@DIST_NAME@|${dist_name}|g" \
-e "s|@ARCH@|${target_arch}|g" \
-e "s|@DEFAULT_ARGS@|${default_args}|g" \
-e "s|@BOOT_ARGS@|${boot_args[*]}|g" \
-e "s|@PROFILE@|${profile}|g" \
-i $1
}
make_grub(){
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
msg "Prepare [/iso/boot/grub]"
local path="${work_dir}/rootfs"
prepare_grub "${path}" "${iso_root}"
configure_grub "${iso_root}/boot/grub/kernels.cfg" "${initsys}" "${profile}" "${nonfree_mhwd}"
configure_grub "${iso_root}/boot/grub/kernels.cfg"
: > ${work_dir}/build.${FUNCNAME}
msg "Done [/iso/boot/grub]"
fi
@ -432,7 +468,7 @@ prepare_images(){
fi
run_safe "make_image_boot"
run_safe "make_grub"
show_elapsed_time "${FUNCNAME}" "${timer}"
}
@ -449,7 +485,7 @@ make_profile(){
msg "Start building [%s]" "${profile}"
if ${clean_first};then
chroot_clean "${chroots_iso}/${profile}/${target_arch}"
local unused_arch=''
case ${target_arch} in
i686) unused_arch='x86_64' ;;
@ -460,7 +496,7 @@ make_profile(){
fi
clean_iso_root "${iso_root}"
fi
if ${iso_only}; then
[[ ! -d ${work_dir} ]] && die "Create images: buildiso -p %s -x" "${profile}"
compress_images

226
lib/util-pkg-chroot.sh Normal file
View file

@ -0,0 +1,226 @@
#!/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 tarch="$1" conf
conf=${make_conf_dir}/$tarch.conf
[[ -f $conf ]] || return 1
info "Loading compiler settings: %s" "$tarch"
source $conf
return 0
}
get_makepkg_conf(){
local conf="${tmp_dir}/makepkg-$1.conf"
cp "${DATADIR}/makepkg.conf" "$conf"
load_compiler_settings "$1"
sed -i "$conf" \
-e "s|@CARCH[@]|$carch|g" \
-e "s|@CHOST[@]|$chost|g" \
-e "s|@CFLAGS[@]|$cflags|g"
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!"
}
find_pkg(){
local result=$(find . -type d -name "$1")
[[ -z $result ]] && die "%s is not a valid package or build list!" "$1"
}
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
info "Loading custom group: %s" "$file"
if ${is_multilib}; then
_multi="s|>multilib||g"
else
_multi="s|>multilib.*||g"
fi
devel_group=$(sed "$_com_rm" "$file" \
| sed "$_space" \
| sed "$_multi" \
| sed "$_clean")
echo ${devel_group}
}
init_base_devel(){
if ${udev_root};then
base_packages=( "$(load_group)" )
else
if ${is_multilib};then
base_packages=('base-devel' 'multilib-devel')
else
base_packages=('base-devel')
fi
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 copy in "${work_dir}"/*; do
[[ -d ${copy} ]] || continue
msg2 "Deleting chroot copy %s ..." "$(basename "${copy}")"
lock 9 "${copy}.lock" "Locking chroot copy '${copy}'"
subvolume_delete_recursive "${copy}"
rm -rf --one-file-system "${copy}"
done
exec 9>&-
rm -rf --one-file-system "${work_dir}"
}
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 ..."
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(){
su ${OWNER} -c "signfile ${pkg_dir}/$1"
}
move_to_cache(){
local src="$1"
[[ -n $PKGDEST ]] && src="$PKGDEST/$1"
[[ ! -f $src ]] && die
msg2 "Moving [%s] -> [%s]" "${src##*/}" "${pkg_dir}"
mv $src ${pkg_dir}/
${sign} && sign_pkg "${src##*/}"
[[ -n $PKGDEST ]] && rm "$1"
user_own "${pkg_dir}" "-R"
}
archive_logs(){
local archive name="$1" ext=log.tar.xz ver src=${tmp_dir}/archives.list target='.'
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
else
find $target -maxdepth 1 -name "$archive*.log" > $src
fi
msg2 "Archiving log files [%s] ..." "$archive.$ext"
tar -cJf ${log_dir}/$archive.$ext -C "$target" -T $src
msg2 "Cleaning log files ..."
find $target -maxdepth 1 -name "$archive*.log" -delete
}
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)
if ${clean_first} || [[ ! -d "${work_dir}" ]]; then
chroot_clean
chroot_create
else
chroot_update
fi
show_elapsed_time "${FUNCNAME}" "${timer}"
}
build_pkg(){
setarch "${target_arch}" \
mkchrootpkg ${mkchrootpkg_args[*]}
post_build
}
make_pkg(){
check_build "$1"
msg "Start building [%s]" "$1"
cd $1
build_pkg
cd ..
msg "Finished building [%s]" "$1"
show_elapsed_time "${FUNCNAME}" "${timer_start}"
}

View file

@ -9,54 +9,21 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
load_compiler_settings(){
local tarch="$1" conf
conf=${make_conf_dir}/$tarch.conf
[[ -f $conf ]] || return 1
info "Loading compiler settings: %s" "$tarch"
source $conf
return 0
}
get_makepkg_conf(){
local conf="${tmp_dir}/makepkg-$1.conf"
cp "${DATADIR}/makepkg.conf" "$conf"
load_compiler_settings "$1"
sed -i "$conf" \
-e "s|@CARCH[@]|$carch|g" \
-e "s|@CHOST[@]|$chost|g" \
-e "s|@CFLAGS[@]|$cflags|g"
echo "$conf"
}
# $1: target_arch
prepare_conf(){
if ! is_valid_arch_pkg "$1";then
die "%s is not a valid arch!" "$1"
# $1: sofile
# $2: soarch
process_sofile() {
# extract the library name: libfoo.so
local soname="${1%.so?(+(.+([0-9])))}".so
# extract the major version: 1
soversion="${1##*\.so\.}"
if [[ "$soversion" = "$1" ]] && (($IGNORE_INTERNAL)); then
continue
fi
local pac_arch='default'
if [[ "$1" == 'multilib' ]];then
pac_arch='multilib'
is_multilib=true
if ! in_array "${soname}=${soversion}-$2" ${soobjects[@]}; then
# libfoo.so=1-64
msg "${soname}=${soversion}-$2"
soobjects+=("${soname}=${soversion}-$2")
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'
}
pkgver_equal() {
@ -144,168 +111,3 @@ find_cached_package() {
;;
esac
}
check_build(){
find_pkg $1
[[ ! -f $1/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"
}
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
info "Loading custom group: %s" "$file"
if ${is_multilib}; then
_multi="s|>multilib||g"
else
_multi="s|>multilib.*||g"
fi
devel_group=$(sed "$_com_rm" "$file" \
| sed "$_space" \
| sed "$_multi" \
| sed "$_clean")
echo ${devel_group}
}
init_base_devel(){
if ${udev_root};then
base_packages=( "$(load_group)" )
else
if ${is_multilib};then
base_packages=('base-devel' 'multilib-devel')
else
base_packages=('base-devel')
fi
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 copy in "${work_dir}"/*; do
[[ -d ${copy} ]] || continue
msg2 "Deleting chroot copy %s ..." "$(basename "${copy}")"
lock 9 "${copy}.lock" "Locking chroot copy '${copy}'"
subvolume_delete_recursive "${copy}"
rm -rf --one-file-system "${copy}"
done
exec 9>&-
rm -rf --one-file-system "${work_dir}"
}
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 ..."
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(){
su ${OWNER} -c "signfile ${pkg_dir}/$1"
}
move_to_cache(){
local src="$1"
[[ -n $PKGDEST ]] && src="$PKGDEST/$1"
[[ ! -f $src ]] && die
msg2 "Moving [%s] -> [%s]" "${src##*/}" "${pkg_dir}"
mv $src ${pkg_dir}/
${sign} && sign_pkg "${src##*/}"
[[ -n $PKGDEST ]] && rm "$1"
user_own "${pkg_dir}" "-R"
}
archive_logs(){
local archive name="$1" ext=log.tar.xz ver src=${tmp_dir}/archives.list target='.'
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
else
find $target -maxdepth 1 -name "$archive*.log" > $src
fi
msg2 "Archiving log files [%s] ..." "$archive.$ext"
tar -cJf ${log_dir}/$archive.$ext -C "$target" -T $src
msg2 "Cleaning log files ..."
find $target -maxdepth 1 -name "$archive*.log" -delete
}
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)
if ${clean_first} || [[ ! -d "${work_dir}" ]]; then
chroot_clean
chroot_create
else
chroot_update
fi
show_elapsed_time "${FUNCNAME}" "${timer}"
}
build_pkg(){
setarch "${target_arch}" \
mkchrootpkg ${mkchrootpkg_args[*]}
post_build
}
make_pkg(){
check_build "$1"
msg "Start building [%s]" "$1"
cd $1
build_pkg
cd ..
msg "Finished building [%s]" "$1"
show_elapsed_time "${FUNCNAME}" "${timer_start}"
}