Files
2026-07-19 14:06:49 +08:00

49 lines
1.3 KiB
Bash

#!/usr/bin/env bash
# Clone / update AUR package sources
pkg_clone_dir() {
local name=$1
printf '%s/%s' "${MIAUR_CLONEDIR}" "$name"
}
# Clone or pull package; prints absolute path to clone dir
aur_clone() {
local name=$1
local dir
dir=$(pkg_clone_dir "$name")
mkdir -p "$MIAUR_CLONEDIR"
if [[ -d $dir/.git ]]; then
msg2 "Updating $name..."
if ! (cd "$dir" && ${MIAUR_GIT} pull --ff-only --quiet); then
warn "Cannot fast-forward $name; cloning it again"
rm -rf "$dir"
${MIAUR_GIT} clone --quiet "${MIAUR_AURURL}/${name}.git" "$dir" || die "clone failed: $name"
fi
else
rm -rf "$dir"
msg2 "Cloning $name..."
${MIAUR_GIT} clone --quiet "${MIAUR_AURURL}/${name}.git" "$dir" || die "clone failed: $name"
fi
[[ -f $dir/PKGBUILD ]] || die "PKGBUILD not found after cloning: $name"
printf '%s\n' "$dir"
}
# Clean clone cache for one package or all
aur_clean_cache() {
local target=${1:-}
if [[ -n $target ]]; then
local dir
dir=$(pkg_clone_dir "$target")
if [[ -d $dir ]]; then
msg "Cleaning cache: $dir"
rm -rf "$dir"
fi
else
if [[ -d $MIAUR_CLONEDIR ]]; then
msg "Cleaning AUR cache: $MIAUR_CLONEDIR"
# Keep VCS src dirs? Plan says clean clone cache — remove package dirs
find "$MIAUR_CLONEDIR" -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} +
fi
fi
}