Skip to content

Instantly share code, notes, and snippets.

@jow-
Last active December 13, 2023 10:37
Show Gist options
  • Save jow-/7e2e174e3dac23083c3d1e9a59ce87c9 to your computer and use it in GitHub Desktop.
Save jow-/7e2e174e3dac23083c3d1e9a59ce87c9 to your computer and use it in GitHub Desktop.
Create download index page
#!/usr/bin/env bash
set -e
get_all_tags() {
curl -s "https://git.openwrt.org/?p=openwrt/openwrt.git;a=tags" | \
sed -rne 's#^.+<a class="list name" href="[^"]+;h=([[:xdigit:]]+)">v([0-9.rc-]+)</a>.+$#\2-\1#p' | \
sort --version-sort
}
get_release_date() {
curl -s "https://git.openwrt.org/?p=openwrt/openwrt.git;a=tag;h=refs/tags/v$1" | \
sed -rne 's#^.+<span class="datetime">(\w{3}, [0-9]{1,2} \w{3} [0-9]{4})\b.+$#\1#p'
}
TAG_LIST="$(get_all_tags)"
HISTORIC_VERSIONS="0.9 7.06 7.07 7.09 8.09 8.09.1 8.09.2 10.03 10.03.1 12.09 14.07 15.05 15.05.1"
upcoming_base=
upcoming_version=
upcoming_date=
stable_base=
stable_version=
stable_date=
oldstable_base=
oldstable_version=
oldstable_date=
archive_list=
for version in $TAG_LIST; do
base=$(echo "$version" | sed -re 's#^([0-9]+)\.([0-9]+)\..+$#\1.\2#')
# rc version
if [ "$version" != "${version%-rc*}" ]; then
if [ "$base" != "$stable_base" ]; then
upcoming_base=$base
upcoming_version=${version%-*}
fi
continue
fi
# releases
if [ "$base" != "$stable_base" ]; then
oldstable_version=$stable_version
oldstable_base=$stable_base
fi
stable_version=${version%-*}
stable_base=$base
done
# some sanity checks
[ -n "$TAG_LIST" ] || { echo "Failed to obtain list of tags" >&2; exit 1; }
[ -z "$oldstable_version" ] || oldstable_date=$(get_release_date "$oldstable_version")
[ -z "$upcoming_version" ] || upcoming_date=$(get_release_date "$upcoming_version")
[ -z "$stable_version" ] || stable_date=$(get_release_date "$stable_version")
[ -z "$oldstable_version" -o -n "$oldstable_date" ] || { echo "Failed to obtain oldstable release date" >&2; exit 1; }
[ -z "$upcoming_version" -o -n "$upcoming_date" ] || { echo "Failed to obtain upcoming release date" >&2; exit 1; }
[ -z "$stable_version" -o -n "$stable_date" ] || { echo "Failed to obtain stable release date" >&2; exit 1; }
[ -n "$stable_version" ] || { echo "No stable version found" >&2; exit 1; }
for tuple in $HISTORIC_VERSIONS $TAG_LIST; do
version=${tuple%-*}
case "$version" in
*-rc*|"${stable_version}"|"${oldstable_version}")
continue
;;
0.9)
name="Whiterussian $version"
link="/whiterussian/$version/"
;;
[78].*)
name="Kamikaze $version"
link="/kamikaze/$version/"
;;
10.*)
name="Backfire $version"
link="/backfire/$version/"
;;
12.*)
name="Attitude Adjustment $version"
link="/attitude_adjustment/$version/"
;;
14.*)
name="Barrier Breaker $version"
link="/barrier_breaker/$version/"
;;
15.*)
name="Chaos Calmer $version"
link="/chaos_calmer/$version/"
;;
17.*)
name="LEDE $version"
link="/releases/$version/targets/"
;;
*)
name="OpenWrt $version"
link="/releases/$version/targets/"
;;
esac
archive_list=$'\t\t<li><a href="//archive.openwrt.org'"$link"'">'"$name"'</a></li>'$'\n'"$archive_list"
done
cat <<HEADER
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title>OpenWrt Downloads</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height: 100%;
}
body {
color: #333;
padding-top: 2em;
font-family: Helvetica,Arial,sans-serif;
width: 90%;
min-width: 700px;
max-width: 1100px;
margin: auto;
font-size: 120%;
background-color: #ddd;
}
h1 {
font-size: 120%;
line-height: 1em;
}
h2 {
font-size: 100%;
line-height: 1em;
}
h3 {
font-size: 90%;
line-height: 1em;
}
p, li {
font-size: 14px;
}
a:link, a:visited {
color: #337ab7;
font-weight: bold;
text-decoration: none;
}
a:hover, a:active, a:focus {
color: #23527c;
text-decoration: underline;
}
footer {
font-size: 80%;
text-align: right;
margin: 1em 0;
}
</style>
</head>
<body>
<h1>OpenWrt Downloads</h1>
<div>
<p>
Welcome to the OpenWrt download area. Follow the links below to find the
appropriate directory.
</p>
<hr>
HEADER
if [ -n "$stable_version" ]; then
cat <<STABLE
<h2>Stable Release</h2>
<p>
The current stable OpenWrt ${stable_base} release is linked below. It is adviced
to use the latest available release if possible.
</p>
<ul>
<li>
<strong><a href="releases/${stable_version}/targets/">OpenWrt ${stable_version}</a></strong><br>
<small>Released: ${stable_date}</small><br /><br />
</li>
</ul>
<hr>
STABLE
fi
if [ -n "$upcoming_version" ]; then
cat <<UPCOMING
<h3>Upcoming Stable Release</h3>
<p>
OpenWrt ${upcoming_base} will be the successor of the ${stable_base} series. It is currently in the
release candidate phase and will replace the current stable release once finalized.
</p>
<ul>
<li>
<strong><a href="releases/${upcoming_version}/targets/">OpenWrt ${upcoming_version}</a></strong><br>
<small>Released: ${upcoming_date}</small><br/><br/>
</li>
</ul>
<hr>
UPCOMING
# NB: show either upcoming or oldstable, this is done to mimic historic behavior
elif [ -n "$oldstable_version" ]; then
cat <<OLDSTABLE
<h3>Old Stable Release</h3>
<p>
The OpenWrt ${oldstable_base} release is considered outdated but will still receive
limited security and bug fixes for some time.
</p>
<ul>
<li>
<strong><a href="releases/${oldstable_version}/targets/">OpenWrt ${oldstable_version}</a></strong><br>
<small>Released: ${oldstable_date}</small><br /><br />
</li>
</ul>
<hr>
OLDSTABLE
fi
cat <<FOOTER
<h3>Development Snapshots</h3>
<p>
Development snapshots are automatic unattended daily builds of the current
OpenWrt development master branch. Bear in mind that these images are generally
not tested, use them at your own risk.
</p>
<ul>
<li><a href="snapshots/targets/">Snapshot download</a></li>
</ul>
<hr>
<h3>Release Archive</h3>
<p>
The releases linked below are mostly for historic interest - they're generally
out of date and no longer maintained.
</p>
<ul>
$archive_list
</ul>
</div>
</body></html>
FOOTER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment