2021-04-22 11:06:27 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-05-24 15:09:45 +02:00
|
|
|
source /etc/de-p1st-repo/arch-repo.cfg || exit $?
|
2021-05-13 19:13:19 +02:00
|
|
|
# Enable nullglob for the case that not all patterns match, e.g. just *.zst but not *.xz packages exist.
|
|
|
|
shopt -s nullglob
|
2021-04-22 11:06:27 +02:00
|
|
|
|
2021-05-13 15:57:01 +02:00
|
|
|
function main() {
|
2021-05-13 17:57:53 +02:00
|
|
|
cd "${LOCAL_PKG_DIR}" || return $?
|
2021-04-22 11:06:27 +02:00
|
|
|
|
2021-05-13 19:13:19 +02:00
|
|
|
# Check if at least one matching file exists
|
2021-05-13 15:57:01 +02:00
|
|
|
match="0"
|
|
|
|
for PKG in ./*.pkg.tar.{xz,zst}; do
|
2021-05-13 19:13:19 +02:00
|
|
|
# There is at least one match!
|
2021-05-13 15:57:01 +02:00
|
|
|
match="1"
|
|
|
|
break
|
|
|
|
done
|
2021-04-22 11:06:27 +02:00
|
|
|
|
2021-05-13 15:57:01 +02:00
|
|
|
if [ "$match" = "0" ]; then
|
2021-05-13 18:01:25 +02:00
|
|
|
echo "There are no local packages inside ${LOCAL_PKG_DIR}"
|
2021-05-13 17:57:53 +02:00
|
|
|
return 0
|
2021-05-13 15:57:01 +02:00
|
|
|
fi
|
2021-04-27 11:41:35 +02:00
|
|
|
|
|
|
|
|
2021-05-13 15:57:01 +02:00
|
|
|
# Get list of new packages, one package per line.
|
|
|
|
rsync --ignore-existing --out-format="%n" --dry-run \
|
2021-05-13 17:57:53 +02:00
|
|
|
./*.pkg.tar.{xz,zst} "${REMOTE_SSH_HOST}":"${REMOTE_PKG_DIR}" > new-pkg.txt || return $?
|
2021-04-27 11:41:35 +02:00
|
|
|
|
2021-05-13 19:13:19 +02:00
|
|
|
# If there are no new packages to push/synchronize, then return
|
2021-05-13 15:57:01 +02:00
|
|
|
if [ ! -s new-pkg.txt ]; then
|
2021-05-13 18:01:25 +02:00
|
|
|
echo "No new packages inside ${LOCAL_PKG_DIR}";
|
2021-05-13 17:57:53 +02:00
|
|
|
return 0;
|
2021-05-13 15:57:01 +02:00
|
|
|
fi
|
2021-04-27 11:41:35 +02:00
|
|
|
|
2021-04-26 14:45:18 +02:00
|
|
|
|
2021-05-13 19:13:19 +02:00
|
|
|
# Transfer new packages using rsync
|
2021-05-13 15:57:01 +02:00
|
|
|
rsync --ignore-existing --progress --human-readable \
|
2021-05-13 17:57:53 +02:00
|
|
|
./*.pkg.tar.{xz,zst} "${REMOTE_SSH_HOST}":"${REMOTE_PKG_DIR}" || return $?
|
2021-04-26 15:16:40 +02:00
|
|
|
|
2021-05-13 19:13:19 +02:00
|
|
|
# Transfer new-pkg.txt
|
2021-05-13 15:57:01 +02:00
|
|
|
rsync --ignore-times --checksum --progress --human-readable \
|
2021-05-13 17:57:53 +02:00
|
|
|
new-pkg.txt "${REMOTE_SSH_HOST}":"${REMOTE_PKG_DIR}" || return $?
|
2021-04-26 14:45:18 +02:00
|
|
|
|
2021-04-22 11:06:27 +02:00
|
|
|
|
2021-05-13 19:13:19 +02:00
|
|
|
# Add each new package to database
|
2021-05-13 17:57:53 +02:00
|
|
|
ssh "${REMOTE_SSH_HOST}" "/usr/bin/arch-repo-receive-new" || return $?
|
2021-05-13 15:57:01 +02:00
|
|
|
}
|
2021-04-26 14:45:18 +02:00
|
|
|
|
|
|
|
|
2021-05-13 15:57:01 +02:00
|
|
|
for LOCAL_PKG_DIR in "${LOCAL_PKG_DIRS[@]}"; do
|
|
|
|
main
|
|
|
|
done
|