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 echo "openwrt-brcm-2.4-squashfs.trx"
33 local file; for file in /lib/upgrade/*.sh; do . $file; done
34 if platform_check_image "$1" >/dev/null 2>/dev/null; then
40 find_remote_checksum()
42 wget -qO- ${1%/*}/md5sums 2>/dev/null | \
43 sed -ne '/'$2'/ { s/ .*//p }'
48 set -- $(md5sum "$tempfile")
54 wget -qO- "${1%/*}/VERSION.txt" 2>/dev/null | \
55 sed -ne "s!.*$D4/$D2/$D2 $D2:$D2.*!\\1\\2\\3\\4\\5!p;t"
60 if [ -f /rom/etc/banner ]; then
61 sed -ne "s!.*$D4/$D2/$D2 $D2:$D2.*!\\1\\2\\3\\4\\5!p;t" \
64 date +"%Y%m%d%H%M" -r /bin/sh
70 [ -x /etc/init.d/$1 ] && {
71 echo -n "Stopping service $1 ... "
72 /etc/init.d/$1 stop >/dev/null 2>/dev/null
79 if [ ${1:-0} -gt 0 ]; then
80 echo -n "${2:-Waiting} "
81 for i in $(seq 1 $1); do
82 printf "%-2dseconds" $(($1-$i))
84 echo -en "\b\b\b\b\b\b\b\b\b"
95 while [ -n "$v1" -o -n "$v2" ]; do
96 if [ -z "${v2:0:4}" -o "${v1:0:4}" -gt "${v2:0:4}" ]; then
98 elif [ -z "${v1:0:4}" -o "${v1:0:4}" -lt "${v2:0:4}" ]; then
117 remote-update [-d] [-n] [-v] [-y] [-s <sleep seconds>] [-u <update url>]
120 -h Display this help message and exit.
121 -c Check for firmware update and exit.
122 -w Fetch image and exit, do not perform flash write.
125 -d Do not detach from terminal.
126 -n Do not backup configuration.
127 -v Skip verification of downloaded image.
128 -y Assume defaults for all questions.
131 Sleep given amount of seconds before invoking firmware burn.
132 If ommitted and '-y' is not used, 5 seconds are assumed.
135 Fetch firmware image from given url. A file "md5sums" is expected
136 in the same remote directory. If there is no such file, use -v to
137 suppress verification.
145 while getopts "s:u:cdnvwyh" flag; do
147 s) sleeptime="$OPTARG";;
148 u) updateurl="$OPTARG";;
160 local image_url="$updateurl"
161 local image_name="${image_url##*/}"
163 [ -z "$image_url" ] && {
164 local arch=$(find_architecture)
165 local image=$(find_image "$arch")
166 local repo=$(uci get freifunk.upgrade.repository 2>/dev/null)
169 echo "Can not determine the current architecture."
174 echo "No repository configured in 'freifunk.upgrade.repository'."
175 echo "Use the '-u' flag to specify an image location."
180 echo "No suitable image for the '$arch' architecture."
181 echo "Your platform is not supported."
185 echo "Architecture: $arch"
186 echo "Repository: $repo"
189 image_url="${repo%/}/$arch/$image"
193 if [ "$checkupdate" = 1 ]; then
194 local v1=$(find_local_version)
195 local v2=$(find_remote_version "$image_url")
197 [ -n "$v1" -a -n "$v2" ] && {
198 version_compare "$v1" "$v2"
200 echo "Update available! $v1 -> $v2"
202 echo "Local version $v1 is up to date"
205 echo "No remote time stamp found."
209 if [ "$noquestions" != 1 ]; then
210 echo -n "${NL}About to download $image_name. Continue? [y] "
217 echo -n "Downloading $image_name ... "
219 wget -qO $tempfile "$image_url" 2>/dev/null
220 [ $? == 0 ] && echo done || {
226 if [ "$noverify" != 1 ]; then
227 echo -n "Verifying $image_name ... "
229 local md5_remote=$(find_remote_checksum "$image_url" "$image_name")
230 local md5_local=$(find_local_checksum)
232 check_image "$tempfile"
235 if [ $image_ok = 0 -a -n "$md5_remote" -a -n "$md5_local" -a "$md5_remote" = "$md5_local" ]; then
238 if [ $image_ok != 0 ]; then
239 echo "unsupported image type"
241 echo "checksum mismatch! (local:${md5_local:-(none)} remote:${md5_remote:-(none)})"
245 if [ "$noquestions" != 1 ]; then
246 echo -n "${NL}Verification failed. Continue anyway? [n] "
261 if [ "$noflash" != 1 ]; then
262 if [ -f "$tempfile" ]; then
263 if [ "$noquestions" == 1 ]; then
264 do_wait ${sleeptime:-5} "${NL}About to start flashing, hit <Ctrl-C> to abort!${NL}${NL}Starting in"
266 if [ -z "$nobackup" ]; then
267 echo -n "${NL}Keep configuration files? [y] "
274 echo -n "${NL}About to start flashing!${NL}Hit <Enter> to continue or <Ctrl-C> to abort.${NL}"
278 for s in lucid collectd; do stop_service $s; done
280 if [ "$nodetach" != 1 ]; then
281 echo -n "Starting sysupgrade in background ... "
282 /bin/busybox start-stop-daemon -S -b -x /sbin/sysupgrade -- ${nobackup:+-n} "$tempfile"
285 echo "Executing sysupgrade ... "
286 exec /sbin/sysupgrade ${nobackup:+-n} "$tempfile"
289 echo "No upgrade image found!"
293 echo "Image saved in '$tempfile'"