-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaur-mirror
More file actions
executable file
·54 lines (47 loc) · 1.33 KB
/
Copy pathaur-mirror
File metadata and controls
executable file
·54 lines (47 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
set -e -o pipefail
# Bare-minimum script for searching and cloning AUR packages from the mirror
# Use when AUR is down (e.g., under a DDoS attack) :(
#
# Install a fuzzy finder like fzf or fzy for better search experience
#
# Usage:
# aur-mirror search
# Search for a package from AUR (interactive)
# aur-mirror clone <package_name>
# Clone the package into <package_name> directory.
# You can then `cd <package_name>` and run `makepkg`
AUR_MIRROR_URL=${AUR_MIRROR_URL:-https://github.com/archlinux/aur.git}
find_alternatives() {
for i in "$@"; do
if command -v "$i" > /dev/null; then
echo "$i"
return 0
fi
done
return 1
}
get_branches() {
git ls-remote "${AUR_MIRROR_URL}" | grep '\srefs/heads/' | sed 's/^.*\srefs\/heads\///'
}
case "$1" in
search)
finder=$(find_alternatives fzf fzy less) || {
echo "Please install a fuzzy finder like fzf or fzy" >&2
exit 1
}
get_branches | "$finder"
;;
clone)
pkg="$2"
[ -n "$pkg" ] || {
echo "Please specify a package name"
exit 1
}
git clone "${AUR_MIRROR_URL}" --branch "$pkg" --single-branch "$pkg"
;;
*)
echo "Usage: $0 {search|clone <package_name>}" >&2
exit 1
;;
esac