-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabs2
executable file
·161 lines (131 loc) · 3.43 KB
/
abs2
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
## Copyright (c) 2017 Timothy Savannah All Rights Reserved
# Licensed under terms of Apache 2.0 License
# abs2 -
#
# Sorta supports some old "abs-style" development, whilst not
# overwhelimg the archlinux servers as developers have requested
#
# Fetches a package into a new "abs2" dir style, which is shared amongst
# all users in the "users" group.
#
# Arguments are individual package names, and will fetch that package.
#
if [ -z "${ABS2_DIR}" ];
then
ABS2_DIR="/var/abs2"
else
# Strip trailing slash
ABS2_DIR="$(echo "${ABS2_DIR}" | sed -e 's|[/][/]*$||g')"
fi
_init_abs2() {
[ -d "${ABS2_DIR}" ] && return;
# Handle conversion maybe here? Right now only one DB version
mkdir ${ABS2_DIR}
if [ $? -ne 0 ];
then
printf "Failed to create \"%s\". Run once as root user.\n" "${ABS2_DIR}" >&2
if [ "`whoami`" != "root" ];
then
printf "Rerunning as root:\n"
sudo $0 "$@"
exit $?
fi
fi
chmod 2775 ${ABS2_DIR}
chgrp users "${ABS2_DIR}"
printf "0.1\n" > "${ABS2_DIR}/.abs2_version"
}
get_repo_for_package() {
PKG_NAME="${1}"
SEARCH_RESULT="$(pacman -Sl | grep " ${PKG_NAME} ")"
if [ $? -ne 0 ] || [ -z "${SEARCH_RESULT}" ];
then
printf "Cannot find package: \"%s\"\n" "${PKG_NAME}" >&2
return 1
fi
REPO="$(echo "${SEARCH_RESULT}" | sed -e 's/ .*//g')"
if [ -z "${REPO}" ];
then
printf "Cannot determine repo for package: \"%s\"\n" "${PKG_NAME}" >&2
return 1
fi
echo "${REPO}"
return 0;
}
do_package() {
PKG_NAME="${1}"
REPO="$(get_repo_for_package "${PKG_NAME}")"
if [ $? -ne 0 ];
then
# Function prints error message, so just raise
return 1;
fi
if [ "$(echo "${REPO}" | wc -l)" -gt 1 ];
then
MULTI_REPOS=1
declare -a REPOS
NUM=0
for item in ${REPO};
do
declare REPOS[$NUM]="${item}"
NUM=$(( $NUM + 1 ))
done
else
declare -a REPOS
declare REPOS[0]="${REPO}"
fi
OLD_DIR="$(pwd)"
cd "${ABS2_DIR}"
for repo in "${REPOS[@]}";
do
if [ "$repo" = "core" -o "${repo}" = "extra" ];
then
DIR="packages"
elif [ "$repo" = "community" -o "$repo" = "multilib" ];
then
DIR="community"
else
printf "Unknown repo: %s\n" "${repo}" >&2
continue
fi
if [ ! -d "${DIR}" ];
then
OUTPUT="$(svn checkout --depth=empty "svn://svn.archlinux.org/${DIR}" 2>&1)"
if [ $? -ne 0 ];
then
printf "Failed to checkout svn://svn.archlinux.org/%s\n" "${DIR}" >&2
printf "%s\n" "${OUTPUT}" >&2
exit 1
fi
chgrp users "${DIR}" "${DIR}/.svn" -R
chmod g+w "${DIR}" "${DIR}/.svn" -R
fi
cd "${DIR}"
svn cleanup
svn up "${PKG_NAME}" >&2
cd ..
echo "$(realpath "${DIR}/${PKG_NAME}")"
done
cd "${OLD_DIR}"
}
if [ "$1" = "--help" ];
then
cat -- <<EOT
Usage: abs2 [package name]
Downloads the latest "package name" - and outputs the directory to find
the trunk version.
EOT
exit 0;
fi
if [ "$1" = "-q" ];
then
shift;
"$0" "$@" 2>/dev/null
exit $?
fi
_init_abs2
for pkg in "$@";
do
do_package "${pkg}"
done