Blame SOURCES/shim-find-debuginfo.sh

a9dd6f
#!/bin/bash
a9dd6f
#
a9dd6f
# shim-find-debuginfo.sh
a9dd6f
# Copyright (C) 2017 Peter Jones <Peter Jones@random>
a9dd6f
#
a9dd6f
# Distributed under terms of the GPLv3 license.
a9dd6f
#
a9dd6f
set -e
a9dd6f
set -u
a9dd6f
a9dd6f
mainarch=$1 && shift
a9dd6f
if [ $# == 1 ]; then
a9dd6f
    altarch=$1 && shift
a9dd6f
fi
a9dd6f
if ! [ -v RPM_BUILD_ROOT ]; then
a9dd6f
    echo "RPM_BUILD_ROOT must be set" 1>&2
a9dd6f
    exit 1
a9dd6f
fi
a9dd6f
a9dd6f
findsource()
a9dd6f
{
a9dd6f
    (
a9dd6f
        cd "${RPM_BUILD_ROOT}"
a9dd6f
        find usr/src/debug/ -type d | sed -e "s,^,%dir /," | sort -u | tac
a9dd6f
        find usr/src/debug/ -type f | sed -e "s,^,/," | sort -u | tac
a9dd6f
    )
a9dd6f
}
a9dd6f
a9dd6f
finddebug()
a9dd6f
{
a9dd6f
    arch=$1 && shift
a9dd6f
    declare -a dirs=()
a9dd6f
    declare -a files=()
a9dd6f
    declare -a excludes=()
a9dd6f
    declare -a tmp=()
a9dd6f
a9dd6f
    pushd "${RPM_BUILD_ROOT}" >/dev/null 2>&1
a9dd6f
a9dd6f
    mapfile -t tmp < <(find usr/lib/debug/ -type f -iname "*.efi.debug")
a9dd6f
    for x in "${tmp[@]}" ; do
a9dd6f
        if ! [ -e "${x}" ]; then
a9dd6f
            break
a9dd6f
        fi
a9dd6f
        if [[ ${x} =~ ${arch}\.efi\.debug$ ]]; then
a9dd6f
            files[${#files[@]}]=${x}
a9dd6f
        else
a9dd6f
            excludes[${#excludes[@]}]=${x}
a9dd6f
        fi
a9dd6f
    done
a9dd6f
    for x in usr/lib/debug/.build-id/*/*.debug ; do
a9dd6f
        if ! [ -e "${x}" ]; then
a9dd6f
            break
a9dd6f
        fi
a9dd6f
        link=$(readlink "${x}")
a9dd6f
        if [[ ${link} =~ ${arch}\.efi\.debug$ ]]; then
a9dd6f
            files[${#files[@]}]=${x}
a9dd6f
            files[${#files[@]}]=${x%%.debug}
a9dd6f
        else
a9dd6f
            excludes[${#excludes[@]}]=${x}
a9dd6f
            excludes[${#excludes[@]}]=${x%%.debug}
a9dd6f
        fi
a9dd6f
    done
a9dd6f
    for x in "${files[@]}" ; do
a9dd6f
        declare name
a9dd6f
a9dd6f
        name=$(dirname "/${x}")
a9dd6f
        while [ "${name}" != "/" ]; do
a9dd6f
            case "${name}" in
a9dd6f
            "/usr/lib/debug"|"/usr/lib"|"/usr")
a9dd6f
                ;;
a9dd6f
            *)
a9dd6f
                dirs[${#dirs[@]}]=${name}
a9dd6f
                ;;
a9dd6f
            esac
a9dd6f
            name=$(dirname "${name}")
a9dd6f
        done
a9dd6f
    done
a9dd6f
a9dd6f
    popd >/dev/null 2>&1
a9dd6f
    for x in "${dirs[@]}" ; do
a9dd6f
        echo "%dir ${x}"
a9dd6f
    done | sort | uniq
a9dd6f
    for x in "${files[@]}" ; do
a9dd6f
        echo "/${x}"
a9dd6f
    done | sort | uniq
a9dd6f
    for x in "${excludes[@]}" ; do
a9dd6f
        echo "%exclude /${x}"
a9dd6f
    done
a9dd6f
}
a9dd6f
a9dd6f
findsource > "build-${mainarch}/debugsource.list"
a9dd6f
finddebug "${mainarch}" > "build-${mainarch}/debugfiles.list"
a9dd6f
if [ -v altarch ]; then
a9dd6f
    finddebug "${altarch}" > "build-${altarch}/debugfiles.list"
a9dd6f
fi