From cf49d82520d814bddec929dc4564e22994123cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 21 Oct 2023 14:37:23 +0200 Subject: [PATCH] initial commit: add deploy script --- deploy.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 deploy.sh diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..00d23a4 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,54 @@ +#! /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 + "${REPO_NAME}".db 0 "${REPO_NAME}".db.sig "${REPO_NAME}".files "${REPO_NAME}".files.sig) + + +# Start script +mapfile -t packages < <(ls ./*pkg.tar.zst$) +mapfile -t sigs < <(ls ./*pkg.tar.zst.sig$) + +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 +rsync "${RSYNC_OPTIONS[@]}" "${remote_files[@]}" "${TMP_REPO_ROOT}" + +# update repo locally +echo "[deploy] Updating repository locally" +cp "${packages[@]}" "${TMP_REPO_ROOT}" +cp "${sigs[@]}" "${TMP_REPO_ROOT}" +repo-add --new --remove --verify --sign ${TMP_REPO_ROOT}/mkessler-arch.db.tar.gz "${packages[*]}" + +# 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}"