diff --git a/README.md b/README.md index 9ce8eb4..e33224d 100644 --- a/README.md +++ b/README.md @@ -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) | | diff --git a/shell/bash/repo_build.sh b/shell/bash/repo_build.sh new file mode 100755 index 0000000..4460eee --- /dev/null +++ b/shell/bash/repo_build.sh @@ -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"