Skip to content
commitpkg.in 4.53 KiB
Newer Older
m4_include(lib/common.sh)
getpkgfile() {
	if [[ ${#} -ne 1 ]]; then
		die 'ERROR: No canonical package found!'
	elif [ ! -f "${1}" ]; then
		die "ERROR: Package ${1} not found!"
# Source makepkg.conf; fail if it is not found
if [ -r '/etc/makepkg.conf' ]; then
	source '/etc/makepkg.conf'
	die '/etc/makepkg.conf not found!'
fi

# Source user-specific makepkg.conf overrides
if [ -r ~/.makepkg.conf ]; then
	. ~/.makepkg.conf
if [ ! -f PKGBUILD ]; then
	die 'No PKGBUILD file'
. PKGBUILD
pkgbase=${pkgbase:-$pkgname}
case "$cmd" in
	commitpkg)
		if [ $# -eq 0 ]; then
			die 'usage: commitpkg <reponame> [-l limit] [-a arch] [commit message]'
		fi
		repo="$1"
		shift
		;;
	*pkg)
		repo="${cmd%pkg}"
		;;
	*)
		die 'usage: commitpkg <reponame> [-l limit] [-a arch] [commit message]'
		;;
esac

case "$repo" in
	core|extra|testing|staging)
		server='gerolde.archlinux.org' ;;
	community*|multilib*)
		server='aur.archlinux.org' ;;
	*)
		server='gerolde.archlinux.org'
		msg "Non-standard repository $repo in use, defaulting to server $server" ;;
# check if all local source files are under version control
for s in "${source[@]}"; do
	if [[ $s != *://* ]] && ! svn status -v "$s" | grep -q '^[ AMRX~]'; then
		die "$s is not under version control"
# check if changelog and install files are under version control
		# 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"
	done < <(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD)
Pierre Schmitz's avatar
Pierre Schmitz committed
# see if any limit options were passed, we'll send them to rsync
rsyncopts=(-e ssh -p --chmod=ug=rw,o=r -c -h -L --progress --partial -y)
while getopts ':l:a:' flag; do
	case $flag in
		l) rsyncopts+=("--bwlimit=$2") ;;
		a) commit_arch=$2 ;;
		:) die "option requires an argument -- '$OPTARG'" ;;
		\?) die "invalid option -- '$OPTARG'" ;;
	esac
done
shift $(( OPTIND - 1 ))
Pierre Schmitz's avatar
Pierre Schmitz committed
if [ -n "$(svn status -q)" ]; then
	if [ -n "$1" ]; then
		stat_busy 'committing changes to trunk'
		svn commit -q -m "${msgtemplate}${1}" || die
		stat_done
		msgtemplate="upgpkg: $pkgbase $(get_full_version)"$'\n\n'
Pierre Schmitz's avatar
Pierre Schmitz committed
		msgfile="$(mktemp)"
		echo "$msgtemplate" > "$msgfile"
		if [ -n "$SVN_EDITOR" ]; then
			$SVN_EDITOR "$msgfile"
		elif [ -n "$VISUAL" ]; then
			$VISUAL "$msgfile"
		elif [ -n "$EDITOR" ]; then
			$EDITOR "$msgfile"
		else
			vi "$msgfile"
		fi
		[ -s "$msgfile" ] || die
		stat_busy 'committing changes to trunk'
		svn commit -q -F "$msgfile" || die
Pierre Schmitz's avatar
Pierre Schmitz committed
		unlink "$msgfile"
declare -a uploads

for _arch in ${arch[@]}; do
	if [ -n "$commit_arch" ] && [ "${_arch}" != "$commit_arch" ]; then
		warning "skipping ${_arch}"
	for _pkgname in ${pkgname[@]}; do
		fullver=$(get_full_version $_pkgname)
		pkgfile=$(getpkgfile "$_pkgname-$fullver-${_arch}".pkg.tar.?z 2>/dev/null)
		pkgdestfile=$(getpkgfile "$PKGDEST/$_pkgname-$fullver-${_arch}".pkg.tar.?z 2>/dev/null)
		if [ -f "$pkgfile" ]; then
			pkgfile="./$pkgfile"
		elif [ -f "$pkgdestfile" ]; then
			pkgfile="$pkgdestfile"
			warning "skipping ${_arch}"
			continue 2
		fi
		uploads+=("$pkgfile")
		sigfile="${pkgfile}.sig"
		if [[ $SIGNPKG == 'y' ]] && [ ! -f "${sigfile}" ]; then
			msg "Signing package ${pkgfile}..."
			if [[ -n $GPGKEY ]]; then
				SIGNWITHKEY="-u ${GPGKEY}"
			fi
			gpg --detach-sign --use-agent ${SIGNWITHKEY} "${pkgfile}" || die
		if [ -f "${sigfile}" ]; then
			if ! gpg --verify "$sigfile" >/dev/null 2>&1; then
				die "Signature ${pkgfile}.sig is incorrect!"
			uploads+=("$sigfile")
			die "Signature ${pkgfile}.sig was not found"
	done
if [[ -n $commit_arch ]]; then
	archrelease "$repo-$commit_arch" || die
	archrelease "${arch[@]/#/$repo-}" || die
if [[ ${#uploads[*]} -gt 0 ]]; then
	msg 'uploading all package and signature files'
	rsync "${rsyncopts[@]}" "${uploads[@]}" "$server:staging/$repo/" || die
if [ "${arch[*]}" == 'any' ]; then
	if [ -d ../repos/$repo-i686 -a -d ../repos/$repo-x86_64 ]; then
		pushd ../repos/ >/dev/null
		stat_busy "removing $repo-i686 and $repo-x86_64"
		svn rm $repo-i686
		svn rm $repo-x86_64
		svn commit -q -m "removed $repo-i686 and $repo-x86_64 for $pkgname"
		popd >/dev/null
	fi
else
	if [ -d ../repos/$repo-any ]; then
		pushd ../repos/ >/dev/null
		stat_busy "removing $repo-any"
		svn rm $repo-any
		svn commit -q -m "removed $repo-any for $pkgname"