Skip to content

Commit f60493a

Browse files
authored
attempt to fix mtk (#9434)
1 parent 0cbce22 commit f60493a

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

vm/mikrotik-routeros.sh

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,31 +237,62 @@ function default_settings() {
237237

238238
function get_mikrotik_version() {
239239
local mode="$1"
240+
local rss_url
240241
local tree_name
241242

243+
case "$mode" in
244+
s) rss_url="https://cdn.mikrotik.com/routeros/latest-stable.rss" ;;
245+
d) rss_url="https://cdn.mikrotik.com/routeros/latest-development.rss" ;;
246+
l) rss_url="https://cdn.mikrotik.com/routeros/latest-long-term.rss" ;;
247+
t) rss_url="https://cdn.mikrotik.com/routeros/latest-testing.rss" ;;
248+
*) return 0 ;;
249+
esac
250+
251+
local rss_content
252+
rss_content=$(curl -fsSL $rss_url 2>/dev/null)
253+
if [ -n "$rss_content" ]; then
254+
local version
255+
version=$(echo "$rss_content" | grep -oP '<title>RouterOS \K[0-9.]+(?= \[)' 2>/dev/null || echo "$rss_content" | sed -n 's/.*<title>RouterOS \([0-9.]\+\) \[.*/\1/p' 2>/dev/null)
256+
if [[ "$version" =~ ^[0-9]+\.[0-9]+ ]]; then
257+
echo "$version"
258+
return 0
259+
fi
260+
fi
261+
242262
case "$mode" in
243263
s) tree_name="Stable release tree" ;;
244264
d) tree_name="Development release tree" ;;
245265
l) tree_name="Long-term release tree" ;;
246266
t) tree_name="Testing release tree" ;;
247-
*) return 0 ;; # not an error, just no-op
248267
esac
249268

250269
local html
251-
html=$(curl -fsSL "https://mikrotik.com/download/changelogs") || return 0
252-
[ -z "$html" ] && return 0
253-
254-
local start_line
255-
start_line=$(echo "$html" | grep -n "$tree_name$" | cut -d: -f1 | head -n1)
256-
[[ "$start_line" =~ ^[0-9]+$ ]] || return 0
257-
258-
local line
259-
line=$( (echo "$html" | tail -n +"$start_line" | grep -m 1 "c-\(stable\|longTerm\|testing\|development\)-v") 2>/dev/null || true)
260-
261-
local version
262-
version=$(echo "$line" | sed -n 's/.*c-[^"]*-v\([0-9_.a-zA-Z-]\+\).*/\1/p' | tr '_' '.')
270+
html=$(curl -fsSL "https://mikrotik.com/download/changelogs" 2>/dev/null)
271+
if [ -n "$html" ]; then
272+
local start_line
273+
start_line=$(echo "$html" | grep -n "$tree_name" | cut -d: -f1 | head -n1)
274+
if [[ "$start_line" =~ ^[0-9]+$ ]]; then
275+
local line
276+
line=$(echo "$html" | tail -n +"$start_line" | grep -m 1 -E "c-(stable|longTerm|testing|development)-v|RouterOS [0-9]+\.[0-9]+" 2>/dev/null)
277+
278+
local version
279+
version=$(echo "$line" | sed -n 's/.*c-[^"]*-v\([0-9_.a-zA-Z-]\+\).*/\1/p' | tr '_' '.' 2>/dev/null)
280+
[ -z "$version" ] && version=$(echo "$line" | grep -oP 'RouterOS \K[0-9]+\.[0-9]+(\.[0-9]+)?' 2>/dev/null)
281+
282+
if [[ "$version" =~ ^[0-9]+\.[0-9]+ ]]; then
283+
echo "$version"
284+
return 0
285+
fi
286+
fi
287+
fi
263288

264-
[[ "$version" =~ ^[0-9]+\.[0-9]+.*$ ]] && echo "$version"
289+
for minor in $(seq 50 -1 15); do
290+
local test_version="7.${minor}"
291+
if curl -fsSL -I "https://download.mikrotik.com/routeros/${test_version}/chr-${test_version}.img.zip" 2>/dev/null | grep -q "200 OK"; then
292+
echo "$test_version"
293+
return 0
294+
fi
295+
done
265296

266297
return 0
267298
}
@@ -504,8 +535,8 @@ if [ -n "$MIK_VER" ]; then
504535
msg_ok "Latest stable version: ${CL}${BL}$MIK_VER${CL}."
505536
else
506537
msg_error "Could not get latest version"
507-
msg_ok "Defaulting to version 7.19"
508-
ver="7.19"
538+
msg_ok "Defaulting to version 7.20"
539+
MIK_VER="7.20"
509540
fi
510541

511542
URL=https://download.mikrotik.com/routeros/$MIK_VER/chr-$MIK_VER.img.zip

0 commit comments

Comments
 (0)