-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaur-getpkg
executable file
·92 lines (75 loc) · 2.26 KB
/
aur-getpkg
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
## Copyright (c) 2017 Timothy Savannah All Rights Reserved
# Licensed under terms of Apache 2.0 License
# aur-getpkg
#
# Download the latest of a package's build files into the current directory.
#
# You probably want to run this in /usr/src/arch to go along with the rest of these
# tools
#
if [ "$1" = "--help" ];
then
cat -- >&2 <<EOT
Usage: aur-getpkg [pkgname]
Downloads the latest snapshot of an AUR package into current directory
You probably want to run this in /usr/src/arch, which is where pacman-utils expects you to
checkout packages.
EOT
exit 0;
fi
if [ $# -ne 1 ];
then
echo "Only a single argument is supported. Loop this program if you need to do multiple packages." >&2
echo " Use --help for help." >&2
exit 1;
fi
if ( echo "$1" | grep -q '/' ) || [ "$1" = ".." -o "$1" = "." ];
then
echo "Cannot be a directory. Must be a package name." >&2
exit 1;
fi
PKG_NAME="$1"
if [ -d "${PKG_NAME}" ];
then
if [ -d "${PKG_NAME}.bak" ];
then
echo "${PKG_NAME} exists and ${PKG_NAME}.bak exists."
x="z"
while [ $x != "y" -a "$x" != "Y" -a "$x" != "n" -a "$x" != "N" ];
do
printf "%s" "Remove old backup? (y/n):"
read x;
done
if [ "$x" = "n" -o "$x" = "N" ];
then
printf "%s\n" "Aborting based on user input." >&2
exit 1;
fi
rm -Rf "${PKG_NAME}.bak"
if [ $? -ne 0 ];
then
echo "Failed to remove '${PKG_NAME}.bak'" >&2
exit 1;
fi
fi
echo "Backing up ${PKG_NAME} to ${PKG_NAME}.bak..."
mv "${PKG_NAME}" "${PKG_NAME}.bak"
if [ $? -ne 0 ];
then
echo "Unable to move '${PKG_NAME}' to '${PKG_NAME}.bak" >&2
exit 1;
fi
fi
die() {
echo "$@" >&2
exit 1
}
TMP_NAME="$(mktemp --suffix=.tar.gz)"
URL="https://aur.archlinux.org/cgit/aur.git/snapshot/${PKG_NAME}.tar.gz"
# For some reason curl doesn't seem to work here, but wget does..
#curl -k https://aur.archlinux.org/cgit/aur.git/snapshot/pacman-utils-data.tar.gz
wget "${URL}" -O "${TMP_NAME}" || die "Failed to download '${URL}'"
tar -xzf "${TMP_NAME}" || die "Failed to extract archive"
rm -f "${TMP_NAME}"
echo "Checked out latest ${PKG_NAME} to `pwd`/${PKG_NAME}"