fix shell globbing in case of no matching files

This commit is contained in:
Daniel Langbein 2021-04-27 11:41:35 +02:00
parent 2856aee2ad
commit 812fcff8b7
3 changed files with 43 additions and 4 deletions

View File

@ -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}"

View File

@ -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;

View File

@ -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