summaryrefslogtreecommitdiff
path: root/src/abslibre-tools/librerelease
diff options
context:
space:
mode:
Diffstat (limited to 'src/abslibre-tools/librerelease')
-rwxr-xr-xsrc/abslibre-tools/librerelease136
1 files changed, 86 insertions, 50 deletions
diff --git a/src/abslibre-tools/librerelease b/src/abslibre-tools/librerelease
index 5913670..f0d59e3 100755
--- a/src/abslibre-tools/librerelease
+++ b/src/abslibre-tools/librerelease
@@ -38,25 +38,22 @@
. 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=""
+readonly rsync_flags=(
+ --no-group
+ --no-perms
+ --copy-links
+ --hard-links
+ --partial
+ --human-readable
+ --progress
+ -e ssh
+)
+
+# Functions ####################################################################
+
+list0_files() {
+ find "${WORKDIR}/staging" -L -type f -print0
}
# This function is taken almost verbatim from makepkg
@@ -81,7 +78,7 @@ create_signature() {
fi
}
-function sign_packages {
+sign_packages() {
if [ -z "${GPG_AGENT_INFO}" ]; then
warning "It's better to use gpg-agent to sign packages in batches"
fi
@@ -104,36 +101,52 @@ function sign_packages {
}
# Remove everything that's not a package or a signature
-function clean_non_packages {
+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"
+ xargs -0 -a "$file_list" "${rmcmd[@]}"
}
-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 packages on $WORKDIR/staging'
+ flag '-l' "Only list packages but not upload them"
+ 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
case $arg in
c) mode=clean ;;
- l) mode=list_packages ;;
+ l) mode=pretty_print_packages ;;
n) dryrun="--dry-run" ;;
h) mode=usage ;;
*) usage >/dev/stderr; return 1 ;;
@@ -154,41 +167,64 @@ 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 -type d -not -empty -printf '%f\n' | sort |
+ while read -r repo; do
+ msg2 "$repo"
+ find "${WORKDIR}/staging/${repo}" -L -type f -printf "%f\n" | 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..."
bash -c "${HOOKPRERELEASE}"
fi
+ lock 10 "${WORKDIR}/staging.lock" \
+ 'Waiting for an exclusive lock on the staging directory'
+
clean_non_packages
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"
+
+ lock_close 10
- msg "%s to upload" $(du -h -d 0 ${WORKDIR}/staging | tr "\t" " " | cut -d" " -f1)
+ msg "%s to upload" "$(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 " \
+ if ! rsync ${dryrun} "${rsync_flags[@]}" \
+ -0 --files-from="$file_list"
${WORKDIR}/staging \
${REPODEST}/
then
@@ -196,10 +232,10 @@ function release_packages {
return 1
fi
- clean
+ clean_files "$file_list"
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..."