This repository has been archived on 2026-10-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
omarchy-pkgs/bin/add-package
T
2026-05-08 01:04:52 -04:00

181 lines
4.1 KiB
Bash
Executable File

#!/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 <<EOF
Usage: $0 <package> [OPTIONS]
Create pkgbuilds/<package> with Omarchy metadata. AUR packages are synced
immediately after metadata is written.
Options:
--source <aur|local> Package source (default: aur)
--local Shortcut for --source local
--aur <name> 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 <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" <<EOF
pkgname=$PACKAGE
pkgver=0.1.0
pkgrel=1
pkgdesc=""
arch=('any')
url="https://omarchy.org"
license=('MIT')
package() {
:
}
EOF
print_success "Scaffolded PKGBUILD"
fi
fi
print_success "Package setup complete: $PACKAGE_DIR"