forked from SoftCreatR/imei
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_version_info.sh
142 lines (117 loc) · 4.44 KB
/
update_version_info.sh
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
#!/usr/bin/env bash
# Make sure, that jq is available
if ! command -v jq >/dev/null 2>&1; then
echo "Error: This tool requires jq to be installed." >&2
exit 1
fi
WORKDIR=$(dirname "$0")
GH_API_BASE="https://api.github.com/repos"
GH_FILE_BASE="https://codeload.github.com"
CLIENT=""
AUTHORIZATION=""
###
# Helper functions
###
getClient()
{
if command -v curl &>/dev/null; then
CLIENT="curl"
elif command -v wget &>/dev/null; then
CLIENT="wget"
elif command -v http &>/dev/null; then
CLIENT="httpie"
else
echo "Error: This tool requires either curl, wget or httpie to be installed." >&2
return 1
fi
}
httpGet()
{
if [[ -n "${GITHUB_TOKEN}" ]]; then
AUTHORIZATION='{"Authorization": "Bearer '"$GITHUB_TOKEN"'}"}'
fi
case "$CLIENT" in
curl) curl -A curl -s -H "$AUTHORIZATION" "$@" ;;
wget) wget -qO- --header="$AUTHORIZATION" "$@" ;;
httpie) http -b GET "$@" "$AUTHORIZATION" ;;
esac
}
###
if [ -z "$CLIENT" ]; then
getClient || exit 1
fi
###
# Stuff that looks more complicated
# than it actually is
###
# Get version information for latest stable ImageMagick and write it to file
IMAGEMAGICK_VER=$(httpGet "$GH_API_BASE/ImageMagick/ImageMagick/releases" | jq -r '[.[] | select(.tag_name|test("^[0-9]+.[0-9]+.[0-9]+(-[0-9]+)?$")) | .tag_name] | join("\n")' | sort -rV | head -1)
if [ -n "$IMAGEMAGICK_VER" ]; then
echo "$IMAGEMAGICK_VER" > "$WORKDIR/versions/imagemagick.version"
else
echo "Error: Failed to get version information for ImageMagick."
exit 1
fi
# Download ImageMagick tarball, calculate it's hash and write it to file
IMAGEMAGICK_HASH=$(httpGet "$GH_FILE_BASE/ImageMagick/ImageMagick/tar.gz/$IMAGEMAGICK_VER" | sha1sum | cut -b-40)
if [ -n "$IMAGEMAGICK_HASH" ]; then
echo "$IMAGEMAGICK_HASH" > "$WORKDIR/versions/imagemagick.hash"
else
echo "Error: Failed to get hash information for ImageMagick $IMAGEMAGICK_VER tarball."
exit 1
fi
# Get version information for latest stable aom and write it to file
LIBAOM_VER=$(httpGet "$GH_API_BASE/jbeich/aom/tags" | jq -r '[.[] | select(.name|test("^v[0-9]+.[0-9]+.[0-9]+$")) | .name[1:]] | join("\n")' | sort -rV | head -1)
if [ -n "$LIBAOM_VER" ]; then
echo "$LIBAOM_VER" > "$WORKDIR/versions/aom.version"
else
echo "Error: Failed to get version information for AOM."
exit 1
fi
# Download aom tarball, calculate it's hash and write it to file
LIBAOM_HASH=$(httpGet "$GH_FILE_BASE/jbeich/aom/tar.gz/v$LIBAOM_VER" | sha1sum | cut -b-40)
if [ -n "$LIBAOM_HASH" ]; then
echo "$LIBAOM_HASH" > "$WORKDIR/versions/aom.hash"
else
echo "Error: Failed to get hash information for AOM $LIBAOM_VER tarball."
exit 1
fi
# Get version information for libheif and write it to file
LIBHEIF_VER=$(httpGet "$GH_API_BASE/strukturag/libheif/tags" | jq -r '[.[] | select(.name|test("^v[0-9]+.[0-9]+.[0-9]+$")) | .name[1:]] | join("\n")' | sort -rV | head -1)
if [ -n "$LIBHEIF_VER" ]; then
echo "$LIBHEIF_VER" > "$WORKDIR/versions/libheif.version"
else
echo "Error: Failed to get version information for libheif."
exit 1
fi
# Download libheif tarball, calculate it's hash and write it to file
LIBHEIF_HASH=$(httpGet "$GH_FILE_BASE/strukturag/libheif/tar.gz/v$LIBHEIF_VER" | sha1sum | cut -b-40)
if [ -n "$LIBHEIF_HASH" ]; then
echo "$LIBHEIF_HASH" > "$WORKDIR/versions/libheif.hash"
else
echo "Error: Failed to get hash information for libheif $LIBHEIF_VER tarball."
exit 1
fi
# Get version information for libjxl and write it to file
LIBJXL_VER=$(httpGet "$GH_API_BASE/libjxl/libjxl/tags" | jq -r '[.[] | select(.name|test("^v[0-9]+.[0-9]+(.[0-9]+)?$")) | .name[1:]] | join("\n")' | sort -rV | head -1)
if [ -n "$LIBJXL_VER" ]; then
echo "$LIBJXL_VER" > "$WORKDIR/versions/libjxl.version"
else
echo "Error: Failed to get version information for libjxl."
exit 1
fi
# Download libjxl tarball, calculate it's hash and write it to file
LIBJXL_HASH=$(httpGet "$GH_FILE_BASE/libjxl/libjxl/tar.gz/v$LIBJXL_VER" | sha1sum | cut -b-40)
if [ -n "$LIBJXL_HASH" ]; then
echo "$LIBJXL_HASH" > "$WORKDIR/versions/libjxl.hash"
else
echo "Error: Failed to get hash information for libjxl $LIBJXL_VER tarball."
exit 1
fi
# Update README file
REPLACEMENT="\n* ImageMagick version: \`$IMAGEMAGICK_VER (Q16)\`\n"
REPLACEMENT+="* libaom version: \`$LIBAOM_VER\`\n"
REPLACEMENT+="* libheif version: \`$LIBHEIF_VER\`\n"
REPLACEMENT+="* libjxl version: \`$LIBJXL_VER\`"
sed -En '1h;1!H;${g;s/(<!-- versions start -->)(.*)(<!-- versions end -->)/\1'"$REPLACEMENT"'\3/;p;}' -i "$WORKDIR/README.md"
exit 0