Skip to content

Commit e22ef65

Browse files
committed
BUILD: Add build and check updates scripts
The package can be built using the script rpmbuild-docker. In order to use this script, a functional Docker environment is needed, with ability to pull CentOS (el6, el7) or Rocky Linux (el8) images from internet if not already downloaded. To build: $ ./rpmbuild-docker -d el8 $ ./rpmbuild-docker -d el7 $ ./rpmbuild-docker -d el6 To check for upstream updates: $ ./check-updates
1 parent d05b391 commit e22ef65

File tree

4 files changed

+546
-0
lines changed

4 files changed

+546
-0
lines changed

check-updates

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/bin/bash
2+
#
3+
# License: MIT
4+
# Author: Benoit DOLEZ <[email protected]>
5+
# Copyright: 2019
6+
#
7+
8+
set -o pipefail
9+
PROGNAME=${0##*/}
10+
SUFFIX="(tar\\.gz|tgz|tar\\.xz|tar\\.bz2|tbz|zip|(src\\.)?rpm)"
11+
CACHEDIR=${CACHEDIR:-/tmp/$PROGNAME}
12+
13+
function get-data-lynx() {
14+
local url=$1 ; shift
15+
lynx -dump "$url" | sed -n -r -e 's/^[ 0-9]+\. //p'
16+
}
17+
18+
function get-data-json() {
19+
local url=$1 ; shift
20+
curl --connect-timeout 10 -fLs "$url" |jq . |grep -Pio '(?<=")[a-z+]+://[^"]+'
21+
}
22+
23+
function get-data() {
24+
local method=$1 ; shift
25+
if declare -F -f "$FUNCNAME-$method"; then
26+
"$FUNCNAME-$method" "$@" || return 1
27+
else
28+
return 1
29+
fi
30+
}
31+
32+
function check-updates() {
33+
local base=$1 ; shift
34+
local current=$1 ; shift
35+
local method=$1 ; shift
36+
local url=$1 ; shift
37+
local vpattern="${1:-[0-9.]+}"
38+
local pattern=$1 ; shift
39+
local rewrite=${1:-"\2\t\1"} ; shift
40+
local source version last current
41+
# pattern need to respect this
42+
# $1 : PATH
43+
# $2 : FILE
44+
# $3 : SUFFIX
45+
if [[ -z $url ]]; then
46+
echo "[FATAL] need at least an url" >&2
47+
exit 1
48+
fi
49+
if [[ -z $base ]]; then
50+
base=${url##*/}
51+
url=${url%/*}
52+
base=${base%%-[0-9]*}
53+
fi
54+
if [[ -z $pattern ]]; then
55+
pattern=".*/($base-($vpattern)\\.$SUFFIX)"
56+
elif [[ ${pattern:0:1} == "-" ]]; then
57+
pattern=".*/($base-($pattern)\\.$SUFFIX)"
58+
elif [[ ${pattern:0:1} == "/" ]] ; then
59+
s=$pattern
60+
pattern=".*/${s%/*}/(${s##*/}\\.$SUFFIX)"
61+
elif [[ ${pattern:0:1} == "=" ]]; then
62+
pattern=".*/(${pattern:1})"
63+
else
64+
pattern=".*/($pattern\\.$SUFFIX)"
65+
fi
66+
67+
echo "# $base ($url)" >&2
68+
69+
[[ $VERBOSE ]] && echo "pattern: $pattern" >&2
70+
[[ $VERBOSE ]] && echo "rewrite: $rewrite" >&2
71+
h=( $base-$(echo "$method,$url" | md5sum) )
72+
[[ $VERBOSE ]] && echo "hash: $h" >&2
73+
if [[ $FORCE || ! -s $CACHEDIR/$h.data ]] &&
74+
! get-data "$method" "$url" > $CACHEDIR/$h.data ; then
75+
echo "[ERROR] can't get data for $base ($method)" >&2
76+
return 1
77+
fi
78+
79+
## FIXME : remove .zip when .tgz exists
80+
81+
[[ -z $FORCE && -s $CACHEDIR/$h.list ]] ||
82+
cat $CACHEDIR/$h.data |
83+
sed -r -n -e "s'^$pattern$'\0\t$rewrite'p" |
84+
sort -u -V -k 2 > $CACHEDIR/$h.list
85+
86+
while read -r s v f ; do
87+
source=$s ; version=$v ; filename=$f
88+
[[ $ALL && $version ]] && echo "$base $version $source"
89+
done < $CACHEDIR/$h.list
90+
91+
if [[ -z $version ]]; then
92+
echo "[ERROR] can't find version for $base" >&2
93+
return 1
94+
fi
95+
96+
[[ $VERBOSE ]] && echo "> $base $version $source" >&2
97+
98+
if [[ $current != $version ]]; then
99+
ordered=( $(echo -e "$current\n$version\n" | sort -V) )
100+
[[ $VERBOSE ]] &&
101+
echo "[DEBUG] $current ? ${ordered[0]} < ${ordered[1]}" >&2
102+
if [[ ${ordered[1]} != $current ]]; then
103+
echo "** $base ($current) need update to $version **"
104+
return 1
105+
fi
106+
fi
107+
}
108+
109+
while [[ $# -gt 0 ]] ; do
110+
case "$1" in
111+
-f|--filename) FILENAME=$2 ; shift ;;
112+
-v|--verbose) VERBOSE=1 ;;
113+
-a|--all) ALL=1 ;;
114+
-F|--force) FORCE=1 ;;
115+
-*) echo "unknown parameter $1" >&2 ; exit 1 ;;
116+
*) break ;;
117+
esac
118+
shift
119+
done
120+
121+
[[ -d $CACHEDIR ]] || mkdir -p $CACHEDIR
122+
[[ -z $1 && -e $PROGNAME.def ]] && FILENAME=$PROGNAME.def
123+
124+
if [[ $FILENAME ]] ; then
125+
status=0
126+
while read -r base current method url pattern rewrite ; do
127+
[[ -z ${url%%# *} ]] && continue
128+
[[ $1 && $base != $1 ]] && continue
129+
check-updates "$base" "$current" "$method" "$url" "$pattern" "$rewrite" || status=1
130+
done < $FILENAME
131+
exit $status
132+
elif [[ $1 ]] ; then
133+
check-updates "$@"
134+
fi

check-updates.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lua-5.3 5.3.6 lynx http://www.lua.org/ftp/ lua-(5.3.[0-9.]+)
2+
lua-cjson 2.1.0 json https://api.github.com/repos/mpx/lua-cjson/tags =([0-9.]+)
3+
Lua-cURLv3 0.3.13 json https://api.github.com/repos/Lua-cURL/Lua-cURLv3/tags =v([0-9.]+)
4+
luafilesystem 1_8_0 json https://api.github.com/repos/keplerproject/luafilesystem/tags =v([0-9]+(_[0-9]+)*)
5+
luasocket 3.0.0 json https://api.github.com/repos/lunarmodules/luasocket/tags =v([0-9.]+)

prebuild.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash -xe
2+
3+
case "$DIST" in
4+
el6)
5+
# el6 EOL, use archive repositories
6+
sed -i -re 's,mirror\.centos\.org,vault.centos.org,; s,^(mirrorlist),#\1,; s,^#(baseurl),\1,' \
7+
/etc/yum.repos.d/CentOS-Base.repo
8+
;;
9+
esac

0 commit comments

Comments
 (0)