3 local tempfile=/tmp/remote-upgrade.img
4 local D2='\([0-9]\{2\}\)'
5 local D4='\([0-9]\{4\}\)'
11 local ifs="$IFS"; IFS="-"
12 set -- $(opkg list_installed kernel)
22 if grep -q '"vmlinux.bin.l7"' /proc/mtd; then
23 echo "openwrt-fonera-combined.img"
25 echo "openwrt-ubiquity-combined.img"
29 if grep -q '"kernel"' /proc/mtd; then
30 echo "openwrt-ar71xx-combined.img"
34 echo "openwrt-brcm-2.4-squashfs.trx"
41 local file; for file in /lib/upgrade/*.sh; do . $file; done
42 if platform_check_image "$1" >/dev/null 2>/dev/null; then
48 find_remote_checksum()
50 wget -qO- ${1%/*}/md5sums 2>/dev/null | \
51 sed -ne '/'$2'/ { s/ .*//p }'
56 set -- $(md5sum "$tempfile")
62 wget -qO- "${1%/*}/VERSION.txt" 2>/dev/null
67 find_remote_info "$1" | \
68 sed -ne "s!.*$D4/$D2/$D2 $D2:$D2.*!\\1\\2\\3\\4\\5!p;t"
73 if [ -f /rom/etc/banner ]; then
74 sed -ne "s!.*$D4/$D2/$D2 $D2:$D2.*!\\1\\2\\3\\4\\5!p;t" \
77 date +"%Y%m%d%H%M" -r /bin/sh
83 [ -x /etc/init.d/$1 ] && {
84 echo -n "Stopping service $1 ... "
85 /etc/init.d/$1 stop >/dev/null 2>/dev/null
92 if [ ${1:-0} -gt 0 ]; then
93 echo -n "${2:-Waiting} "
94 for i in $(seq 1 $1); do
95 printf "%-2dseconds" $(($1-$i))
97 echo -en "\b\b\b\b\b\b\b\b\b"
108 while [ -n "$v1" -o -n "$v2" ]; do
109 if [ -z "${v2:0:4}" -o "${v1:0:4}" -gt "${v2:0:4}" ]; then
111 elif [ -z "${v1:0:4}" -o "${v1:0:4}" -lt "${v2:0:4}" ]; then
128 remote-update [-u <update url>] -c
129 remote-update [-v] [-y] [-u <update url>] -w
130 remote-update [-d] [-n] [-v] [-y] [-s <sleep seconds>] [-u <update url>]
133 -h Display this help message and exit.
134 -c Check for firmware update and exit.
135 -w Fetch image and exit, do not perform flash write.
138 -d Do not detach from terminal.
139 -n Do not backup configuration.
140 -v Skip verification of downloaded image.
141 -y Assume defaults for all questions.
144 Sleep given amount of seconds before starting flash write.
145 If ommitted and '-y' is not used, 5 seconds are assumed.
148 Fetch firmware image from given url. A file "md5sums" is expected
149 in the same remote directory. If there is no such file, use -v to
150 suppress verification.
158 while getopts "s:u:cdnvwyh" flag; do
160 s) sleeptime="$OPTARG";;
161 u) updateurl="$OPTARG";;
173 local image_url="$updateurl"
174 local image_name="${image_url##*/}"
176 [ -z "$image_url" ] && {
177 local arch=$(find_architecture)
178 local image=$(find_image "$arch")
179 local repo=$(uci get freifunk.upgrade.repository 2>/dev/null)
180 repo=${repo:-$(uci get system.upgrade.repository 2>/dev/null)}
183 echo "Can not determine the current architecture."
188 echo "No repository configured in 'system.upgrade.repository'."
189 echo "Use the '-u' flag to specify an image location."
194 echo "No suitable image for the '$arch' architecture."
195 echo "Your platform is not supported."
199 echo "Architecture: $arch"
200 echo "Repository: $repo"
203 image_url="${repo%/}/$arch/$image"
207 if [ "$checkupdate" = 1 ]; then
208 local v1=$(find_local_version)
209 local v2=$(find_remote_version "$image_url")
211 [ -n "$v1" -a -n "$v2" ] && {
212 version_compare "$v1" "$v2"
214 echo "Update available!${NL}Local: $v1${NL}Remote: $v2${NL}--"
215 find_remote_info "$image_url"
218 echo "Local version $v1 is up to date"
222 echo "No remote time stamp found."
226 if [ "$noquestions" != 1 ]; then
227 echo -n "${NL}About to download $image_name. Continue? [y] "
234 echo -n "Downloading $image_name ... "
236 wget -qO $tempfile "$image_url" 2>/dev/null
237 [ $? == 0 ] && echo done || {
243 if [ "$noverify" != 1 ]; then
244 echo -n "Verifying $image_name ... "
246 local md5_remote=$(find_remote_checksum "$image_url" "$image_name")
247 local md5_local=$(find_local_checksum)
249 check_image "$tempfile"
252 if [ $image_ok = 0 -a -n "$md5_remote" -a -n "$md5_local" -a "$md5_remote" = "$md5_local" ]; then
255 if [ $image_ok != 0 ]; then
256 echo "unsupported image type"
258 echo "checksum mismatch! (local:${md5_local:-(none)} remote:${md5_remote:-(none)})"
262 if [ "$noquestions" != 1 ]; then
263 echo -n "${NL}Verification failed. Continue anyway? [n] "
278 if [ "$noflash" != 1 ]; then
279 if [ -f "$tempfile" ]; then
280 if [ "$noquestions" == 1 ]; then
281 do_wait ${sleeptime:-5} "${NL}About to start flashing, hit <Ctrl-C> to abort!${NL}${NL}Starting in"
283 if [ -z "$nobackup" ]; then
284 echo -n "${NL}Keep configuration files? [y] "
291 echo -n "${NL}About to start flashing!${NL}Hit <Enter> to continue or <Ctrl-C> to abort.${NL}"
295 for s in lucid collectd; do stop_service $s; done
297 if [ "$nodetach" != 1 ]; then
298 echo -n "Starting sysupgrade in background ... "
299 /bin/busybox start-stop-daemon -S -b -x /sbin/sysupgrade -- ${nobackup:+-n} "$tempfile"
302 echo "Executing sysupgrade ... "
303 exec /sbin/sysupgrade ${nobackup:+-n} "$tempfile"
306 echo "No upgrade image found!"
310 echo "Image saved in '$tempfile'"