mirror of
https://codeberg.org/hyperreal/vauxite-build
synced 2024-11-25 12:23:42 +01:00
102 lines
3.4 KiB
Bash
Executable File
102 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
CLEAN_BUILD=""
|
|
SOURCE_BRANCH="f39"
|
|
SOURCE_URL="https://pagure.io/workstation-ostree-config"
|
|
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"
|
|
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*
|
|
|
|
if [ -n "${CLEAN_BUILD}" ]; then
|
|
log_struc_info "Clean build repo" directory "${BUILD_REPO}"
|
|
rm -rf "${BUILD_REPO}"
|
|
fi
|
|
|
|
# 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 "${BUILD_REPO}/objects" ]; then
|
|
log_info "Previous build repo not found. Initialize new build repo in archive mode"
|
|
if ! ostree --repo="${BUILD_REPO}" init --mode=archive; then
|
|
log_struc_error "Error initializing new build 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
|
|
|
|
# Deploy
|
|
log_struc_info "Deploy to web server" build_repo "${BUILD_REPO}" dest_repo "${DEST_REPO}"
|
|
if ! "$(pwd)/rsync-repos" --src "${BUILD_REPO}" --dest "${DEST_REPO}"; then
|
|
log_struc_error "Error deploying to web server" status "$?"
|
|
exit 1
|
|
fi
|