mirror of
https://codeberg.org/hyperreal/vauxite-build
synced 2024-11-25 12:23:42 +01:00
135 lines
4.8 KiB
Bash
Executable File
135 lines
4.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
SOURCE_BRANCH="f39"
|
|
SOURCE_URL="https://pagure.io/workstation-ostree-config"
|
|
OSTREE_BRANCH="vauxite/f39/x86_64/main"
|
|
DEST_REPO="/srv/repo"
|
|
OSTREE_FILES_DIR="$(pwd)/src"
|
|
CACHE_DIR="$(pwd)/.cache"
|
|
BUILD_REPO="$(pwd)/.build-repo"
|
|
SOURCE_REPO="$(pwd)/.source-repo"
|
|
TMP_WORK_DIR="$(pwd)/.tmp"
|
|
DEPLOY_REPO="$(pwd)/.deploy-repo"
|
|
TREEFILE="${TMP_WORK_DIR}/vauxite.json"
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
gum log --time datetime --level error "Please run build with sudo"
|
|
exit 1
|
|
fi
|
|
|
|
function log_struc_info() {
|
|
gum log --time datetime --structured --level info "$@"
|
|
}
|
|
|
|
function log_info() {
|
|
gum log --time datetime --level info "$@"
|
|
}
|
|
|
|
function log_struc_error() {
|
|
gum log --time datetime --structured --level error "$@"
|
|
}
|
|
|
|
# Clean working directory
|
|
log_struc_info "Clean cache directory" directory "${CACHE_DIR}"
|
|
rm -rf "${CACHE_DIR}"
|
|
|
|
log_struc_info "Clean source repo" directory "${SOURCE_REPO}"
|
|
rm -rf "${SOURCE_REPO}"
|
|
|
|
log_struc_info "Clean temporary working directory" directory "${TMP_WORK_DIR}"
|
|
rm -rf "${TMP_WORK_DIR}"
|
|
|
|
log_struc_info "Clean /tmp/rpmostree*" files /tmp/rpmostree*
|
|
rm -rf /tmp/rpmostree*
|
|
|
|
log_struc_info "Clean build repo" directory "${BUILD_REPO}"
|
|
rm -rf "${BUILD_REPO}"
|
|
|
|
# Prepare build env
|
|
log_struc_info "Ensure cache directory exists" directory "${CACHE_DIR}"
|
|
mkdir -p "${CACHE_DIR}"
|
|
|
|
log_struc_info "Ensure temporary working directory exists" directory "${TMP_WORK_DIR}"
|
|
mkdir -p "${TMP_WORK_DIR}"
|
|
|
|
if [ -d "${DEPLOY_REPO}" ] && [ -n "$(ls "${DEPLOY_REPO}")" ]; then
|
|
log_info "Deploy repo found. Initialize ostree repo in bare-user mode."
|
|
if ! ostree --repo="${BUILD_REPO}" init --mode=bare-user; then
|
|
log_struc_error "Error initializing ostree repo in bare-user mode" status "$?"
|
|
exit 1
|
|
fi
|
|
|
|
log_info "Pull existing deploy repo into local build repo"
|
|
if ! ostree --repo="${BUILD_REPO}" pull-local --depth=2 "${DEPLOY_REPO}" "${OSTREE_BRANCH}"; then
|
|
log_struc_error "Error pulling existing deploy repo into local build repo" status "$?"
|
|
exit 1
|
|
fi
|
|
else
|
|
log_info "Deploy repo not found. Initialize new deploy repo in archive mode."
|
|
if ! ostree --repo="${BUILD_REPO}" init --mode=archive; then
|
|
log_struc_error "Error initializing new deploy repo in archive mode" status "$?"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
log_struc_info "Clone source repo" url "${SOURCE_URL}" branch "${SOURCE_BRANCH}" directory "${SOURCE_REPO}"
|
|
if ! git clone -b "${SOURCE_BRANCH}" "${SOURCE_URL}" "${SOURCE_REPO}"; then
|
|
log_struc_error "Error cloning source repo" status "$?"
|
|
exit 1
|
|
fi
|
|
|
|
log_struc_info "Copy contents of source repo into temporary work directory" source_repo "${SOURCE_REPO}" directory "${TMP_WORK_DIR}"
|
|
rsync -aAX "${SOURCE_REPO}"/ "${TMP_WORK_DIR}"
|
|
|
|
log_struc_info "Remove upstream xfce-desktop-pkgs.yaml from temporary work directory" file xfce-desktop-pkgs.yaml directory "${TMP_WORK_DIR}"
|
|
rm -f "${TMP_WORK_DIR}"/xfce-desktop-pkgs.yaml
|
|
|
|
log_struc_info "Copy contents of ostree files directory into temporary work directory" source "${OSTREE_FILES_DIR}" dest "${TMP_WORK_DIR}"
|
|
rsync -aAX "${OSTREE_FILES_DIR}"/ "${TMP_WORK_DIR}"
|
|
|
|
# Compose ostree
|
|
METADATA_STR="$(date '+%Y-%m-%dT%H%M%S')"
|
|
log_struc_info "Compose ostree" cachedir "${CACHE_DIR}" repo "${BUILD_REPO}" metadata-string "${METADATA_STR}" treefile "${TREEFILE}"
|
|
if ! rpm-ostree compose tree --unified-core --cachedir="${CACHE_DIR}" --repo="${BUILD_REPO}" --add-metadata-string=Build="${METADATA_STR}" "${TREEFILE}"; then
|
|
log_struc_error "Error composing ostree" status "$?"
|
|
exit 1
|
|
fi
|
|
|
|
# Prepare deploy
|
|
log_info "Prune refs older than 30 days"
|
|
if ! ostree --repo="${BUILD_REPO}" prune --refs-only --keep-younger-than='30 days ago'; then
|
|
log_struc_error "Error pruning refs" status "$?"
|
|
exit 1
|
|
fi
|
|
|
|
log_struc_info "Pull new ostree commit into deploy repo" deploy_repo "${DEPLOY_REPO}"
|
|
if ! ostree --repo="${DEPLOY_REPO}" pull-local --depth=1 "${BUILD_REPO}" "${OSTREE_BRANCH}"; then
|
|
log_struc_error "Error pulling new ostree commit into deploy repo" status "$?"
|
|
exit 1
|
|
fi
|
|
|
|
log_struc_info "Remove local build repo" build_repo "${BUILD_REPO}"
|
|
rm -rf "${BUILD_REPO}"
|
|
|
|
log_struc_info "Check filesystem for errors" deploy_repo "${DEPLOY_REPO}" ostree_branch "${OSTREE_BRANCH}"
|
|
if ! ostree --repo="${DEPLOY_REPO}" fsck "${OSTREE_BRANCH}"; then
|
|
log_struc_error "Error checking filesystem for errors" status "$?"
|
|
exit 1
|
|
fi
|
|
|
|
# Update summary
|
|
log_struc_info "Update summary file" deploy_repo "${DEPLOY_REPO}"
|
|
if ! ostree --repo="${DEPLOY_REPO}" summary -u; then
|
|
log_struc_error "Error updating summary" status "$?"
|
|
exit 1
|
|
fi
|
|
|
|
# Deploy
|
|
log_struc_info "Deploy to web server" deploy_repo "${DEPLOY_REPO}" dest_repo "${DEST_REPO}"
|
|
if ! "$(pwd)/rsync-repos" --src "${DEPLOY_REPO}" --dest "${DEST_REPO}"; then
|
|
log_struc_error "Error deploying to web server" status "$?"
|
|
exit 1
|
|
fi
|