sequoia-sq: rebuild for capnproto-1.1.0.
[void-pkg.git] / common / xbps-src / shutils / update_check.sh
blobe626b307b7c65f21fac142319a47fa8ba3becf8c
1 # vim: set ts=4 sw=4 et ft=bash :
3 update_check() {
4 local i p url pkgurlname rx found_version consider
5 local update_override=$XBPS_SRCPKGDIR/$XBPS_TARGET_PKG/update
6 local original_pkgname=$pkgname
7 local pkgname=$sourcepkg
8 local urlpfx urlsfx
9 local -A fetchedurls
11 local curlargs=(
12 -A "xbps-src-update-check/$XBPS_SRC_VERSION"
13 --max-time 10 --compressed -Lsk
16 pkgname=${pkgname#kf6-}
18 # XBPS_UPDATE_CHECK_VERBOSE is the old way to show verbose messages
19 [ "$XBPS_UPDATE_CHECK_VERBOSE" ] && XBPS_VERBOSE="$XBPS_UPDATE_CHECK_VERBOSE"
21 if [ -r $update_override ]; then
22 . $update_override
23 msg_verbose "using $XBPS_TARGET_PKG/update overrides\n"
24 if [ -n "$disabled" ]; then
25 msg_verbose "update-check DISABLED for $original_pkgname: $disabled\n"
26 return 0
28 elif [ -z "$distfiles" ]; then
29 msg_verbose "NO DISTFILES found for $original_pkgname\n"
30 return 0
33 if ! type curl >/dev/null 2>&1; then
34 echo "ERROR: cannot find \`curl' executable!"
35 return 1
38 export LC_ALL=C
40 if [ -z "$site" ]; then
41 case "$distfiles" in
42 # special case those sites provide better source elsewhere
43 *ftp.gnome.org*|*download.gnome.org*) ;;
44 *archive.xfce.org*) ;;
46 printf '%s\n' "$homepage" ;;
47 esac
48 for i in $distfiles; do
49 printf '%s\n' "${i%/*}/"
50 done
51 else
52 printf '%s\n' "$site"
53 fi |
54 # filter loop: if version are "folder" name based,
55 # substitute original url by every folder based ones (expand)
56 while IFS= read -r url; do
57 # default case: don't rewrite url
58 printf '%s\n' "$url"
59 if [ "$single_directory" ]; then
60 continue
62 rx=
63 urlpfx="${url}"
64 urlsfx=
65 dirpfx=
66 case "$url" in
67 *.voidlinux.*|\
68 *sourceforge.net/sourceforge*|\
69 *code.google.com*|*googlecode*|\
70 *launchpad.net*|\
71 *cpan.*|\
72 *pythonhosted.org*|*pypi.org/project/*|\
73 *github.com*|\
74 *//gitlab.*|\
75 *bitbucket.org*|\
76 *ftp.gnome.org*|*download.gnome.org*|\
77 *archive.xfce.org*|\
78 *kernel.org/pub/linux/kernel/*|\
79 *cran.r-project.org/src/contrib*|\
80 *rubygems.org*|\
81 *crates.io*|\
82 *codeberg.org*|\
83 *hg.sr.ht*|\
84 *software.sil.org*|\
85 *git.sr.ht*)
86 continue
89 vdpfx=${vdprefix:-"|v|\\Q$pkgname\\E"}
90 vdsfx=${vdsuffix:-"|\\.x"}
91 match=$(grep -Po "^[^/]+//[^/]+(/.+)?/($vdpfx)(?=[-_.0-9]*[0-9](?<!\\Q$pkgname\\E)($vdsfx)/)" <<< "$url")
92 if [ "$?" = 0 ]; then
93 urlpfx="${match%/*}/"
94 dirpfx="${match##*/}"
95 urlsfx="${url#$urlpfx}"
96 urlsfx="${urlsfx#*/}"
97 rx="href=[\"']?(\\Q$urlpfx\\E)?\\.?/?\\K\\Q$dirpfx\\E[-_.0-9]*[0-9]($vdsfx)[\"'/]"
100 esac
101 if [ "$rx" ]; then
102 # substitute url if needed
103 msg_verbose "(folder) fetching $urlpfx and scanning with $rx\n"
104 skipdirs=
105 curl "${curlargs[@]}" "$urlpfx" |
106 grep -Po -i "$rx" |
107 # sort -V places 1.1/ before 1/, but 1A/ before 1.1A/
108 sed -e 's:$:A:' -e 's:/A$:A/:' | sort -Vru | sed -e 's:A/$:/A:' -e 's:A$::' |
109 while IFS= read -r newver; do
110 newurl="${urlpfx}${newver}${urlsfx}"
111 if [ "$newurl" = "$url" ]; then
112 skipdirs=yes
114 if [ -z "$skipdirs" ]; then
115 printf '%s\n' "$newurl"
117 done
119 done |
120 while IFS= read -r url; do
122 if [ -z "$site" ]; then
123 case "$url" in
124 *sourceforge.net/sourceforge*)
125 pkgurlname="$(printf %s "$url" | cut -d/ -f5)"
126 url="https://sourceforge.net/projects/$pkgurlname/rss?limit=200";;
127 *code.google.com*|*googlecode*)
128 url="https://code.google.com/p/$pkgname/downloads/list";;
129 *launchpad.net*)
130 pkgurlname="$(printf %s "$url" | cut -d/ -f4)"
131 url="https://launchpad.net/$pkgurlname/+download";;
132 *cpan.*)
133 pkgname=${pkgname#perl-};;
134 *pythonhosted.org*|*pypi.org/project/*)
135 pkgname=${pkgname#python-}
136 pkgname=${pkgname#python3-}
137 rx="(?<=${pkgname//-/[-_]}-)[0-9.]+(post[0-9]*)?(?=(([.]tar|-cp|-py)))"
138 url="https://pypi.org/simple/$pkgname";;
139 *github.com*)
140 pkgurlname="$(printf %s "$url" | cut -d/ -f4,5)"
141 url="https://github.com/$pkgurlname/tags"
142 rx='/archive/refs/tags/(v?|\Q'"$pkgname"'\E[-_])?\K[\d.]+(?=\.tar\.gz")';;
143 *//gitlab.*|*code.videolan.org*)
144 case "$url" in
145 */-/*) pkgurlname="$(printf %s "$url" | sed -e 's%/-/.*%%g; s%/$%%')";;
146 *) pkgurlname="$(printf %s "$url" | cut -d / -f 1-5)";;
147 esac
148 url="$pkgurlname/-/tags"
149 rx='/archive/[^/]+/\Q'"$pkgname"'\E-v?\K[\d.]+(?=\.tar\.gz)';;
150 *bitbucket.org*)
151 pkgurlname="$(printf %s "$url" | cut -d/ -f4,5)"
152 url="https://bitbucket.org/$pkgurlname/downloads"
153 rx='/(get|downloads)/(v?|\Q'"$pkgname"'\E-)?\K[\d.]+(?=\.tar)';;
154 *ftp.gnome.org*|*download.gnome.org*)
155 rx='(?<=LATEST-IS-)([0-24-9]|3\.[0-9]*[02468]|[4-9][0-9]+)\.[0-9.]*[0-9](?=\")'
156 url="https://download.gnome.org/sources/$pkgname/cache.json";;
157 *archive.xfce.org*)
158 rx='\Q'"$pkgname"'\E-\K((([4-9]|([1-9][0-9]+))\.[0-9]*[02468]\.[0-9.]*[0-9])|([0-3]\.[0-9.]*))(?=.tar)'
159 url="https://archive.xfce.org/feeds/project/$pkgname" ;;
160 *kernel.org/pub/linux/kernel/*)
161 rx=linux-'\K'${version%.*}'\.[\d.]+(?=\.tar\.xz)';;
162 *cran.r-project.org/src/contrib*)
163 rx='\b\Q'"${pkgname#R-cran-}"'\E_\K\d+(\.\d+)*(-\d+)?(?=\.tar)';;
164 *rubygems.org*)
165 url="https://rubygems.org/gems/${pkgname#ruby-}"
166 rx='href="/gems/'${pkgname#ruby-}'/versions/\K[\d.]*(?=")' ;;
167 *crates.io*)
168 url="https://crates.io/api/v1/crates/${pkgname#rust-}"
169 rx='/crates/'${pkgname#rust-}'/\K[0-9.]*(?=/download)' ;;
170 *codeberg.org*)
171 pkgurlname="$(printf %s "$url" | cut -d/ -f4,5)"
172 url="https://codeberg.org/$pkgurlname/tags"
173 rx='/archive/(v-?|\Q'"$pkgname"'\E-)?\K[\d.]+(?=\.tar\.gz)' ;;
174 *hg.sr.ht*)
175 pkgurlname="$(printf %s "$url" | cut -d/ -f4,5)"
176 url="https://hg.sr.ht/$pkgurlname/tags"
177 rx='/archive/(v?|\Q'"$pkgname"'\E-)?\K[\d.]+(?=\.tar\.gz")';;
178 *git.sr.ht*)
179 pkgurlname="$(printf %s "$url" | cut -d/ -f4,5)"
180 url="https://git.sr.ht/$pkgurlname/refs/rss.xml"
181 rx='<guid>\Q'"${url%/*}"'\E/(v-?|\Q'"$pkgname"'\E-)?\K[\d.]+(?=</guid>)' ;;
182 *pkgs.fedoraproject.org*)
183 url="https://pkgs.fedoraproject.org/repo/pkgs/$pkgname" ;;
184 *software.sil.org/downloads/*)
185 pkgurlname=$(printf '%s\n' "$url" | cut -d/ -f6)
186 url="https://software.sil.org/$pkgurlname/download/"
187 pkgname="${pkgname#font-}"
188 pkgname="${pkgname#sil-}"
189 _pkgname="${pkgname//-/}"
190 rx="($_pkgname|${_pkgname}SIL)[_-]\K[0-9.]+(?=\.tar|\.zip)" ;;
191 *software.sil.org/*)
192 pkgname="${pkgname#font-}"
193 pkgname="${pkgname#sil-}"
194 _pkgname="${pkgname//-/}"
195 rx="($_pkgname|${_pkgname}SIL)[_-]\K[0-9.]+(?=\.tar|\.zip)" ;;
196 esac
199 rx=${pattern:-$rx}
200 rx=${rx:-'(?<!-)\b\Q'"$pkgname"'\E[-_]?((src|source)[-_])?v?\K([^-/_\s]*?\d[^-/_\s]*?)(?=(?:[-_.](?:src|source|orig))?\.(?:[jt]ar|shar|t[bglx]z|tbz2|zip))\b'}
202 if [ "${fetchedurls[$url]}" ]; then
203 msg_verbose "already fetched $url\n"
204 continue
207 msg_verbose "fetching $url and scanning with $rx\n"
208 curl "${curlargs[@]}" -H 'Accept: text/html,application/xhtml+xml,application/xml,text/plain,application/rss+xml' "$url" |
209 grep -Po -i "$rx"
210 fetchedurls[$url]=yes
211 done |
212 tr _ . |
213 sort -Vu |
215 grep . || echo "NO VERSION found for $original_pkgname" 1>&2
217 while IFS= read -r found_version; do
218 msg_verbose "found version $found_version\n"
219 consider=true
220 p="$ignore "
221 while [ -n "$p" ]; do
222 i=${p%% *}
223 p=${p#* }
224 case "$found_version" in
226 consider=false
227 msg_verbose "ignored $found_version due to $i\n"
228 esac
229 done
230 if $consider; then
231 xbps-uhelper cmpver "$original_pkgname-${version}_1" \
232 "$original_pkgname-$(printf %s "$found_version" | tr - .)_1"
233 if [ $? = 255 ]; then
234 echo "${original_pkgname}-${version} -> ${original_pkgname}-${found_version}"
237 done