Blame SOURCES/shim-find-debuginfo.sh

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