2023-10-21 14:37:23 +02:00
|
|
|
#! /bin/bash
|
|
|
|
# This script deploys packages built with 'makepkg' to an Arch Linux repository
|
|
|
|
# that lives on a remote host not necessarily running Arch.
|
|
|
|
# It works by syncing the remote database to a local place, editing (adding
|
|
|
|
# packages and signing the database).
|
|
|
|
# It is meant to run on an Arch Linux system, where the necessary tools
|
|
|
|
# (repo-add and some libraries) are present.
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Configurable variables
|
|
|
|
REPO_NAME=abstractnonsense
|
|
|
|
REMOTE_REPO_ROOT=arch.abstractnonsen.se:/var/www/arch.abstractnonsen.se/
|
|
|
|
TMP_REPO_ROOT=~/.cache/${REPO_NAME}
|
|
|
|
|
|
|
|
# Might be modified if you want other rsync options
|
|
|
|
RSYNC_OPTIONS=(--links --safe-links "--info=del,progress2,remove,symsafe")
|
|
|
|
|
|
|
|
# Should not be changed, these files need to be synced in order for repo-add to work properly
|
|
|
|
REPO_FILES=("${REPO_NAME}".db.tar.gz "${REPO_NAME}".db.tar.gz.sig "${REPO_NAME}".files.tar.gz "${REPO_NAME}".files.tar.gz.sig
|
2023-10-21 14:45:19 +02:00
|
|
|
"${REPO_NAME}".db "${REPO_NAME}".db.sig "${REPO_NAME}".files "${REPO_NAME}".files.sig)
|
2023-10-21 14:37:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Start script
|
2023-10-21 14:45:19 +02:00
|
|
|
mapfile -t packages < <(ls ./*pkg.tar.zst)
|
|
|
|
mapfile -t sigs < <(ls ./*pkg.tar.zst.sig)
|
2023-10-21 14:37:23 +02:00
|
|
|
|
|
|
|
mkdir -p $TMP_REPO_ROOT
|
|
|
|
|
|
|
|
echo "[deploy] Deploying the following $(echo "${packages[@]}" | wc -w) package(s):"
|
|
|
|
echo "${packages[*]}"
|
|
|
|
|
|
|
|
# get old state of repo
|
|
|
|
echo "[deploy] Syncing remote repo to locale cache"
|
|
|
|
|
|
|
|
remote_files=()
|
|
|
|
for f in "${REPO_FILES[@]}"; do
|
|
|
|
remote_files+=("${REMOTE_REPO_ROOT}/$f")
|
|
|
|
done
|
2023-10-21 14:45:19 +02:00
|
|
|
rsync --ignore-missing-args "${RSYNC_OPTIONS[@]}" "${remote_files[@]}" "${TMP_REPO_ROOT}"
|
2023-10-21 14:37:23 +02:00
|
|
|
|
|
|
|
# update repo locally
|
|
|
|
echo "[deploy] Updating repository locally"
|
|
|
|
cp "${packages[@]}" "${TMP_REPO_ROOT}"
|
|
|
|
cp "${sigs[@]}" "${TMP_REPO_ROOT}"
|
2023-10-21 14:45:19 +02:00
|
|
|
repo-add --new --remove --verify --sign "${TMP_REPO_ROOT}/${REPO_NAME}.db.tar.gz" "${packages[*]}"
|
2023-10-21 14:37:23 +02:00
|
|
|
|
|
|
|
# sync repo to remote
|
|
|
|
echo "[deploy] Syncing changes to remote"
|
|
|
|
local_files=()
|
|
|
|
for f in "${REPO_FILES[@]}" "${sigs[@]}" "${packages[@]}"; do
|
|
|
|
local_files+=("$TMP_REPO_ROOT/$f")
|
|
|
|
done
|
|
|
|
|
|
|
|
rsync "${RSYNC_OPTIONS[@]}" "${local_files[@]}" "${REMOTE_REPO_ROOT}"
|