Compare commits

..

No commits in common. "8a9cb1e45c07008268084ba4d55e51bf6cfcdeee" and "79916bf5c54a05be3390da0d92582c30ad873334" have entirely different histories.

2 changed files with 21 additions and 111 deletions

View file

@ -1,42 +1,9 @@
# Apt Repo Updater
This script will monitor an income dir and execute `reprepro` to
include the new .deb files under the income dir.
This script will monitor a dir and execute `reprepro` to include the new .deb files.
# Usage
Create a directory as WORK_DIR, take `work` as example, and cd into it.
```bash
mkdir work
cd work
```
Create `conf/distributions` with content like the follow for `reprepro`
to use, see more at [here](https://manpages.debian.org/jessie/reprepro/reprepro.1.en.html)
```bash
mkdir conf
cat << EOF > conf/distributions
Codename: bookworm
Description: An example repository
Architectures: amd64
Components: main
EOF
WORK_DIR=/srv/apt apt-repo-updater
```
Start apt-repo-updater
```bash
/path/to/apt-repo-updater --work-dir .
```
Use another terminal to copy a .deb into the INCOME_DIR created
by apt-repo-updater, normally it will be named `income` under the WORK_DIR
```bash
cp /path/to/a/package.deb /path/to/WORK_DIR/income
```
Now the apt repository will include the .deb file just copyied.
And the .deb file will be deleted after included in the repository.

View file

@ -1,20 +1,18 @@
#!/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
shopt -s nullglob
function msg_base {
local prefix="$1" ; shift
function msg {
local mesg="$1"; shift
printf "${prefix} ${mesg}\n" "$@"
printf "====> ${mesg}\n" "$@"
}
function msg { msg_base "====>" "$@" ; }
function msg1 { msg_base "======>" "$@" ; }
function msg2 { msg_base "=========>" "$@" ; }
function msg3 { msg_base "===========>" "$@" ; }
function term_handle {
if [[ -n "$inotify_pid" ]]
@ -34,90 +32,38 @@ trap 'term_handle' TERM SIGINT INT
function build_repo {
trap 'term_delay' TERM SIGINT INT
local has_deb=0
local deb_name=""
msg1 "start build repository"
local return_code=0
for deb in "${INCOME_DIR}/"*.deb
for deb in "${INCOME_DIR}/"*
do
has_deb=1
deb_name="$(basename "$deb")"
if [[ "$deb" = *"/*" ]]
then
msg "no file in $INCOME_DIR, skip this build"
break
fi
msg2 "start adding $deb_name"
msg "start adding $deb"
for codename in "${CODENAME[@]}"
do
msg3 "adding $deb_name into $codename"
msg "adding $deb into $codename"
reprepro includedeb "$codename" "$deb" && return_code=$? || return_code=$?
if [[ "$return_code" -ne 0 ]]
then
msg3 "failed to add $deb_name into $codename"
msg3 "copy $deb_name to FAILED_DIR/$codename"
msg "failed to add $deb into $codename"
msg "copy $deb to $FAILED_DIR/$codename"
mkdir -p "$FAILED_DIR/$codename"
cp "$deb" "$FAILED_DIR/$codename/"
else
msg3 "added $deb_name into $codename"
fi
done
msg2 "finished adding $deb_name"
msg "finished adding $deb"
msg2 "removing $deb_name from INCOME_DIR"
msg "removing $deb from income dir $INCOME_DIR"
rm $deb
done
if [[ "$has_deb" == 0 ]]
then
msg1 "no .deb file in INCOME_DIR, skip this build"
fi
msg1 "finish build repository"
trap 'term_handle' TERM SIGINT INT
}
if [[ "$#" -eq 0 ]]
then
set -- "$@" --help
fi
CODENAME=()
while [[ "$#" -gt 0 ]]
do
case $1 in
--work-dir)
WORK_DIR="$2" ; shift ;;
--codename)
CODENAME+=("$2") ; shift ;;
--help)
echo "usage: $0 --work-dir <work_dir>"
echo " [--codename bookworm]..."
exit 0
;;
*)
shift ;;
esac
shift
done
WORK_DIR=${WORK_DIR:?"WORK_DIR is not set!!"}
INCOME_DIR=${INCOME_DIR:="income"}
FAILED_DIR=${FAILED_DIR:="${INCOME_DIR}/failed"}
if [[ -z "${CODENAME-}" ]]
then
CODENAME+=(bookworm)
fi
# log environements before actullay run
msg "WORK_DIR: $WORK_DIR"
msg "INCOME_DIR: $INCOME_DIR"
msg "FAILED_DIR: $FAILED_DIR"
msg "CODENAME: ${CODENAME[*]}"
msg "============================"
cd "$WORK_DIR"
GO_ON=1 # flag of if continue the loop
@ -126,8 +72,7 @@ while [[ "$GO_ON" = "1" ]]
do
build_repo
mkdir -p "$INCOME_DIR"
msg "start watching INCOME_DIR"
msg "start watching $INCOME_DIR"
inotifywait --quiet -e move -e modify -e create "$INCOME_DIR" &
inotify_pid="$!"
@ -137,8 +82,6 @@ do
#
# Break the loop when failed to watching (or killed)
wait $inotify_pid || GO_ON=0
msg "found directory modify in INCOME_DIR"
done
msg "$PROGRAM_NAME shutdown"