3 local tempfile=/tmp/remote-upgrade.img
4 local D2='\([0-9]\{2\}\)'
5 local D4='\([0-9]\{4\}\)'
11 opkg list_installed 'base-files-*' | \
12 sed -ne 's/base-files-\([^ ]\+\).*/\1/p'
19 echo "openwrt-atheros-combined.img"
22 echo "openwrt-ar71xx-combined.img"
25 echo "openwrt-brcm-2.4-squashfs.trx"
32 local file; for file in /lib/upgrade/*.sh; do . $file; done
33 if platform_check_image "$1" >/dev/null 2>/dev/null; then
39 find_remote_checksum()
41 wget -qO- ${1%/*}/md5sums 2>/dev/null | \
42 sed -ne '/'$2'/ { s/ .*//p }'
47 set -- $(md5sum "$tempfile")
53 wget -qO- "${1%/*}/VERSION.txt" 2>/dev/null
58 find_remote_info "$1" | \
59 sed -ne "s!.*$D4/$D2/$D2 $D2:$D2.*!\\1\\2\\3\\4\\5!p;t"
64 if [ -f /rom/etc/banner ]; then
65 sed -ne "s!.*$D4/$D2/$D2 $D2:$D2.*!\\1\\2\\3\\4\\5!p;t" \
68 date +"%Y%m%d%H%M" -r /bin/sh
74 [ -x /etc/init.d/$1 ] && {
75 echo -n "Stopping service $1 ... "
76 /etc/init.d/$1 stop >/dev/null 2>/dev/null
83 if [ ${1:-0} -gt 0 ]; then
84 echo -n "${2:-Waiting} "
85 for i in $(seq 1 $1); do
86 printf "%-2dseconds" $(($1-$i))
88 echo -en "\b\b\b\b\b\b\b\b\b"
99 while [ -n "$v1" -o -n "$v2" ]; do
100 if [ -z "${v2:0:4}" -o "${v1:0:4}" -gt "${v2:0:4}" ]; then
102 elif [ -z "${v1:0:4}" -o "${v1:0:4}" -lt "${v2:0:4}" ]; then
119 remote-update [-u <update url>] -c
120 remote-update [-v] [-y] [-u <update url>] -w
121 remote-update [-d] [-n] [-v] [-y] [-s <sleep seconds>] [-u <update url>]
124 -h Display this help message and exit.
125 -c Check for firmware update and exit.
126 -w Fetch image and exit, do not perform flash write.
129 -d Do not detach from terminal.
130 -n Do not backup configuration.
131 -v Skip verification of downloaded image.
132 -y Assume defaults for all questions.
135 Sleep given amount of seconds before starting flash write.
136 If ommitted and '-y' is not used, 5 seconds are assumed.
139 Fetch firmware image from given url. A file "md5sums" is expected
140 in the same remote directory. If there is no such file, use -v to
141 suppress verification.
149 while getopts "s:u:cdnvwyh" flag; do
151 s) sleeptime="$OPTARG";;
152 u) updateurl="$OPTARG";;
164 local image_url="$updateurl"
165 local image_name="${image_url##*/}"
167 [ -z "$image_url" ] && {
168 local arch=$(find_architecture)
169 local image=$(find_image "$arch")
170 local repo=$(uci get freifunk.upgrade.repository 2>/dev/null)
171 repo=${repo:-$(uci get system.upgrade.repository 2>/dev/null)}
174 echo "Can not determine the current architecture."
179 echo "No repository configured in 'system.upgrade.repository'."
180 echo "Use the '-u' flag to specify an image location."
185 echo "No suitable image for the '$arch' architecture."
186 echo "Your platform is not supported."
190 echo "Architecture: $arch"
191 echo "Repository: $repo"
194 image_url="${repo%/}/$arch/$image"
198 if [ "$checkupdate" = 1 ]; then
199 local v1=$(find_local_version)
200 local v2=$(find_remote_version "$image_url")
202 [ -n "$v1" -a -n "$v2" ] && {
203 version_compare "$v1" "$v2"
205 echo "Update available!${NL}Local: $v1${NL}Remote: $v2${NL}--"
206 find_remote_info "$image_url"
209 echo "Local version $v1 is up to date"
213 echo "No remote time stamp found."
217 if [ "$noquestions" != 1 ]; then
218 echo -n "${NL}About to download $image_name. Continue? [y] "
225 echo -n "Downloading $image_name ... "
227 wget -qO $tempfile "$image_url" 2>/dev/null
228 [ $? == 0 ] && echo done || {
234 if [ "$noverify" != 1 ]; then
235 echo -n "Verifying $image_name ... "
237 local md5_remote=$(find_remote_checksum "$image_url" "$image_name")
238 local md5_local=$(find_local_checksum)
240 check_image "$tempfile"
243 if [ $image_ok = 0 -a -n "$md5_remote" -a -n "$md5_local" -a "$md5_remote" = "$md5_local" ]; then
246 if [ $image_ok != 0 ]; then
247 echo "unsupported image type"
249 echo "checksum mismatch! (local:${md5_local:-(none)} remote:${md5_remote:-(none)})"
253 if [ "$noquestions" != 1 ]; then
254 echo -n "${NL}Verification failed. Continue anyway? [n] "
269 if [ "$noflash" != 1 ]; then
270 if [ -f "$tempfile" ]; then
271 if [ "$noquestions" == 1 ]; then
272 do_wait ${sleeptime:-5} "${NL}About to start flashing, hit <Ctrl-C> to abort!${NL}${NL}Starting in"
274 if [ -z "$nobackup" ]; then
275 echo -n "${NL}Keep configuration files? [y] "
282 echo -n "${NL}About to start flashing!${NL}Hit <Enter> to continue or <Ctrl-C> to abort.${NL}"
286 for s in lucid collectd; do stop_service $s; done
288 if [ "$nodetach" != 1 ]; then
289 echo -n "Starting sysupgrade in background ... "
290 /bin/busybox start-stop-daemon -S -b -x /sbin/sysupgrade -- ${nobackup:+-n} "$tempfile"
293 echo "Executing sysupgrade ... "
294 exec /sbin/sysupgrade ${nobackup:+-n} "$tempfile"
297 echo "No upgrade image found!"
301 echo "Image saved in '$tempfile'"