63 lines
2.4 KiB
Bash
Executable File
63 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Internal initial-recipe import used by add-package. Maintained recipes are
|
|
# never replaced; subsequent releases go through sync-upstream.
|
|
set -euo pipefail
|
|
|
|
BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..")
|
|
source "$BUILD_ROOT/helpers/message-helpers.sh"
|
|
source "$BUILD_ROOT/helpers/paths.sh"
|
|
|
|
if [[ ${1:-} == --help || ${1:-} == -h ]]; then
|
|
echo "Usage: bin/add-package <package> --source aur [--aur <upstream-name>]"
|
|
exit 0
|
|
fi
|
|
if [[ $# != 1 || ! $1 =~ ^[a-zA-Z0-9@_+][a-zA-Z0-9@._+-]*$ ]]; then
|
|
print_error "Use bin/add-package <package> --source aur for an initial import"
|
|
exit 1
|
|
fi
|
|
package=$1
|
|
package_dir="$PKGBUILDS_DIR/$package"
|
|
metadata="$package_dir/.omarchy/package.json"
|
|
if [[ -f "$package_dir/PKGBUILD" ]]; then
|
|
print_error "Refusing to replace the maintained recipe for $package"
|
|
exit 1
|
|
fi
|
|
if [[ ! -f "$metadata" ]] || [[ $(jq -r .source "$metadata") != aur ]]; then
|
|
print_error "Initial import requires metadata created by bin/add-package --source aur"
|
|
exit 1
|
|
fi
|
|
aur_package=$(jq -r --arg name "$package" '.aur // $name' "$metadata")
|
|
if [[ ! $aur_package =~ ^[a-zA-Z0-9@_+][a-zA-Z0-9@._+-]*$ ]]; then
|
|
print_error "Invalid AUR package name"
|
|
exit 1
|
|
fi
|
|
# Refuse unrelated package files: an import only starts from .omarchy metadata.
|
|
shopt -s dotglob nullglob
|
|
for item in "$package_dir"/*; do
|
|
if [[ ${item##*/} != .omarchy ]]; then
|
|
print_error "Initial import needs an empty package directory: $package_dir"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
work=$(mktemp -d "$PKGBUILDS_DIR/.import-aur.XXXXXX")
|
|
trap 'rm -rf "$work"' EXIT
|
|
print_info "Importing $package from AUR package $aur_package..."
|
|
git clone --quiet "https://aur.archlinux.org/${aur_package}.git" "$work/recipe"
|
|
[[ -f "$work/recipe/PKGBUILD" ]] || { print_error "AUR package has no PKGBUILD"; exit 1; }
|
|
commit=$(git -C "$work/recipe" rev-parse HEAD)
|
|
rm -rf "$work/recipe/.git" "$work/recipe/.omarchy"
|
|
rm -f "$work/recipe/.SRCINFO" "$work/recipe/.gitignore"
|
|
cp -a "$package_dir/.omarchy" "$work/recipe/.omarchy"
|
|
jq --arg name "$aur_package" --arg commit "$commit" '
|
|
.source = "local" | .origin = {aur: $name, commit: $commit}
|
|
| del(.aur, .upstream_commit)
|
|
' "$metadata" > "$work/recipe/.omarchy/package.json"
|
|
# Stage on the same filesystem, restoring the metadata directory on failure.
|
|
mv "$package_dir" "$work/original"
|
|
if ! mv "$work/recipe" "$package_dir"; then
|
|
mv "$work/original" "$package_dir"
|
|
exit 1
|
|
fi
|
|
print_success "Imported $package; review the recipe and configure its direct upstream watch"
|