summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/abslibre-tools/librestage201
-rw-r--r--src/libretools.conf4
-rw-r--r--test/librestage-test.sh70
-rw-r--r--test/librestage.d/PKGBUILD-hello19
-rw-r--r--test/librestage.d/PKGBUILD-split42
5 files changed, 220 insertions, 116 deletions
diff --git a/src/abslibre-tools/librestage b/src/abslibre-tools/librestage
index 528a0be..52e761a 100755
--- a/src/abslibre-tools/librestage
+++ b/src/abslibre-tools/librestage
@@ -1,137 +1,114 @@
#!/bin/bash
# LibreStage
-# Prepares packages for upload into [staging]
-
-# Copyright 2010 Nicolás Reynolds
-
-# ---------- GNU General Public License 3 ----------
+# 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)
-load_files libretools
-check_vars libretools ARCHES WORKDIR || exit 1
-
-if [ -w / ]; then
- error "This script should be run as regular user"
- exit 1
-fi
-
-
-# End Config
+cmd=${0##*/}
usage() {
- cat <<EOU
-LibreStage Copyright (C) 2011 Nicolás Reynolds
-This program comes with ABSOLUTELY NO WARRANTY.
-This is free software, and you are welcome to redistribute it
-under the terms of the GNU General Public License version 3 or later.
-
-
-Usage: $(basename $0) <repo> [<repo2> ... ]
-
-LibreRelease will stage for upload the package(s) built by the PKGBUILD on
-the current directory to the specified repo(s).
-EOU
-}
-
-repos=$@
-
-while getopts 'h' arg; do
- case $arg in
- h) usage; exit 0 ;;
- esac
-done
-
-if [ ${#repos} -eq 0 ]; then
- usage
- exit 1;
-fi
-
-[[ ! -e ./PKGBUILD ]] && {
- error "PKGBUILD not found"
- exit 1
+ 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."
}
-# Source the needed files
-load_files makepkg
-source ./PKGBUILD
-[[ -e ./rePKGBUILD ]] && source ./rePKGBUILD
-
-# Default package location
-PKGDEST=${PKGDEST:-.}
-SRCPKGDEST=${SRCPKGDEST:-.}
-
-PKGEXT=".pkg.tar.?z"
-
-staged=false
-# Copies the packages to the specified repos inside staging
-for _arch in "${ARCHES[@]}"; do
- for pkg in "${pkgname[@]}"; do
-
- pkgpath=$(find ${PKGDEST}/ -type f \
- -name "${pkg}-$(get_full_version "${pkg}")-${_arch}${PKGEXT}")
-
- [[ -z ${pkgpath} ]] && continue
-
- pkgfile=$(basename ${pkgpath})
-
- # TODO refactor this
- if [ -e "${pkgpath}" ]; then
- msg "Found ${pkgfile}"
-
- canonical=""
- for _repo in ${repos[@]}; do
-
- if [ ! -d "${WORKDIR}/staging/${_repo}" ]; then
- warning "[${_repo}] didn't exist, creating..."
- mkdir -p "${WORKDIR}/staging/${_repo}"
- fi
-
- if [ -z "$canonical" ]; then
- canonical="${WORKDIR}/staging/${_repo}/${pkgfile}"
-
- cp "${pkgpath}" "${WORKDIR}/staging/${_repo}/" || {
- error "Can't put ${pkgfile} on [staging]"
- exit 1
- } && {
- msg2 "${pkg} staged on [${_repo}]"
- staged=true
- }
-
- else
- ln "${canonical}" "${WORKDIR}/staging/${_repo}/${pkgfile}" || {
- error "Can't put ${pkgfile} on [staging]"
- exit 1
- } && {
- msg2 "${pkg} staged on [${_repo}]"
- staged=true
- }
-
- fi
- done
+main() {
+ # 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[@]} == 0 ]]; then
+ usage >>/dev/stderr
+ return 1;
+ fi
+
+ if [[ -w / ]]; then
+ error "This script should be run as regular user"
+ return 1
+ fi
+
+ [[ ! -e ./PKGBUILD ]] && {
+ error "PKGBUILD not found"
+ return 1
+ }
+
+ # Load configuration
+
+ load_files libretools
+ check_vars libretools WORKDIR || return 1
+
+ load_files makepkg
+
+ # Load the PKGBUILD
+ source ./PKGBUILD
+ if [[ $arch == 'any' ]]; then
+ CARCH='any'
+ fi
+
+ # Now for the main routine.
+ staged=false
+ 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
- error "No package was staged"
- exit 1
-fi
+ if $staged ; then
+ return 0
+ else
+ error "No package was staged"
+ return 1
+ fi
+}
-exit 0
+main "$@"
diff --git a/src/libretools.conf b/src/libretools.conf
index 54b4323..947ee58 100644
--- a/src/libretools.conf
+++ b/src/libretools.conf
@@ -19,10 +19,6 @@ DIFFTOOL=`which vimdiff gvimdiff meld colordiff diff 2>/dev/null|sed 's/\s.*//;1
# precedence on the path cache (the last path added replaces the rest)
REPOS=('core' 'libre' 'extra' 'community' 'libre-testing' 'social' 'sugar' 'pcr' 'java')
-## The architectures
-## Used by `librestage`
-ARCHES=('i686' 'x86_64' 'mips64el' 'any')
-
################################################################################
# abslibre #
################################################################################
diff --git a/test/librestage-test.sh b/test/librestage-test.sh
new file mode 100644
index 0000000..83194b5
--- /dev/null
+++ b/test/librestage-test.sh
@@ -0,0 +1,70 @@
+#!/usr/bin/env roundup
+
+describe librestage
+
+
+before() {
+ tmpdir=$(mktemp -d --tmpdir test-librestage.XXXXXXXXXXXX)
+ stat=0
+
+ mkdir -p $XDG_CONFIG_HOME/libretools
+ echo "WORKDIR='$tmpdir/workdir'" >$XDG_CONFIG_HOME/libretools/libretools.conf
+
+ export HOME=$XDG_CONFIG_HOME
+ echo 'PKGEXT=.pkg.tar.gz' > $HOME/.makepkg.conf
+ echo "PKGDEST='$tmpdir/workdir/pkgdest'" >> $HOME/.makepkg.conf
+ mkdir -p "$tmpdir/workdir/pkgdest"
+}
+
+after() {
+ rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME"
+}
+
+it_displays_usage_text() {
+ librestage -h >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ "$(sed 1q "$tmpdir/stdout")" =~ Usage:.* ]]
+ [[ -z "$(cat "$tmpdir/stderr")" ]]
+}
+
+it_fails_with_0_args() {
+ librestage >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ [[ -z "$(cat "$tmpdir/stdout")" ]]
+ [[ -n "$(cat "$tmpdir/stderr")" ]]
+}
+
+it_fails_with_invalid_args() {
+ librestage -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ [[ -z "$(cat "$tmpdir/stdout")" ]]
+ [[ -n "$(cat "$tmpdir/stderr")" ]]
+}
+
+# This was an actual bug I hit with md/emacs-mdmua a long time ago; solution was
+# to use $(get_full_version)
+it_stages_split_packages_with_different_versions() {
+ cp librestage.d/PKGBUILD-split "$tmpdir/PKGBUILD"
+ cd "$tmpdir"
+
+ makepkg
+ librestage '~lukeshu'
+
+ # peak at the PKGBUILD to get this info
+ [[ -f $tmpdir/workdir/staging/~lukeshu/md-0.81-4-any.pkg.tar.gz ]]
+ [[ -f $tmpdir/workdir/staging/~lukeshu/emacs-mdmua-0.72-4-any.pkg.tar.gz ]]
+}
+
+it_stages_packages_to_multiple_repos() {
+ cp librestage.d/PKGBUILD-hello "$tmpdir/PKGBUILD"
+ cd "$tmpdir"
+
+ makepkg
+ librestage repo1 repo2 repo3
+
+ [[ -f $tmpdir/workdir/staging/repo1/libretools-hello-1.0-1-any.pkg.tar.gz ]]
+ [[ -f $tmpdir/workdir/staging/repo2/libretools-hello-1.0-1-any.pkg.tar.gz ]]
+ [[ -f $tmpdir/workdir/staging/repo3/libretools-hello-1.0-1-any.pkg.tar.gz ]]
+}
diff --git a/test/librestage.d/PKGBUILD-hello b/test/librestage.d/PKGBUILD-hello
new file mode 100644
index 0000000..706cb24
--- /dev/null
+++ b/test/librestage.d/PKGBUILD-hello
@@ -0,0 +1,19 @@
+pkgname='libretools-hello'
+pkgver=1.0
+license=('GPL')
+url='https://parabolagnulinux.org'
+
+pkgrel=1
+arch=(any)
+depends=(sh)
+
+build() {
+ cd "$srcdir"
+ echo '#!/bin/sh' > hello.sh
+ echo 'echo Hello, world!' >> hello.sh
+}
+
+package() {
+ cd "$srcdir"
+ install -Dm755 hello.sh "$pkgdir"/usr/bin/libretools-hello
+}
diff --git a/test/librestage.d/PKGBUILD-split b/test/librestage.d/PKGBUILD-split
new file mode 100644
index 0000000..a8ec1ef
--- /dev/null
+++ b/test/librestage.d/PKGBUILD-split
@@ -0,0 +1,42 @@
+# Maintainer: Luke Shumaker <lukeshu@sbcglobal.net>
+
+pkgname=("md" "emacs-mdmua")
+pkgver=0.81
+pkgrel=4
+arch=('any')
+url="https://github.com/nicferrier/$_pkgname"
+license=('GPL3')
+
+#makedepends=(python-distribute)
+
+#__gitbranch=1d69744 # This is the commit that is 0.81
+__gitbranch=455b6b4 # this is currently HEAD (has bugfixes)
+#source=("nicferrier-md-${__gitbranch}.tar.gz::https://github.com/nicferrier/$pkgname/tarball/${__gitbranch}")
+
+#build() {
+# cd "${srcdir}/nicferrier-md-${__gitbranch}"
+#
+# # fix typo
+# sed -i 's/pyprofyfs/pyproxyfs/' setup.py
+#}
+
+package_md() {
+ pkgdesc="A maildir client and library."
+ depends=('python' 'python-pyproxyfs')
+
+# cd "${srcdir}/nicferrier-md-${__gitbranch}"
+# python setup.py install --root="$pkgdir/" --optimize=1
+}
+
+package_emacs-mdmua() {
+ pkgdesc="An Emacs mail user agent (MUA) build around md."
+ pkgver='0.72'
+ depends=("md=0.81" 'emacs>=24')
+
+# cd "${srcdir}/nicferrier-md-${__gitbranch}"
+# cd useragents/emacs
+# install -d ${pkgdir}/usr/share/emacs/site-lisp
+# install -m 644 *.el ${pkgdir}/usr/share/emacs/site-lisp
+}
+
+#md5sums=('452727348df2f51d7eddade709aceb1c')