-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.sh
executable file
·234 lines (195 loc) · 5.65 KB
/
update.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
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
226
227
228
229
230
231
232
233
234
#!/bin/bash
# dummy methods
get_pkg_directory() {
echo "H"
}
get_build_dir() {
echo "B"
}
get_install_dir() {
echo "I"
}
target_has_feature() {
return 1
}
PROGNAME=$0
RUN=""
PACKAGE=""
usage() {
cat << EOF >&2
Usage: $PROGNAME [-a|-t|-s PKG_NAME|-r PKG_NAME]
Options
-a : Check and update all packages
-p : Update Plugins only
-t : Do a dry run for updating all packages
-s PKG_NAME : Check and update single package PKG_NAME
-r PKG_NAME : reset package PKG_NAME to HEAD
--help : Show this help
EOF
exit 1
}
reset_package() {
if [[ -z "$1" ]]; then
echo "ERROR: no PKG_NAME given"
usage
exit 1
fi
FOUND=""
packages=($(find packages -name package.mk))
for (( i=0; i<${#packages[@]}; i++ )); do
source ${packages[$i]}
if [[ "$1" != "$PKG_NAME" ]]; then
continue
fi
FOUND="1"
echo "$PKG_NAME - trying reset to HEAD"
SUCCESS="$(git checkout HEAD ${packages[$i]} 2>&1 | grep '^[^0]')"
if [[ -z ${SUCCESS} ]]; then
echo " --> no reset needed"
else
echo " --> reset done"
fi
done
if [[ -z ${FOUND} ]]; then
echo "could not find package $1"
fi
}
# find all package.mk und try to check, if an update exists
# if an updated version exist, update the package if forced with "-u"
# This currently works only for git repositories
update() {
packages=($(find packages -name package.mk))
if [[ -z ${RUN} ]]; then
echo "Perform a dry run!"
else
echo "Try update ..."
fi
if [[ -z "$PACKAGE" ]]; then
echo "Available packages: ${#packages[@]}"
else
echo "checking $PACKAGE"
fi
PKGARRAY=()
VERARRAY=()
SHAARRAY=()
PKGNAMEARRAYMAN=()
PKGNAMEARRAYSKIP=()
manual=0
skipped=0
autoupdate=0
for (( i=0; i<${#packages[@]}; i++ )); do
PKG_BRANCH=""
PKG_BRANCH_DEFAULT=""
PKG_NAME=$(grep -e "^PKG_NAME" ${packages[$i]} | sed s/^PKG_NAME=\"// | sed s/\"$// )
PKG_SITE=$(grep -e "^PKG_SITE" ${packages[$i]} | sed s/^PKG_SITE=\"// | sed s/\"$// )
PKG_BRANCH=$(grep -e "^PKG_BRANCH" ${packages[$i]} | sed s/^PKG_BRANCH=\"// | sed s/\"$// )
PKG_VERSION=$(grep -e "^PKG_VERSION" ${packages[$i]} | sed s/^PKG_VERSION=\"// | sed s/\"$// )
PKG_URL=$(grep -e "^PKG_URL" ${packages[$i]} | sed s/^PKG_URL=\"// | sed s/\"$// )
PKG_BRANCH=$(grep -e "^PKG_BRANCH" ${packages[$i]} | sed s/^PKG_BRANCH=\"// | sed s/\"$// )
if [ -n "$PACKAGE" ] && [ ! "$PACKAGE" = "$PKG_NAME" ]; then
continue
fi
if [[ ! -z "$PLUGINSONLY" ]] && [[ ! $PKG_NAME =~ "_vdr-plugin" ]]; then
continue
fi
if [[ $PKG_SITE =~ github ]] || [[ $PKG_SITE =~ gitlab ]]; then
COUNT_BRANCHES=$(git ls-remote -h $PKG_SITE | wc -l)
PKG_BRANCH_DEFAULT=`git ls-remote --symref "$PKG_SITE" HEAD | sed -nE 's|^ref: refs/heads/(\S+)\s+HEAD|\1|p'`
if [[ -z ${PKG_BRANCH} ]]; then
PKG_BRANCH=$PKG_BRANCH_DEFAULT
fi
LATEST=$(git ls-remote -h $PKG_SITE | grep $PKG_BRANCH | head -1 | awk -F' ' '{ print $1 }')
if [ ! "$PKG_VERSION" == "$LATEST" ]; then
if [[ -z `grep -oE "^PKG_VERSION=\"([a-f]|[0-9]){40}\"" ${packages[$i]}` ]]; then
echo " $PKG_NAME - found new version, but packages version is a release tag, skip updating"
PKGNAMEARRAYMAN+=( ${PKG_NAME} )
manual=$((manual + 1))
continue
fi
echo "$PKG_NAME - found new version"
NEUE_URL=$( echo ${PKG_URL} | sed -e s/\$\{PKG_VERSION\}/${LATEST}/g )
SHA=$(wget -q "${NEUE_URL}" -O- | sha256sum | cut -d " " -f1)
echo " PKG_VERSION=\"$LATEST\""
echo " PKG_SHA256=\"${SHA}\""
# fill array with updateable packages
PKGARRAY+=( ${packages[$i]} )
PKGNAMEARRAY+=( ${PKG_NAME} )
VERARRAY+=( ${LATEST} )
SHAARRAY+=( ${SHA} )
autoupdate=$((autoupdate + 1))
else
echo " ## $PKG_NAME - no update available"
noupdate=$((noupdate + 1))
fi
else
PKGNAMEARRAYSKIP+=( ${PKG_NAME} )
skipped=$((skipped + 1))
fi
done
# update packages
if [ -z "$PACKAGE" ]; then
echo "Auto update possible ($autoupdate):"
fi
if [[ -n $RUN ]]; then
for j in ${!PKGARRAY[@]}; do
echo "--> replacing PKG_VERSION and PKG_SHA256 for ${PKGNAMEARRAY[$j]}"
sed -i "s/^PKG_VERSION=.*/PKG_VERSION=\"${VERARRAY[$j]}\"/" ${PKGARRAY[$j]}
sed -i "s/^PKG_SHA256=.*/PKG_SHA256=\"${SHAARRAY[$j]}\"/" ${PKGARRAY[$j]}
done
else
for j in ${!PKGARRAY[@]}; do
echo "--> update available for ${PKGNAMEARRAY[$j]} -> ${VERARRAY[$j]} (${SHAARRAY[$j]})"
done
fi
if [ -n "$PACKAGE" ]; then
exit 0
fi
echo "Manual update possible ($manual):"
for j in ${!PKGNAMEARRAYMAN[@]}; do
echo "--> manual update available for ${PKGNAMEARRAYMAN[$j]}"
done
echo "No update available ($noupdate):"
echo "Skipped packages ($skipped):"
for j in ${!PKGNAMEARRAYSKIP[@]}; do
echo "--> skipped check for ${PKGNAMEARRAYSKIP[$j]}"
done
}
try_update() {
update
}
update_all() {
RUN="1"
update
}
update_plugins_only() {
RUN="1"
PLUGINSONLY="1"
update
}
update_package() {
if [[ -z "$1" ]]; then
echo "ERROR: no PKG_NAME given"
usage
exit 1
fi
RUN="1"
PACKAGE=$1
update
}
if [[ "$#" -eq 0 ]]; then
echo "No parameter passed!"
usage
fi
while [[ "$#" -gt 0 ]]; do
case $1 in
-a) update_all ;;
-p) update_plugins_only ;;
-t) try_update ;;
-s) shift; update_package $1 ;;
-r) shift; reset_package $1 ;;
--help) usage ;;
*) echo "Unknown parameter passed: $1"; usage ;;
esac
shift || continue
done
exit 0