diff --git a/apt-repo-updater b/apt-repo-updater index eae379f..7f63202 100755 --- a/apt-repo-updater +++ b/apt-repo-updater @@ -32,6 +32,7 @@ trap 'term_handle' TERM SIGINT INT function build_repo { trap 'term_delay' TERM SIGINT INT + local return_code=0 for deb in "${INCOME_DIR}/"* do if [[ "$deb" = *"/*" ]] @@ -44,7 +45,15 @@ function build_repo { for codename in "${CODENAME[@]}" do msg "adding $deb into $codename" - reprepro includedeb "$codename" "$deb" + reprepro includedeb "$codename" "$deb" && return_code=$? || return_code=$? + + if [[ "$return_code" -ne 0 ]] + then + msg "failed to add $deb into $codename" + msg "copy $deb to $FAILED_DIR/$codename" + mkdir -p "$FAILED_DIR/$codename" + cp "$deb" "$FAILED_DIR/$codename/" + fi done msg "finished adding $deb" @@ -67,9 +76,12 @@ do 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 + # When inotifywait was killed, its return code is no-zero, + # so when wait return inotifywait's return code, script will exit due to errexit. + # Use '||' to fix the above problem + # + # Break the loop when failed to watching (or killed) + wait $inotify_pid || GO_ON=0 done msg "$PROGRAM_NAME shutdown"