#!/bin/bash set -euo pipefail BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") source "$BUILD_ROOT/helpers/message-helpers.sh" source "$BUILD_ROOT/helpers/paths.sh" PACKAGE="" SOURCE="aur" SYNC="true" RELEASE_RING="" AUR_PACKAGE="" FORCE=false SCAFFOLD=false usage() { cat < [OPTIONS] Create pkgbuilds/ with Omarchy metadata. AUR packages are synced immediately after metadata is written. Options: --source Package source (default: aur) --local Shortcut for --source local --aur AUR package name when different from local directory --no-sync For AUR packages, mark sync disabled after initial setup --fast Put package in the fast release ring --release-ring Release ring (currently: fast) --scaffold For local packages, create a starter PKGBUILD --force Overwrite existing .omarchy/package.json -h, --help Show this help message Examples: $0 yay $0 spotify --fast $0 signal-desktop --no-sync $0 omarchy-zsh --local --scaffold EOF } while [[ $# -gt 0 ]]; do case "$1" in --source) SOURCE="$2" shift 2 ;; --local) SOURCE="local" shift ;; --aur) AUR_PACKAGE="$2" shift 2 ;; --no-sync) SYNC="false" shift ;; --fast) RELEASE_RING="fast" shift ;; --release-ring) RELEASE_RING="$2" shift 2 ;; --scaffold) SCAFFOLD=true shift ;; --force) FORCE=true shift ;; -h|--help) usage exit 0 ;; --*) print_error "Unknown option: $1" exit 1 ;; *) if [[ -n "$PACKAGE" ]]; then print_error "Only one package can be added at a time" exit 1 fi PACKAGE="$1" shift ;; esac done if [[ -z "$PACKAGE" ]]; then print_error "Package name required" usage exit 1 fi case "$SOURCE" in aur|local) ;; *) print_error "Invalid source: $SOURCE (must be aur or local)"; exit 1 ;; esac case "$RELEASE_RING" in ""|fast) ;; *) print_error "Invalid release ring: $RELEASE_RING (currently only 'fast' is supported)"; exit 1 ;; esac PACKAGE_DIR="$PKGBUILDS_DIR/$PACKAGE" OMARCHY_DIR="$PACKAGE_DIR/.omarchy" METADATA_FILE="$OMARCHY_DIR/package.json" if [[ -f "$METADATA_FILE" && "$FORCE" != true ]]; then print_error "Package metadata already exists: $METADATA_FILE" print_info "Use --force to overwrite it" exit 1 fi print_header "Add Package" print_info "Package: $PACKAGE" print_info "Source: $SOURCE" [[ -n "$RELEASE_RING" ]] && print_info "Release ring: $RELEASE_RING" mkdir -p "$OMARCHY_DIR" jq_args=(--arg source "$SOURCE") jq_filter='{source: $source}' if [[ "$SOURCE" == "aur" && -n "$AUR_PACKAGE" && "$AUR_PACKAGE" != "$PACKAGE" ]]; then jq_args+=(--arg aur "$AUR_PACKAGE") jq_filter="$jq_filter + {aur: \$aur}" fi if [[ "$SOURCE" == "aur" && "$SYNC" == "false" ]]; then jq_filter="$jq_filter + {sync: false}" fi if [[ -n "$RELEASE_RING" ]]; then jq_args+=(--arg release_ring "$RELEASE_RING") jq_filter="$jq_filter + {release_ring: \$release_ring}" fi jq -n "${jq_args[@]}" "$jq_filter" > "$METADATA_FILE" print_success "Wrote $METADATA_FILE" if [[ "$SOURCE" == "aur" ]]; then if [[ "$SYNC" == "false" ]]; then # Temporarily sync once, then restore sync=false so future automated syncs skip it. tmpfile=$(mktemp) jq 'del(.sync)' "$METADATA_FILE" > "$tmpfile" mv "$tmpfile" "$METADATA_FILE" "$BUILD_ROOT/bin/sync-aur" "$PACKAGE" jq '. + {sync: false}' "$METADATA_FILE" > "$tmpfile" mv "$tmpfile" "$METADATA_FILE" print_info "AUR sync disabled for future runs" else "$BUILD_ROOT/bin/sync-aur" "$PACKAGE" fi else if [[ "$SCAFFOLD" == true && ! -f "$PACKAGE_DIR/PKGBUILD" ]]; then cat > "$PACKAGE_DIR/PKGBUILD" <