forked from ArchStrike/pkgupdates
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestversion
More file actions
executable file
·225 lines (193 loc) · 6.81 KB
/
testversion
File metadata and controls
executable file
·225 lines (193 loc) · 6.81 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env bash
# Change to the script directory
cd "${0%/*}"
# SCRIPT VARIABLES
currdir="$PWD"
script_name=$(grep -o -e "[^\/]*$" <<< "$0")
archversion_check="check"
replace_values=0
# CONFIG VARIABLES
config='pkgupdates.conf'
[[ ! -f "$config" ]] && {
printf '%s\n' 'Error: the config file is missing, run ./pkgupdates -c to generate a new one' >&2
exit 1
}
source "$config"
GITREPO_URL=${GITREPO_URL:='https://github.com/ArchStrike/ArchStrike.git'}
archversion_config_test="$(sed -re 's|([^/]*$)|test\.\1|g' <<< "$ARCHVERSION_CONF")"
pkg_cache="$currdir/.archversion.cache"
# Colourscheme
[[ -t 1 ]] && {
c_d=$'\e[1;30m' # DARK GREY
c_r=$'\e[1;31m' # RED
c_g=$'\e[1;32m' # GREEN
c_y=$'\e[1;33m' # YELLOW
c_b=$'\e[1;34m' # BLUE
c_m=$'\e[1;35m' # VIOLET
c_t=$'\e[1;36m' # TEAL
c_w=$'\e[1;37m' # WHITE
c_c=$'\e[0m' # DISABLES COLOUR
}
function help {
printf '\n%s\n' 'DESCRIPTION:'
printf '%s\n\n' ' $script_name - use archversion.conf to create and run test configs'
printf '%s\n' 'USAGE:'
printf '%s\n\n' " $script_name [FLAGS] [COMMAND]"
printf '%s\n' 'FLAGS:'
printf '%s\n' " -d ${c_d}|$c_c run archversion with debugging enabled"
printf '%s\n' " -r ${c_d}|$c_c replace current values with ones generated by $script_name"
printf '%s\n\n' " -u ${c_d}|$c_c update the package repo before running the command"
printf '%s\n' "COMMANDS:"
printf '%s\n' " n|next ${c_d}|$c_c load the next commented package into the test config"
printf '%s\n' " l|list ${c_d}|$c_c generate a test config using a list of packages"
printf '%s\n' " c|check ${c_d}|$c_c check the loaded package in the text config"
printf '%s\n\n' " h|help ${c_d}|$c_c show this help"
exit "$1"
}
function pkgname_sanitize {
tmp_name=${1#ruby1\.[8-9]-}
tmp_name=${tmp_name#python[2-3]-}
tmp_name=${tmp_name#python-}
tmp_name=${tmp_name%-cvs}
tmp_name=${tmp_name%-svn}
tmp_name=${tmp_name%-hg}
tmp_name=${tmp_name%-darcs}
tmp_name=${tmp_name%-bzr}
tmp_name=${tmp_name%-git}
printf '%s' "${tmp_name/-git}"
}
function repo_init {
# Setup/Update Repo
printf '%s\n\n' "Updating repo @ $REPODIR..."
if [[ -d "$REPODIR" ]]; then
pushd "$REPODIR" > /dev/null 2>&1
git reset --hard >/dev/null 2>&1
git pull >/dev/null 2>&1
else
git clone "$GITREPO_URL" "$REPODIR" >/dev/null 2>&1
pushd "$REPODIR" > /dev/null 2>&1
git checkout updates >/dev/null 2>&1
fi
popd > /dev/null 2>&1
}
function config_init {
# write (or write over) the config file with a template for everything above packages
sed 's|^\s*#\s*||;/\[\s*DEFAULT\s*\]/,$!d;/^$/q' "$ARCHVERSION_CONF" \
> "$archversion_config_test"
}
function pkg_generate {
# reset any variables we're going to use and set the package name
unset pkgbuild pkgdef regex pkgname _pkgname url _url
pkg="$1"
# configure the location of the PKGBUILD after checking that there is one
[[ ! -f "$REPODIR/packages/$pkg/PKGBUILD" ]] && {
printf '%s\n' "Error: no PKGBUILD for $pkg exists in $REPODIR/packages" >&2
exit 1
}
pkgbuild="$REPODIR/packages/$pkg/PKGBUILD"
# create an initial $pkgdef, using the archversion.conf entry one exists
if egrep -q "\[\s*$pkg\s*\]" "$ARCHVERSION_CONF"; then
pkgdef=$(sed 's|^\s*#\s*||;/\[\s*'"$pkg"'\s*\]/,$!d;/^$/q' "$ARCHVERSION_CONF")
else
pkgdef="[$pkg]"
fi
# remove values after the title if $replace_values is set to 1
[[ "$replace_values" = 1 ]] \
&& pkgdef=$(head -n 1 <<< "$pkgdef")
# source the information we want from the PKGBUILD
eval "$(egrep '^_pkgname\s*=|^pkgname\s*=|^url\s*=' "$pkgbuild" | egrep -v '^\s*#')"
# if this is a python package, use pipy as the upstream url if the page exists
if egrep -q '^python[2-3]|^python-' <<< "$pkg"; then
_url='https://pypi.python.org/pypi/'"$(pkgname_sanitize "$pkg")"
[[ ! $(curl --write-out %{http_code} --silent --output /dev/null "$_url") = 404 ]] \
&& url=$_url
unset _url
fi
# add a url after the package name if one doesn't exist
egrep -q '^\s*url\s*=' <<< "$pkgdef" \
|| pkgdef=$(sed -re 's|^(\s*\[.*\]\s*)$|\1\nurl = '"$url"'|' <<< "$pkgdef")
# add a regex after if one doesn't exist
if egrep -q '^\s*regex\s*=' <<< "$pkgdef"; then
regex=$(egrep '^\s*regex\s*=\s*' <<< "$pkgdef" | sed 's|^.*= *||')
elif ! egrep -q "^\s*\[\s*$pkg\s*\]" "$ARCHVERSION_CONF"; then
regex="$(pkgname_sanitize "$pkg")"'-([0-9][0-9]*\\\.[0-9][0-9]*)'
pkgdef=$(sed -re 's|^(\s*url\s*=.*)$|\1\nregex = '"$regex"'|' <<< "$pkgdef")
fi
# add the definition to the package
printf '%s\n\n' "$pkgdef" >> "$archversion_config_test"
# display the starting values
printf '%s\n\n' "$pkgdef"
}
function pkg_list {
[[ -z "$1" ]] && {
printf '%s\n' 'Error: you must supply at least one package to use' >&2
exit 1
}
config_init
# extract each package, uncomment if necessary, then add to the config
for pkg in "$@"; do
pkg_generate "$pkg"
done
printf '%s\n' "Created: $archversion_config_test"
printf '%s\n\n' "Running: archversion $archversion_check..."
pkg_check
}
function pkg_next {
config_init
# find the first commented package
pkg=$(grep -v '[DEFAULT]' "$ARCHVERSION_CONF" \
| sed '/^\ *#\ *\[/,$!d;/^$/q;s|^\ *#\ *||' \
| grep -e '^\s*\[[^]]*\]' \
| grep -o -e '[^][]*')
pkg_generate "$pkg"
printf '%s\n' "Created: $archversion_config_test"
printf '%s\n\n' "Running: archversion $archversion_check..."
pkg_check
}
function pkg_check {
# Create the cache file if it's missing
[[ ! -f "$pkg_cache" ]] \
&& printf '%s\n' '{"downstream": {}, "compare": {}}' > "$pkg_cache"
CONFIG_PACKAGES="$archversion_config_test" \
CACHE_PACKAGES="$pkg_cache" \
archversion $archversion_check
}
function handle_args {
# Otherwise, do what he user asks for
case "$1" in
n|next)
pkg_next
;;
l|list)
shift
pkg_list "$@"
;;
c|check)
printf '%s\n' "Running archversion check for $archversion_config_test"
pkg_check
;;
h|help)
help 0
;;
-d)
archversion_check="--debug $archversion_check"
shift; handle_args "$@"
;;
-r)
replace_values="1"
shift; handle_args "$@"
;;
-u)
repo_init
shift; handle_args "$@"
;;
*)
printf '%s\n' "Invalid command: $1"
help 1
;;
esac
}
# if the user enters nothing, show the help
[[ -z "$1" ]] \
&& help 0
handle_args "$@"