It works
This commit is contained in:
parent
4a03e5cb43
commit
ffb65e26b5
75
apt-repo-updater.sh
Normal file
75
apt-repo-updater.sh
Normal file
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
WORK_DIR=${WORK_DIR:?"WORK_DIR is not set!!"}
|
||||
INCOME_DIR=${INCOME_DIR:="${WORK_DIR}/income"}
|
||||
CODENAME=(bookworm)
|
||||
|
||||
set -o functrace
|
||||
set -o nounset
|
||||
set -o errtrace
|
||||
set -o errexit
|
||||
|
||||
function msg {
|
||||
local mesg="$1"; shift
|
||||
printf "====> ${mesg}\n" "$@"
|
||||
}
|
||||
|
||||
function term_handle {
|
||||
if [[ -n "$inotify_pid" ]]
|
||||
then
|
||||
GO_ON=0
|
||||
msg "sending TERM to inotifywait..."
|
||||
kill -s TERM "$inotify_pid" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
function term_delay {
|
||||
GO_ON=0
|
||||
msg "building repo, will terminate later"
|
||||
}
|
||||
trap 'term_handle' TERM SIGINT INT
|
||||
|
||||
|
||||
function build_repo {
|
||||
trap 'term_delay' TERM SIGINT INT
|
||||
|
||||
for deb in "${INCOME_DIR}/"*
|
||||
do
|
||||
if [[ "$deb" = *"/*" ]]
|
||||
then
|
||||
msg "no file in $INCOME_DIR, skip this build"
|
||||
break
|
||||
fi
|
||||
|
||||
msg "start adding $deb"
|
||||
for codename in "${CODENAME[@]}"
|
||||
do
|
||||
msg "adding $deb into $codename"
|
||||
reprepro includedeb "$codename" "$deb"
|
||||
done
|
||||
msg "finished adding $deb"
|
||||
|
||||
msg "removing $deb from income dir $INCOME_DIR"
|
||||
rm $deb
|
||||
done
|
||||
|
||||
trap 'term_handle' TERM SIGINT INT
|
||||
}
|
||||
|
||||
cd "$WORK_DIR"
|
||||
|
||||
GO_ON=1 # flag of if continue the loop
|
||||
PROGRAM_NAME="$0"
|
||||
while [[ "$GO_ON" = "1" ]]
|
||||
do
|
||||
build_repo
|
||||
|
||||
msg "start watching $INCOME_DIR"
|
||||
inotifywait --quiet -e move -e modify -e create "$INCOME_DIR" &
|
||||
inotify_pid="$!"
|
||||
|
||||
# when inotifywait was killed, its return code is no-zero,
|
||||
# so when wait return inotifywait's return code, script will exit due to errexit
|
||||
wait || true
|
||||
done
|
||||
|
||||
msg "$PROGRAM_NAME shutdown"
|
Loading…
Reference in a new issue