diff options
Diffstat (limited to 'src/abslibre-tools')
-rwxr-xr-x | src/abslibre-tools/createworkdir | 54 | ||||
-rwxr-xr-x | src/abslibre-tools/diff-unfree | 22 | ||||
-rwxr-xr-x | src/abslibre-tools/libreaddiff | 18 | ||||
-rwxr-xr-x | src/abslibre-tools/librerelease | 215 | ||||
-rwxr-xr-x | src/abslibre-tools/librestage | 61 |
5 files changed, 218 insertions, 152 deletions
diff --git a/src/abslibre-tools/createworkdir b/src/abslibre-tools/createworkdir index 99214ab..27b285c 100755 --- a/src/abslibre-tools/createworkdir +++ b/src/abslibre-tools/createworkdir @@ -1,8 +1,10 @@ #!/usr/bin/env bash +set -euE # CreateWorkDir # Creates a dir structure for working with Parabola packages -# Copyright 2010 Nicolás Reynolds +# Copyright (C) 2010 Nicolás Reynolds +# Copyright (C) 2013 Luke Shumaker # ---------- GNU General Public License 3 ---------- @@ -24,41 +26,27 @@ . libremessages . $(librelib conf.sh) load_files libretools -check_vars libretools WORKDIR REPOS ABSLIBREGIT || exit 1 +check_vars libretools WORKDIR REPOS ABSLIBRERECV ABSLIBRESEND -[[ ! -d ${WORKDIR} ]] && { # Create the WORKDIR +trap 'error "Aborting..."' EXIT - msg "Creating WORKDIR on ${WORKDIR}" - mkdir -p ${WORKDIR} ||{ - error "Could not create ${WORKDIR}"; exit 1 - } +msg "Creating WORKDIR at %s..." "$WORKDIR" +mkdir -p "$WORKDIR" -} +msg "Creating staging directory in WORKDIR..." +mkdir -p "$WORKDIR/staging" -for _repo in "${REPOS[@]}"; do # Create the staging dirs +cmd=(gitget -f -p "$ABSLIBRESEND" checkout "$ABSLIBRERECV" "$WORKDIR/abslibre") +if ! "${cmd[@]}"; then + error "Could not clone ABSLibre" + plain "Try running this command:" + echo + printf '%q ' "${cmd[@]}" + echo + exit 1 +fi - [[ ! -d ${WORKDIR}/staging/${_repo} ]] && { - mkdir -p ${WORKDIR}/staging/${_repo} || { - error "Can't create ${WORKDIR}/staging/${_repo}" - exit 1 - } - } +msg "Finished, your packaging directory tree looks like this now:" +ls --color=always "${WORKDIR}"/* -done - -[[ ! -d ${WORKDIR}/abslibre/.git ]] && { - msg "Cloning into ABSLibre" - CMD="git clone ${ABSLIBREGIT} ${WORKDIR}/abslibre" - ${CMD} || { - error "Could not clone ABSLibre" - plain "Try running this command:" - echo - plain "${CMD}" - exit 1 - } -} - -msg "Finished, your packaging dir tree looks like this now:" -ls --color=always ${WORKDIR}/*/* - -exit 0 +trap -- EXIT diff --git a/src/abslibre-tools/diff-unfree b/src/abslibre-tools/diff-unfree index 07f2ca2..af5bbe5 100755 --- a/src/abslibre-tools/diff-unfree +++ b/src/abslibre-tools/diff-unfree @@ -1,7 +1,7 @@ #!/usr/bin/env bash # This script will help you diff a *-libre PKGBUILD against the unfree one # to check for updates. -# Copyright 2010 Nicolás Reynolds +# Copyright (C) 2010 Nicolás Reynolds # ---------- GNU General Public License 3 ---------- @@ -23,16 +23,14 @@ . libremessages . $(librelib conf.sh) load_files libretools -check_vars libretools DIFFTOOL || exit 1 - -cmd=${0##*/} +check_vars libretools DIFFPROG || exit 1 usage() { - echo "Usage: $cmd [community|packages] [unfree-package] [repo]" - echo "Usage: $cmd --help" - echo "Helps you diff build scripts from ABSLibre against (Unfree) ABS." - echo "" - echo "Package name and repo will we guessed if you don't specify them." + print "Usage: %s [community|packages] [unfree-package] [repo]" "${0##*/}" + print "Usage: %s --help" "${0##*/}" + prose "Helps you diff build scripts from ABSLibre against (Unfree) ABS." + echo + prose "Package name and repo will we guessed if you don't specify them." } main() { @@ -68,7 +66,7 @@ main() { pushd "${tmp_dir}" &>/dev/null - msg "Getting diff from $repo/$package..." + msg "Getting diff from %s..." "$repo/$package" svn checkout --depth=empty svn://svn.archlinux.org/$svnrepo &>/dev/null @@ -81,8 +79,8 @@ main() { msg "Diffing files" for _file in ${unfree_dir}/*; do - msg2 "$(basename "${_file}")" - ${DIFFTOOL} "$PWD/$(basename "${_file}")" "${_file}" + msg2 "%s" "$(basename "${_file}")" + ${DIFFPROG} "$PWD/$(basename "${_file}")" "${_file}" done } diff --git a/src/abslibre-tools/libreaddiff b/src/abslibre-tools/libreaddiff index 03d0ad0..ebd749d 100755 --- a/src/abslibre-tools/libreaddiff +++ b/src/abslibre-tools/libreaddiff @@ -23,10 +23,12 @@ check_vars libretools WORKDIR for arg in "$@" ; do case "$arg" in -h|--h|--he|--hel|--help|-\?) - echo 'Usage: libreaddiff repo [arch] - -This script outputs a diff of package names and versions in repo -between pacman'\''s sync db and abslibre checkout.' >&2 + { + print 'Usage: %s repo [arch]' "${0##*/}" + echo + prose "This script outputs a diff of package names and versions + in repo between pacman's sync db and abslibre checkout." + } >&2 exit 0 ;; esac @@ -72,14 +74,14 @@ except StopIteration: load_PKGBUILD "$f/PKGBUILD" || continue is_here=false for arc in ${arch[@]} ; do - if [ "$arc" = "any" -o "$arc" = "$CARCH" ] ; then + if [[ "$arc" == "any" ]] || [[ "$arc" == "$CARCH" ]] ; then is_here=true break fi done - if [ "$is_here" = "true" ] ; then - for name in ${pkgname[@]} ; do - if [ -z "$epoch" ] ; then + if [[ "$is_here" == "true" ]] ; then + for name in "${pkgname[@]}" ; do + if [[ -z "$epoch" ]] ; then echo $name-$pkgver-$pkgrel else echo $name-$epoch:$pkgver-$pkgrel diff --git a/src/abslibre-tools/librerelease b/src/abslibre-tools/librerelease index 5913670..8b1e05f 100755 --- a/src/abslibre-tools/librerelease +++ b/src/abslibre-tools/librerelease @@ -2,23 +2,23 @@ # Librerelease # Uploads packages into [staging] -# Copyright 2010 Nicolás Reynolds -# Copyright 2013 Luke Shumaker +# Copyright (C) 2010 Nicolás Reynolds +# Copyright (C) 2013-2014 Luke Shumaker # For just the create_signature() function: -# Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> -# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> -# Copyright (c) 2005 by Aurelien Foret <orelien@chez.com> -# Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org> -# Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu> -# Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk> -# Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org> -# Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> -# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> -# Copyright (c) 2005 by Aurelien Foret <orelien@chez.com> -# Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org> -# Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu> -# Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk> -# Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org> +# Copyright (C) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (C) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> +# Copyright (C) 2005 by Aurelien Foret <orelien@chez.com> +# Copyright (C) 2006 by Miklos Vajna <vmiklos@frugalware.org> +# Copyright (C) 2005 by Christian Hamar <krics@linuxforum.hu> +# Copyright (C) 2006 by Alex Smith <alex@alex-smith.me.uk> +# Copyright (C) 2006 by Andras Voroskoi <voroskoi@frugalware.org> +# Copyright (C) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (C) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> +# Copyright (C) 2005 by Aurelien Foret <orelien@chez.com> +# Copyright (C) 2006 by Miklos Vajna <vmiklos@frugalware.org> +# Copyright (C) 2005 by Christian Hamar <krics@linuxforum.hu> +# Copyright (C) 2006 by Alex Smith <alex@alex-smith.me.uk> +# Copyright (C) 2006 by Andras Voroskoi <voroskoi@frugalware.org> # # This file is part of Parabola. # @@ -38,25 +38,24 @@ . libremessages . $(librelib conf.sh) -function usage { - print "Usage: %s [OPTIONS]" "${0##*/}" - echo - print 'This script uploads packages on $WORKDIR/stagging' - print "to parabola server." - echo - print "Options:" - print ' -c Clean packages on $WORKDIR/staging' - print " -l Only list packages but not upload them" - print " -n Dry-run; don't actually do anything" - print " -h Show this message" -} - -function list_packages { - find "$WORKDIR/staging/" -mindepth 1 -type d -not -empty -printf '%f\n' | sort | - while read -r repo; do - msg2 "$repo" - find "${WORKDIR}/staging/${repo}" -type f -printf "%f\n" | sort - done +dryrun="" +upload_only=false +readonly rsync_flags=( + --no-group + --no-perms + --copy-links + --hard-links + --partial + --human-readable + --progress + -e ssh +) + +# Functions #################################################################### + +list0_files() { + find -L "${WORKDIR}/staging" -type f \ + -exec realpath -z --relative-to="${WORKDIR}/staging" {} + } # This function is taken almost verbatim from makepkg @@ -70,7 +69,7 @@ create_signature() { SIGNWITHKEY="-u ${GPGKEY}" fi # The signature will be generated directly in ascii-friendly format - gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$? + gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" || ret=$? if (( ! ret )); then @@ -81,67 +80,81 @@ create_signature() { fi } -function sign_packages { - if [ -z "${GPG_AGENT_INFO}" ]; then - warning "It's better to use gpg-agent to sign packages in batches" +sign_packages() { + if [[ -z "${GPG_AGENT_INFO}" ]]; then + warning "It's better to have \`%s\` running to sign packages in batches" 'gpg-agent --daemon' fi - for package in $(find "${WORKDIR}/staging/" -type f -iname '*.pkg.tar.?z'); do - if [ -f "${package}.sig" ]; then - msg2 "Package signature found, verifying..." + for file in $(find "${WORKDIR}/staging/" -type f -not -iname '*.sig'); do + if [[ -f "${file}.sig" ]]; then + msg2 "File signature found, verifying..." # Verify that the signature is correct, else remove for re-signing - if ! gpg --quiet --verify "${package}.sig" >/dev/null 2>&1; then + if ! gpg --quiet --verify "${file}.sig" >/dev/null 2>&1; then error "Failed! Re-signing..." - rm -f "${package}.sig" + rm -f "${file}.sig" fi fi - if ! [ -f "${package}.sig" ]; then - create_signature "$package" || return 2 + if ! [[ -f "${file}.sig" ]]; then + create_signature "$file" || return 2 fi done } -# Remove everything that's not a package or a signature -function clean_non_packages { - find $WORKDIR/staging/ -type f \ - \! -iname "*.pkg.tar.?z" -a \! -iname "*.pkg.tar.?z.sig" \ - -delete -} - # Clean everything if not on dry-run mode -function clean { +clean_files() { + local file_list=$1 + + local rmcmd=(rm -fv) if [[ -n "${dryrun}" ]]; then - : - else - msg "Removing files from local staging directory" - # use '-exec rm' instead of '-delete' to be verbose - find "${WORKDIR}/staging" -type f -exec rm -fv {} + + rmcmd=(printf "$(_ "removed '%s' (dry-run)")\n") fi + + msg "Removing files from local staging directory" + cd "${WORKDIR}/staging" && xargs -0r -a "$file_list" "${rmcmd[@]}" + cd "${WORKDIR}/staging" && find . -mindepth 1 -type d -empty \ + -exec rmdir -p {} + 2>/dev/null } -function main { - if [ -w / ]; then +################################################################################ + +usage() { + print "Usage: %s [OPTIONS]" "${0##*/}" + echo + prose 'This script uploads packages on $WORKDIR/stagging + to parabola server.' + echo + print "Options:" + flag '-c' 'Clean; delete packages in $WORKDIR/staging' + flag '-l' "List; list packages but not upload them" + flag '-u' "Upload-only; do not run db-update on the server" + + flag '-n' "Dry-run; don't actually do anything" + flag '-h' "Show this message" +} + +main() { + if [[ -w / ]]; then error "This program should be run as regular user" return 1 fi # Parse options - local dryrun="" local mode="release_packages" - while getopts 'clnh' arg; do + while getopts 'clunh' arg; do case $arg in c) mode=clean ;; - l) mode=list_packages ;; + l) mode=pretty_print_packages ;; + u) upload_only=true ;; n) dryrun="--dry-run" ;; h) mode=usage ;; - *) usage >/dev/stderr; return 1 ;; + *) usage >&2; return 1 ;; esac done shift $(($OPTIND - 1)) if [[ $# != 0 ]]; then - usage >/dev/stderr + usage >&2 return 1 fi @@ -154,41 +167,66 @@ function main { check_vars makepkg GPGKEY load_files libretools check_vars libretools WORKDIR REPODEST || return 1 - # The following variables are actually optional + REPODEST+='/staging/' + # The following settings are actually optional #check_vars libretools HOOKPRERELEASE HOOKPOSTRELEASE || return 1 - lock 10 "${WORKDIR}/staging.lock" 'Waiting for an exclusive lock on the staging directory' "$mode" } -function release_packages { +# The different modes (sans 'usage') ########################################### + +pretty_print_packages() { + find "$WORKDIR/staging/" -mindepth 1 -maxdepth 1 -type d -not -empty | sort | + while read -r path; do + msg2 "${path##*/}" + cd "$path" + find -L . -type f | sed 's|^\./| |' | sort + done +} + +clean() { + lock 10 "${WORKDIR}/staging.lock" \ + 'Waiting for an exclusive lock on the staging directory' + + local file_list="$(mktemp -t ${0##*/}.XXXXXXXXXX)" + trap "$(printf 'rm -f -- %q' "$file_list")" EXIT + list0_files > "$file_list" + + lock_close 10 + + clean_files "$file_list" +} + +release_packages() { if [[ -n $HOOKPRERELEASE ]]; then msg "Running HOOKPRERELEASE..." + plain '%s' "${HOOKPRERELEASE}" bash -c "${HOOKPRERELEASE}" fi - clean_non_packages + lock 10 "${WORKDIR}/staging.lock" \ + 'Waiting for an exclusive lock on the staging directory' + sign_packages || return 1 # Make the permissions of the packages 644 otherwise the user will get access # denied error when they try to download (rsync --no-perms doesn't seem to # work). - find ${WORKDIR}/staging -type f -exec chmod 644 {} \; - find ${WORKDIR}/staging -type d -exec chmod 755 {} \; + find ${WORKDIR}/staging -type f -exec chmod 644 {} + + find ${WORKDIR}/staging -type d -exec chmod 755 {} + + + local file_list="$(mktemp -t ${0##*/}.XXXXXXXXXX)" + trap "$(printf 'rm -f -- %q' "$file_list")" EXIT + list0_files > "$file_list" - msg "%s to upload" $(du -h -d 0 ${WORKDIR}/staging | tr "\t" " " | cut -d" " -f1) + lock_close 10 + + msg "%s to upload" "$(cd "${WORKDIR}/staging" && du -hc --files0-from="$file_list" | sed -n '$s/\t.*//p')" msg "Uploading packages..." - if ! rsync --recursive \ - ${dryrun} \ - --no-group \ - --no-perms \ - --copy-links \ - --hard-links \ - --partial \ - --prune-empty-dirs \ - --human-readable \ - --progress \ - -e "ssh " \ + xargs -0r -a "$file_list" dirname -z | ssh ${REPODEST%%:*} "$(printf 'mkdir -p -- %q && cd %q && xargs -0r mkdir -pv --' "${REPODEST#*:}" "${REPODEST#*:}")" + if ! rsync ${dryrun} "${rsync_flags[@]}" \ + -0 --files-from="$file_list" \ ${WORKDIR}/staging \ ${REPODEST}/ then @@ -196,13 +234,18 @@ function release_packages { return 1 fi - clean + clean_files "$file_list" + + if $upload_only; then + return 0 + fi msg "Running db-update on repos" - ssh ${REPODEST%%:*} dbscripts/db-update + ssh ${REPODEST%%:*} "$(printf 'STAGING=%q dbscripts/db-update' "${REPODEST#*:}")" if [[ -n $HOOKPOSTRELEASE ]]; then msg "Running HOOKPOSTRELEASE..." + plain '%s' "${HOOKPOSTRELEASE}" bash -c "${HOOKPOSTRELEASE}" fi diff --git a/src/abslibre-tools/librestage b/src/abslibre-tools/librestage index 57846fc..610de50 100755 --- a/src/abslibre-tools/librestage +++ b/src/abslibre-tools/librestage @@ -2,8 +2,8 @@ # LibreStage # Prepares packages for upload -# Copyright 2010-2011 Nicolás Reynolds -# Copyright 2013 Luke Shumaker +# Copyright (C) 2010-2011 Nicolás Reynolds +# Copyright (C) 2013-2014 Luke Shumaker # # This file is part of Parabola. # @@ -23,14 +23,13 @@ . libremessages . $(librelib conf.sh) -cmd=${0##*/} usage() { - print "Usage: %s REPO [REPO2 REPO3...]" "$cmd" + print "Usage: %s REPO [REPO2 REPO3...]" "${0##*/}" 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." + prose "The package(s) are staged for the named repositories. + It is in general a bad idea to stage a package on multiple + repositories, but it supported by this tool." } main() { @@ -43,12 +42,12 @@ main() { while getopts 'h' arg; do case $arg in h) usage; return 0;; - *) usage >/dev/stderr; return 1;; + *) usage >&2; return 1;; esac done repos=("$@") if [[ ${#repos[@]} -eq 0 ]]; then - usage >>/dev/stderr + usage >&2 return 1; fi @@ -60,14 +59,16 @@ main() { # Load configuration load_files libretools check_vars libretools WORKDIR ARCHES || return 1 - load_files makepkg # for PKGDEST, which is optional + load_files makepkg # for PKGDEST and SRCDEST, which are optional + load_files librefetch # for MIRRORS, 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' + 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} @@ -79,7 +80,7 @@ main() { pkgpath="$(readlink -f "$pkgpath")" fi - msg "Found ${pkgfile}" + msg 'Found package: %s' "${pkgfile}" canonical="" # is empty for the first iteration, set after that for repo in "${repos[@]}"; do @@ -101,10 +102,44 @@ main() { done done + for netfile in "${source[@]}"; do + for mirror in "${MIRRORS[@]}"; do + srcurl=${netfile#*::} + if [[ "$srcurl" == "$mirror"* ]]; then + if [[ $netfile = *::* ]]; then + srcname=${netfile%%::*} + else + srcname=${netfile##*/} + fi + + srcpath='' + for path in "./$srcname" "${SRCDEST:-.}/$srcname"; do + if [[ -f "$path" ]]; then + srcpath="$path" + break + fi + done + if [[ -n "$srcpath" ]]; then + msg "Found generated source file: %s" "$srcname" + dest="${WORKDIR}/staging/other/${srcurl##"$mirror"}" + mkdir -p -- "${dest%/*}" + if cp "$srcpath" "$dest"; then + msg2 "%s staged on [%s]" "$srcname" other + staged=true + else + error "Can't put %s on [%s]" "$srcname" other + return 1 + fi + fi + break + fi + done + done + if $staged ; then return 0 else - error "No package was staged" + error "Nothing was staged" return 1 fi } |