diff options
Diffstat (limited to 'src/abslibre-tools/librestage')
-rwxr-xr-x | src/abslibre-tools/librestage | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/abslibre-tools/librestage b/src/abslibre-tools/librestage new file mode 100755 index 0000000..57846fc --- /dev/null +++ b/src/abslibre-tools/librestage @@ -0,0 +1,112 @@ +#!/usr/bin/env bash +# LibreStage +# Prepares packages for upload + +# Copyright 2010-2011 Nicolás Reynolds +# Copyright 2013 Luke Shumaker +# +# This file is part of Parabola. +# +# Parabola is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Parabola is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Parabola. If not, see <http://www.gnu.org/licenses/>. + +. libremessages +. $(librelib conf.sh) + +cmd=${0##*/} +usage() { + print "Usage: %s REPO [REPO2 REPO3...]" "$cmd" + print "Stages the package(s) build by ./PKGBUILD for upload." + echo + print "The package(s) are staged for the named repositories." + print "It is in general a bad idea to stage a package on multiple" + print "repositories, but it supported by this tool." +} + +main() { + if [[ -w / ]]; then + error "This program should be run as regular user" + return 1 + fi + + # Parse options, set up + while getopts 'h' arg; do + case $arg in + h) usage; return 0;; + *) usage >/dev/stderr; return 1;; + esac + done + repos=("$@") + if [[ ${#repos[@]} -eq 0 ]]; then + usage >>/dev/stderr + return 1; + fi + + [[ ! -e ./PKGBUILD ]] && { + error "PKGBUILD not found" + return 1 + } + + # Load configuration + load_files libretools + check_vars libretools WORKDIR ARCHES || return 1 + load_files makepkg # for PKGDEST, which is optional + + # Load the PKGBUILD + load_PKGBUILD + + # Now for the main routine. + staged=false + slock 10 "${WORKDIR}/staging.lock" 'Waiting for a shared lock on the staging directory' + for CARCH in "${ARCHES[@]}" any; do + for _pkgname in "${pkgname[@]}"; do + pkgfile=${_pkgname}-$(get_full_version $_pkgname)-${CARCH}${PKGEXT} + pkgpath="$(find . "${PKGDEST:-.}" -maxdepth 1 -type f -name "$pkgfile"|sed 1q)" + + if [[ ! -f "${pkgpath}" ]]; then + continue + else + pkgpath="$(readlink -f "$pkgpath")" + fi + + msg "Found ${pkgfile}" + + canonical="" # is empty for the first iteration, set after that + for repo in "${repos[@]}"; do + mkdir -p "${WORKDIR}/staging/${repo}" + if [[ -z $canonical ]]; then + canonical="${WORKDIR}/staging/${repo}/${pkgfile}" + cmd=(cp "$pkgpath" "$canonical") + else + cmd=(ln "$canonical" "${WORKDIR}/staging/${repo}/${pkgfile}") + fi + if "${cmd[@]}"; then + msg2 "%s staged on [%s]" "$_pkgname" "$repo" + staged=true + else + error "Can't put %s on [%s]" "$_pkgname" "$repo" + return 1 + fi + done + done + done + + if $staged ; then + return 0 + else + error "No package was staged" + return 1 + fi +} + +main "$@" |