#!/bin/bash m4_include(lib/common.sh) getpkgfile() { case $# in 0) error 'No canonical package found!' return 1 ;; [!1]) error 'Failed to canonicalize package name -- multiple packages found:' msg2 '%s' "$@" return 1 ;; esac echo "$1" } # Source makepkg.conf; fail if it is not found if [[ -r '/etc/makepkg.conf' ]]; then source '/etc/makepkg.conf' else die '/etc/makepkg.conf not found!' fi # Source user-specific makepkg.conf overrides if [[ -r ~/.makepkg.conf ]]; then . ~/.makepkg.conf fi cmd=${0##*/} if [[ ! -f PKGBUILD ]]; then die 'No PKGBUILD file' fi . PKGBUILD pkgbase=${pkgbase:-$pkgname} case "$cmd" in commitpkg) if (( $# == 0 )); then die 'usage: commitpkg [-f] [-s server] [-l limit] [-a arch] [commit message]' fi repo="$1" shift ;; *pkg) repo="${cmd%pkg}" ;; *) die 'usage: commitpkg [-f] [-s server] [-l limit] [-a arch] [commit message]' ;; esac # check if all local source files are under version control # TODO: FIXME: check if files are in git #for s in "${source[@]}"; do #if [[ $s != *://* ]] && ! svn status -v "$s@" | grep -q '^[ AMRX~]'; then #die "$s is not under version control" #fi #done # check if changelog and install files are under version control # TODO: FIXME: check if files are in git #for i in 'changelog' 'install'; do #while read -r file; do ## evaluate any bash variables used #eval file=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "$file")\" #if ! svn status -v "${file}" | grep -q '^[ AMRX~]'; then #die "${file} is not under version control" #fi #done < <(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD) #done rsyncopts=(-e ssh -p --chmod=ug=rw,o=r -c -h -L --progress --partial -y) archreleaseopts=() while getopts ':l:a:s:f' flag; do case $flag in f) archreleaseopts+=('-f') ;; s) server=$OPTARG ;; l) rsyncopts+=("--bwlimit=$OPTARG") ;; a) commit_arch=$OPTARG ;; :) die "Option requires an argument -- '$OPTARG'" ;; \?) die "Invalid option -- '$OPTARG'" ;; esac done shift $(( OPTIND - 1 )) # check packages have the packager field set for _arch in ${arch[@]}; do if [[ -n $commit_arch && ${_arch} != "$commit_arch" ]]; then continue fi for _pkgname in ${pkgname[@]}; do fullver=$(get_full_version $_pkgname) if pkgfile=$(shopt -s nullglob; getpkgfile "${PKGDEST+$PKGDEST/}$_pkgname-$fullver-${_arch}".pkg.tar.?z); then if grep -q "packager = Unknown Packager" <(bsdtar -xOqf $pkgfile .PKGINFO); then die "PACKAGER was not set when building package" fi fi done done if [[ -z $server ]]; then case "$repo" in core|extra|testing|staging|kde-unstable|gnome-unstable) server='localhost' ;; community*|multilib*) server='localhost' ;; *) server='gerolde.archlinux.org' msg "Non-standard repository $repo in use, defaulting to server $server" ;; esac fi if [[ -n $(git status -s | grep -v "^?? ") ]]; then msgtemplate="upgpkg: $pkgbase $(get_full_version)"$'\n\n' if [[ -n $1 ]]; then stat_busy 'Committing changes' git commit -a -q -m "${msgtemplate}${1}" || die git tag "$(get_full_version)" || die stat_done else stat_busy 'Committing changes to trunk' echo "$msgtemplate" | git commit -a -q -e -F - || die git tag "$(get_full_version)" || die stat_done fi fi declare -a uploads declare -a commit_arches declare -a skip_arches for _arch in ${arch[@]}; do if [[ -n $commit_arch && ${_arch} != "$commit_arch" ]]; then skip_arches+=($_arch) continue fi for _pkgname in ${pkgname[@]}; do fullver=$(get_full_version $_pkgname) if ! pkgfile=$(shopt -s nullglob; getpkgfile "${PKGDEST+$PKGDEST/}$_pkgname-$fullver-${_arch}".pkg.tar.?z); then warning "Skipping $_pkgname-$fullver-$_arch: failed to locate package file" skip_arches+=($_arch) continue 2 fi uploads+=("$pkgfile") sigfile="${pkgfile}.sig" if [[ ! -f $sigfile ]]; then msg "Signing package ${pkgfile}..." if [[ -n $GPGKEY ]]; then SIGNWITHKEY="-u ${GPGKEY}" fi gpg --detach-sign --use-agent ${SIGNWITHKEY} "${pkgfile}" || die fi if ! gpg --verify "$sigfile" >/dev/null 2>&1; then die "Signature ${pkgfile}.sig is incorrect!" fi uploads+=("$sigfile") done done for _arch in ${arch[@]}; do if ! in_array $_arch ${skip_arches[@]}; then commit_arches+=($_arch) fi done #if [[ ${#commit_arches[*]} -gt 0 ]]; then #archrelease "${archreleaseopts[@]}" "${commit_arches[@]/#/$repo-}" || die #fi if [[ ${#uploads[*]} -gt 0 ]]; then new_uploads=() # convert to absolute paths so rsync can work with colons (epoch) while read -r -d '' upload; do new_uploads+=("$upload") done < <(realpath -z "${uploads[@]}") uploads=("${new_uploads[@]}") unset new_uploads msg 'Uploading all package and signature files' rsync "${rsyncopts[@]}" "${uploads[@]}" "$server:arch/git-pkgs-test/staging/$repo/" || die fi