Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement debug package handling #78

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions commitpkg.in
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,14 @@ for _arch in "${arch[@]}"; do
fullver=$(get_full_version "$_pkgname")

if pkgfile=$(find_cached_package "$_pkgname" "$fullver" "$_arch"); then
if grep -q "packager = Unknown Packager" <(bsdtar -xOqf "$pkgfile" .PKGINFO); then
die "PACKAGER was not set when building package"
fi
hashsum=sha256sum
pkgbuild_hash=$(awk -v"hashsum=$hashsum" -F' = ' '$1 == "pkgbuild_"hashsum {print $2}' <(bsdtar -xOqf "$pkgfile" .BUILDINFO))
if [[ "$pkgbuild_hash" != "$($hashsum PKGBUILD|cut -d' ' -f1)" ]]; then
die "PKGBUILD $hashsum mismatch: expected $pkgbuild_hash"
fi
check_package_validity "$pkgfile"
fi
done

fullver=$(get_full_version "$pkgbase")
if pkgfile=$(find_cached_package "$pkgbase-debug" "$fullver" "$_arch"); then
check_package_validity "$pkgfile"
fi
done

if [[ -z $server ]]; then
Expand Down Expand Up @@ -146,27 +144,37 @@ for _arch in "${arch[@]}"; do

for _pkgname in "${pkgname[@]}"; do
fullver=$(get_full_version "$_pkgname")

if ! pkgfile=$(find_cached_package "$_pkgname" "$fullver" "${_arch}"); then
warning "Skipping %s: failed to locate package file" "$_pkgname-$fullver-$_arch"
skip_arches+=("$_arch")
continue 2
fi
uploads+=("$pkgfile")
done

sigfile="${pkgfile}.sig"
if [[ ! -f $sigfile ]]; then
msg "Signing package %s..." "${pkgfile}"
if [[ -n $GPGKEY ]]; then
SIGNWITHKEY=(-u "${GPGKEY}")
fi
gpg --detach-sign --use-agent --no-armor "${SIGNWITHKEY[@]}" "${pkgfile}" || die
fi
if ! gpg --verify "$sigfile" "$pkgfile" >/dev/null 2>&1; then
die "Signature %s is incorrect!" "$sigfile"
fullver=$(get_full_version "$pkgbase")
if ! pkgfile=$(find_cached_package "$pkgbase-debug" "$fullver" "$_arch"); then
continue
fi
if ! is_debug_package "$pkgfile"; then
continue
fi
uploads+=("$pkgfile")
done

for pkgfile in "${uploads[@]}"; do
sigfile="${pkgfile}.sig"
if [[ ! -f $sigfile ]]; then
msg "Signing package %s..." "${pkgfile}"
if [[ -n $GPGKEY ]]; then
SIGNWITHKEY=(-u "${GPGKEY}")
fi
uploads+=("$sigfile")
done
gpg --detach-sign --use-agent --no-armor "${SIGNWITHKEY[@]}" "${pkgfile}" || die
fi
if ! gpg --verify "$sigfile" "$pkgfile" >/dev/null 2>&1; then
die "Signature %s is incorrect!" "$sigfile"
fi
uploads+=("$sigfile")
done

for _arch in "${arch[@]}"; do
Expand Down
70 changes: 70 additions & 0 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,73 @@ find_cached_package() {
return 1
esac
}


check_package_validity(){
local pkgfile=$1
if grep -q "packager = Unknown Packager" <(bsdtar -xOqf "$pkgfile" .PKGINFO); then
die "PACKAGER was not set when building package"
fi
hashsum=sha256sum
pkgbuild_hash=$(awk -v"hashsum=$hashsum" -F' = ' '$1 == "pkgbuild_"hashsum {print $2}' <(bsdtar -xOqf "$pkgfile" .BUILDINFO))
if [[ "$pkgbuild_hash" != "$($hashsum PKGBUILD|cut -d' ' -f1)" ]]; then
die "PKGBUILD $hashsum mismatch: expected $pkgbuild_hash"
fi
}


# usage: _grep_pkginfo pkgfile pattern
_grep_pkginfo() {
local _ret=()
mapfile -t _ret < <(bsdtar -xOqf "$1" ".PKGINFO" | grep "^${2} = ")
printf '%s\n' "${_ret[@]#${2} = }"
}


# Get the package name
getpkgname() {
local _name

_name="$(_grep_pkginfo "$1" "pkgname")"
if [[ -z $_name ]]; then
error "Package '%s' has no pkgname in the PKGINFO. Fail!" "$1"
exit 1
fi

echo "$_name"
}


# Get the package base or name as fallback
getpkgbase() {
local _base

_base="$(_grep_pkginfo "$1" "pkgbase")"
if [[ -z $_base ]]; then
getpkgname "$1"
else
echo "$_base"
fi
}


getpkgdesc() {
local _desc

_desc="$(_grep_pkginfo "$1" "pkgdesc")"
if [[ -z $_desc ]]; then
error "Package '%s' has no pkgdesc in the PKGINFO. Fail!" "$1"
exit 1
fi

echo "$_desc"
}


is_debug_package() {
local pkgfile=${1} pkgbase pkgname pkgdesc
pkgbase="$(getpkgbase "${pkgfile}")"
pkgname="$(getpkgname "${pkgfile}")"
pkgdesc="$(getpkgdesc "${pkgfile}")"
[[ ${pkgdesc} == "Detached debugging symbols for "* && ${pkgbase}-debug = "${pkgname}" ]]
}