From 812fcff8b7c95954a9e81044c3d44288ed639dc5 Mon Sep 17 00:00:00 2001 From: langfingaz Date: Tue, 27 Apr 2021 11:41:35 +0200 Subject: [PATCH] fix shell globbing in case of no matching files --- pkg/de-p1st-repo/PKGBUILD | 4 ++-- pkg/de-p1st-repo/arch-repo-push-new.sh | 22 ++++++++++++++++++++-- pkg/de-p1st-repo/iterate-files-test.sh | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 pkg/de-p1st-repo/iterate-files-test.sh diff --git a/pkg/de-p1st-repo/PKGBUILD b/pkg/de-p1st-repo/PKGBUILD index 70b839a..2b86dd2 100644 --- a/pkg/de-p1st-repo/PKGBUILD +++ b/pkg/de-p1st-repo/PKGBUILD @@ -2,8 +2,8 @@ _pkgname=repo _reponame=arch pkgname="de-p1st-$_pkgname" -pkgver=0.1.4 -pkgrel=2 +pkgver=0.1.5 +pkgrel=1 pkgdesc="Bash script to manage remote Arch Linux repository" arch=('any') url="https://codeberg.org/privacy1st/${_reponame}" diff --git a/pkg/de-p1st-repo/arch-repo-push-new.sh b/pkg/de-p1st-repo/arch-repo-push-new.sh index df7b7ed..1a1b5fc 100644 --- a/pkg/de-p1st-repo/arch-repo-push-new.sh +++ b/pkg/de-p1st-repo/arch-repo-push-new.sh @@ -6,11 +6,29 @@ source /etc/de-p1st-repo/arch-repo.cfg || exit cd "${LOCAL_PKG_DIR}" || exit -# get list of new packages, one package per line +# check if at least one matching file exists +match="0" +for PKG in ./*.pkg.tar.{xz,zst}; do + [ -f "$PKG" ] || { echo "No match for pattern $PKG"; continue; } + + # if we are here, then there is at least one match! + match="1" + break +done + +if [ "$match" = "0" ]; then + echo "There are no local packages" + exit 0 +fi + + +# Get list of new packages, one package per line. +# Enable nullglob for the case that e.g. just *.zst but not *.xz packages exist. +shopt -s nullglob rsync --ignore-existing --out-format="%n" --dry-run \ ./*.pkg.tar.{xz,zst} "${REMOTE_SSH_HOST}":"${REMOTE_PKG_DIR}" > new-pkg.txt || exit -# if there are no new packages, exit +# if there are no new packages to push/synchronize, then exit if [ ! -s new-pkg.txt ]; then echo "No new packages."; exit 0; diff --git a/pkg/de-p1st-repo/iterate-files-test.sh b/pkg/de-p1st-repo/iterate-files-test.sh new file mode 100644 index 0000000..a67c129 --- /dev/null +++ b/pkg/de-p1st-repo/iterate-files-test.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +source /etc/de-p1st-repo/arch-repo.cfg || exit + + +cd "${LOCAL_PKG_DIR}" || exit + +match="0" +for PKG in ./*.pkg.tar.{xz,zst}; do + [ -f "$PKG" ] || { echo "No match for pattern $PKG"; continue; } + + # if we are here, there is at least one match! + match="1" + break +done + +if [ "$match" = "1" ]; then + shopt -s nullglob + # print all matching + echo ./*.pkg.tar.{xz,zst} +fi