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 if grep -q '"vmlinux.bin.l7"' /proc/mtd; then
20 echo "openwrt-fonera-combined.img"
22 echo "openwrt-ubiquity-combined.img"
26 if grep -q '"kernel"' /proc/mtd; then
27 echo "openwrt-ar71xx-combined.img"
31 echo "openwrt-brcm-2.4-squashfs.trx"
38 local file; for file in /lib/upgrade/*.sh; do . $file; done
39 if platform_check_image "$1" >/dev/null 2>/dev/null; then
45 find_remote_checksum()
47 wget -qO- ${1%/*}/md5sums 2>/dev/null | \
48 sed -ne '/'$2'/ { s/ .*//p }'
53 set -- $(md5sum "$tempfile")
59 wget -qO- "${1%/*}/VERSION.txt" 2>/dev/null
64 find_remote_info "$1" | \
65 sed -ne "s!.*$D4/$D2/$D2 $D2:$D2.*!\\1\\2\\3\\4\\5!p;t"
70 if [ -f /rom/etc/banner ]; then
71 sed -ne "s!.*$D4/$D2/$D2 $D2:$D2.*!\\1\\2\\3\\4\\5!p;t" \
74 date +"%Y%m%d%H%M" -r /bin/sh
80 [ -x /etc/init.d/$1 ] && {
81 echo -n "Stopping service $1 ... "
82 /etc/init.d/$1 stop >/dev/null 2>/dev/null
89 if [ ${1:-0} -gt 0 ]; then
90 echo -n "${2:-Waiting} "
91 for i in $(seq 1 $1); do
92 printf "%-2dseconds" $(($1-$i))
94 echo -en "\b\b\b\b\b\b\b\b\b"
105 while [ -n "$v1" -o -n "$v2" ]; do
106 if [ -z "${v2:0:4}" -o "${v1:0:4}" -gt "${v2:0:4}" ]; then
108 elif [ -z "${v1:0:4}" -o "${v1:0:4}" -lt "${v2:0:4}" ]; then
125 remote-update [-u <update url>] -c
126 remote-update [-v] [-y] [-u <update url>] -w
127 remote-update [-d] [-n] [-v] [-y] [-s <sleep seconds>] [-u <update url>]
130 -h Display this help message and exit.
131 -c Check for firmware update and exit.
132 -w Fetch image and exit, do not perform flash write.
135 -d Do not detach from terminal.
136 -n Do not backup configuration.
137 -v Skip verification of downloaded image.
138 -y Assume defaults for all questions.
141 Sleep given amount of seconds before starting flash write.
142 If ommitted and '-y' is not used, 5 seconds are assumed.
145 Fetch firmware image from given url. A file "md5sums" is expected
146 in the same remote directory. If there is no such file, use -v to
147 suppress verification.
155 while getopts "s:u:cdnvwyh" flag; do
157 s) sleeptime="$OPTARG";;
158 u) updateurl="$OPTARG";;
170 local image_url="$updateurl"
171 local image_name="${image_url##*/}"
173 [ -z "$image_url" ] && {
174 local arch=$(find_architecture)
175 local image=$(find_image "$arch")
176 local repo=$(uci get freifunk.upgrade.repository 2>/dev/null)
177 repo=${repo:-$(uci get system.upgrade.repository 2>/dev/null)}
180 echo "Can not determine the current architecture."
185 echo "No repository configured in 'system.upgrade.repository'."
186 echo "Use the '-u' flag to specify an image location."
191 echo "No suitable image for the '$arch' architecture."
192 echo "Your platform is not supported."
196 echo "Architecture: $arch"
197 echo "Repository: $repo"
200 image_url="${repo%/}/$arch/$image"
204 if [ "$checkupdate" = 1 ]; then
205 local v1=$(find_local_version)
206 local v2=$(find_remote_version "$image_url")
208 [ -n "$v1" -a -n "$v2" ] && {
209 version_compare "$v1" "$v2"
211 echo "Update available!${NL}Local: $v1${NL}Remote: $v2${NL}--"
212 find_remote_info "$image_url"
215 echo "Local version $v1 is up to date"
219 echo "No remote time stamp found."
223 if [ "$noquestions" != 1 ]; then
224 echo -n "${NL}About to download $image_name. Continue? [y] "
231 echo -n "Downloading $image_name ... "
233 wget -qO $tempfile "$image_url" 2>/dev/null
234 [ $? == 0 ] && echo done || {
240 if [ "$noverify" != 1 ]; then
241 echo -n "Verifying $image_name ... "
243 local md5_remote=$(find_remote_checksum "$image_url" "$image_name")
244 local md5_local=$(find_local_checksum)
246 check_image "$tempfile"
249 if [ $image_ok = 0 -a -n "$md5_remote" -a -n "$md5_local" -a "$md5_remote" = "$md5_local" ]; then
252 if [ $image_ok != 0 ]; then
253 echo "unsupported image type"
255 echo "checksum mismatch! (local:${md5_local:-(none)} remote:${md5_remote:-(none)})"
259 if [ "$noquestions" != 1 ]; then
260 echo -n "${NL}Verification failed. Continue anyway? [n] "
275 if [ "$noflash" != 1 ]; then
276 if [ -f "$tempfile" ]; then
277 if [ "$noquestions" == 1 ]; then
278 do_wait ${sleeptime:-5} "${NL}About to start flashing, hit <Ctrl-C> to abort!${NL}${NL}Starting in"
280 if [ -z "$nobackup" ]; then
281 echo -n "${NL}Keep configuration files? [y] "
288 echo -n "${NL}About to start flashing!${NL}Hit <Enter> to continue or <Ctrl-C> to abort.${NL}"
292 for s in lucid collectd; do stop_service $s; done
294 if [ "$nodetach" != 1 ]; then
295 echo -n "Starting sysupgrade in background ... "
296 /bin/busybox start-stop-daemon -S -b -x /sbin/sysupgrade -- ${nobackup:+-n} "$tempfile"
299 echo "Executing sysupgrade ... "
300 exec /sbin/sysupgrade ${nobackup:+-n} "$tempfile"
303 echo "No upgrade image found!"
307 echo "Image saved in '$tempfile'"