124 lines
5.4 KiB
Bash
Executable File
124 lines
5.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
BUILDER_ROOT=${BUILDER_ROOT:-/opt/rust-package-builder}
|
|
source "$BUILDER_ROOT/scripts/lib.sh"
|
|
|
|
: "${SHA:?SHA required}"
|
|
: "${SRC:?SRC required}"
|
|
: "${OUT:?OUT required}"
|
|
: "${VERSION:?VERSION required}"
|
|
: "${SOURCE_REVISION:?SOURCE_REVISION required}"
|
|
|
|
REPOSITORY="$DATA_DIR/repository"
|
|
BRANCH_RELEASE_ID="$(date -u '+%Y%m%dT%H%M%SZ')-${SHORT_SHA}-freebsd"
|
|
RELEASE_DIR="$REPOSITORY/releases/$BRANCH_RELEASE_ID"
|
|
PUBLISHED=0
|
|
cleanup_freebsd_release() {
|
|
if [[ "$PUBLISHED" != "1" && -d "$RELEASE_DIR" ]]; then
|
|
rm -rf "$RELEASE_DIR"
|
|
fi
|
|
}
|
|
trap cleanup_freebsd_release EXIT
|
|
|
|
FREEBSD_BINARY="$OUT/rust-proxy-freebsd"
|
|
if [[ ! -x "$FREEBSD_BINARY" ]]; then
|
|
# Reuse the same FreeBSD cross-build as OPNsense if it succeeded first.
|
|
"$BUILDER_ROOT/scripts/build-opnsense.sh" "$SRC" "$FREEBSD_BINARY" "$BINARY_NAME" "$WORK"
|
|
fi
|
|
|
|
FREEBSD_PACKAGE_REVISION=$SOURCE_REVISION
|
|
LAST_FREEBSD_PACKAGE_VERSION=""
|
|
if [[ -r "$DATA_DIR/state/last_freebsd_package_version" ]]; then
|
|
LAST_FREEBSD_PACKAGE_VERSION=$(cat "$DATA_DIR/state/last_freebsd_package_version")
|
|
elif [[ -r "$REPOSITORY/current/freebsd/BUILD-INFO.txt" ]]; then
|
|
LAST_FREEBSD_PACKAGE_VERSION=$(sed -n 's/^package_version=//p' "$REPOSITORY/current/freebsd/BUILD-INFO.txt" | head -n1)
|
|
fi
|
|
if [[ "$LAST_FREEBSD_PACKAGE_VERSION" == "${VERSION}_"* ]]; then
|
|
LAST_FREEBSD_REVISION=${LAST_FREEBSD_PACKAGE_VERSION#"${VERSION}_"}
|
|
if [[ "$LAST_FREEBSD_REVISION" =~ ^[0-9]+$ ]] && (( LAST_FREEBSD_REVISION >= FREEBSD_PACKAGE_REVISION )); then
|
|
FREEBSD_PACKAGE_REVISION=$((LAST_FREEBSD_REVISION + 1))
|
|
fi
|
|
fi
|
|
if (( FREEBSD_PACKAGE_REVISION == 0 )); then
|
|
FREEBSD_PACKAGE_REVISION=1
|
|
fi
|
|
FREEBSD_PACKAGE_VERSION="${VERSION}_${FREEBSD_PACKAGE_REVISION}"
|
|
FREEBSD_PACKAGE_FILE="$OUT/rustproxy-${FREEBSD_PACKAGE_VERSION}.pkg"
|
|
"$BUILDER_ROOT/scripts/package-freebsd.sh" \
|
|
"$SRC" "$FREEBSD_BINARY" "$FREEBSD_PACKAGE_FILE" "$FREEBSD_PACKAGE_VERSION"
|
|
|
|
mkdir -p "$RELEASE_DIR/apt" "$RELEASE_DIR/rpm/x86_64" "$RELEASE_DIR/opnsense" "$RELEASE_DIR/freebsd"
|
|
CURRENT_TARGET=""
|
|
if [[ -L "$REPOSITORY/current" ]]; then
|
|
CURRENT_LINK=$(readlink "$REPOSITORY/current")
|
|
CURRENT_TARGET="$REPOSITORY/$CURRENT_LINK"
|
|
fi
|
|
|
|
log 'staging native FreeBSD repository snapshot'
|
|
if [[ -n "$CURRENT_TARGET" ]]; then
|
|
for component in apt rpm opnsense freebsd; do
|
|
if [[ -d "$CURRENT_TARGET/$component" ]]; then
|
|
rsync -a --delete --link-dest="$CURRENT_TARGET/$component"/ "$CURRENT_TARGET/$component"/ "$RELEASE_DIR/$component"/
|
|
fi
|
|
done
|
|
for copied in repo-key.gpg index.html LINUX-BUILD-INFO.txt; do
|
|
if [[ -f "$CURRENT_TARGET/$copied" ]]; then
|
|
cp -a "$CURRENT_TARGET/$copied" "$RELEASE_DIR/$copied"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
FREEBSD_PACKAGE_DIR="$RELEASE_DIR/freebsd/$FREEBSD_ABI"
|
|
mkdir -p "$FREEBSD_PACKAGE_DIR"
|
|
cp -f "$FREEBSD_PACKAGE_FILE" "$FREEBSD_PACKAGE_DIR/"
|
|
"$BUILDER_ROOT/scripts/generate-opnsense-repo.py" "$RELEASE_DIR/freebsd" --retention "$FREEBSD_NATIVE_RETENTION" --repo-version 2
|
|
NATIVE_URL="${OPNSENSE_REPOSITORY_URL%/}/freebsd"
|
|
cat > "$RELEASE_DIR/freebsd/RustProxy-FreeBSD.conf" <<CONF
|
|
RustProxyNative: {
|
|
url: "${NATIVE_URL}",
|
|
enabled: yes,
|
|
mirror_type: "none",
|
|
signature_type: "none"
|
|
}
|
|
CONF
|
|
cp -f "$FREEBSD_PACKAGE_FILE" "$RELEASE_DIR/freebsd/rustproxy-latest.pkg"
|
|
(cd "$RELEASE_DIR/freebsd" && sha256sum "$FREEBSD_ABI/$(basename "$FREEBSD_PACKAGE_FILE")") > "$RELEASE_DIR/freebsd/SHA256"
|
|
cat > "$RELEASE_DIR/freebsd/BUILD-INFO.txt" <<INFO
|
|
app_version=$VERSION
|
|
built_at=$(date -u "+%Y-%m-%dT%H:%M:%SZ")
|
|
package_version=$FREEBSD_PACKAGE_VERSION
|
|
source_url=$SOURCE_REPO
|
|
source_ref=$SOURCE_BRANCH
|
|
source_commit=$SHA
|
|
build_reason=$BUILD_REASON
|
|
source_revision=$SOURCE_REVISION
|
|
packaging_revision=$FREEBSD_NATIVE_PACKAGING_REVISION
|
|
freebsd_release=$FREEBSD_RELEASE
|
|
freebsd_abi=$FREEBSD_ABI
|
|
freebsd_arch=$FREEBSD_ARCH
|
|
package=$FREEBSD_ABI/$(basename "$FREEBSD_PACKAGE_FILE")
|
|
INFO
|
|
"$BUILDER_ROOT/scripts/generate-freebsd-index.sh" "$RELEASE_DIR/freebsd/index.html"
|
|
|
|
[[ -s "$RELEASE_DIR/freebsd/index.html" ]]
|
|
[[ -s "$RELEASE_DIR/freebsd/meta.conf" ]]
|
|
[[ -s "$RELEASE_DIR/freebsd/packagesite.pkg" ]]
|
|
[[ -s "$RELEASE_DIR/freebsd/data.pkg" ]]
|
|
grep -Fqx "version: 2;" "$RELEASE_DIR/freebsd/meta.conf" || fatal "unexpected FreeBSD pkg repository format"
|
|
[[ -s "$RELEASE_DIR/freebsd/rustproxy-latest.pkg" ]]
|
|
bsdtar -tf "$RELEASE_DIR/freebsd/packagesite.pkg" | grep -Fx 'packagesite.yaml' >/dev/null || fatal 'invalid FreeBSD packagesite.pkg'
|
|
bsdtar -xOf "$FREEBSD_PACKAGE_DIR/$(basename "$FREEBSD_PACKAGE_FILE")" +COMPACT_MANIFEST >/dev/null || fatal 'invalid FreeBSD package manifest'
|
|
# Fail before switching the live repository if the public package is missing or empty.
|
|
[[ -s "$FREEBSD_PACKAGE_DIR/$(basename "$FREEBSD_PACKAGE_FILE")" ]] || fatal 'missing FreeBSD native package artifact'
|
|
|
|
log 'publishing native FreeBSD repository branch'
|
|
rm -f "$REPOSITORY/current.new"
|
|
ln -s "releases/$BRANCH_RELEASE_ID" "$REPOSITORY/current.new"
|
|
mv -Tf "$REPOSITORY/current.new" "$REPOSITORY/current"
|
|
PUBLISHED=1
|
|
printf '%s\n' "$SHA" | atomic_write "$DATA_DIR/state/last_freebsd_commit"
|
|
printf '%s\n' "$FREEBSD_PACKAGE_VERSION" | atomic_write "$DATA_DIR/state/last_freebsd_package_version"
|
|
printf '%s\n' "$BRANCH_RELEASE_ID" | atomic_write "$DATA_DIR/state/last_freebsd_release"
|
|
printf '%s\n' "$BRANCH_RELEASE_ID" | atomic_write "$DATA_DIR/state/last_release"
|
|
log "FreeBSD native publication completed: package=$FREEBSD_PACKAGE_VERSION commit=$SHA"
|