#!/bin/sh QFILE="${HOME}"/createrepo.queue REPOS_ROOT="${HOME}"/repos createrepo_loop() { while sleep 30; do [ -f "${QFILE}" ] || continue mv "${QFILE}" "${QFILE}.work" sort -u "${QFILE}.work" > "${QFILE}.sorted" while read dir; do printf 'Generating repository metadata for %s\n' "${dir}" createrepo_c "${dir}" done < "${QFILE}.sorted" rm -f "${QFILE}.work" "${QFILE}.sorted" done } inotify_loop() { stdbuf -o 0 inotifywait \ --monitor \ --event close_write,move,delete \ --recursive \ "${REPOS_ROOT}" \ | stdbuf -o 0 grep -E '\.rpm$' \ | while read dir _ _; do flock "${QFILE}" sh -c 'echo "$1" >> "$2"' -- "${dir}" "${QFILE}" done } mkdir -p "${REPOS_ROOT}" createrepo_loop & inotify_loop & wait