Add repo_build.sh

This commit is contained in:
slonkazoid 2023-10-13 18:28:35 +03:00
parent 2a1ecd1aca
commit 12433c6974
2 changed files with 57 additions and 0 deletions

View file

@ -10,3 +10,4 @@ All code is licensed under GPL-3.0 unless specified otherwise.
| ---------------------- | ----------------------------------------------------- | --- |
| [unlink.c](c/unlink.c) | [arshit](shell/bash/arshit) | |
| [cecho.c](c/cecho.c) | [sshfs_mount_file.sh](shell/bash/sshfs_mount_file.sh) | |
| | [repo_build.sh](shell/bash/repo_build.sh) | |

56
shell/bash/repo_build.sh Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# repo_build.sh
# Script to create a signed Arch Linux repository
# Usage: ./repo_build.sh [dir] [path-to-db] [key-id]
cd "$(dirname "$0")"
TARGET="${1-arch}"
DB_FILE="${2-slonkrepo.db.tar.xz}"
KEY_ID="${3-9C51F3072F8D11A2}"
echo_stderr() {
echo $@ >&2
}
if [[ ! -d "${TARGET}" ]]; then
echo_stderr "Error: Not a directory: ${TARGET}"
exit 1
fi
for dir in "${TARGET}" "${TARGET}"/*; do
[[ ! -d "${dir}" ]] &&continue
echo_stderr "Processing '${dir}'"
cd "${dir}"
packages=()
for file in *.pkg*; do
[[ "${file}" == '*.pkg*' ]] && continue
[[ "${file}" =~ .*'.sig' ]] && continue
packages+=("${file}")
[[ -f "${file}.sig" ]] && continue
echo_stderr "Signing '${file}'"
if gpg -u "${KEY_ID}" --output "${file}.sig" --detach-sig "${file}"; then
echo_stderr "Signed '${file}'"
else
code=$?
echo_stderr "gpg failed with exit code ${code}."
exit $code
fi
done
if [[ "${#packages}" == 0 ]]; then
echo_stderr "No packages in '${dir}', ignoring"
cd - >/dev/null
continue
fi
if repo-add -n -s -k "${KEY_ID}" "${DB_FILE}" "${packages[@]}"; then
echo_stderr "Processed '${dir}'"
else
code=$?
echo_stderr "repo-add failed with exit code ${code}."
exit $code
fi
cd - >/dev/null
done
echo_stderr "All done"