First check for arguments before even getting an IP address
[openwrt.git] / target / linux / adm5120 / router_le / base-files / sbin / wget2nand
1 #!/bin/sh
2 # wget2nand
3 # This script can be used to download a TGZ file from your build system which
4 # contains the files to be installed on the NAND flash on your RB1xx card.
5 # The one parameter is the URL of the TGZ file to be downloaded.
6 # Licence GPL V2
7 # Author david.goodenough@linkchoose.co.uk
8 # Based on cf2nand from RB532 support
9 . /etc/functions.sh
10
11 [ -d /tmp/wget2nand ] && {
12 echo "/tmp/wget2nand already exists"
13 exit 1
14 }
15
16 # need to find the wget server from the command line
17 url=$1
18 [ -z "$url" ] && {
19 echo "No URL specified for image TGZ"
20 echo "Usage : $0 URL"
21 exit 1
22 }
23
24
25 # first get an address for br-lan using udhcpc
26 killall udhcpc
27 /sbin/udhcpc -i br-lan
28
29 boot="$(find_mtd_part 'RouterBoard NAND Boot')"
30 main="$(find_mtd_part 'rootfs')"
31 [ -z "$boot" -o -z "$main" ] && {
32 echo "Cannot find NAND Flash partitions"
33 exit 1
34 }
35
36 echo "Erasing filesystem."
37 mtd erase Boot 2>/dev/null >/dev/null
38 mtd erase Main 2>/dev/null >/dev/null
39
40 echo "Mounting $main as new root and $boot as boot partition"
41
42 mkdir /tmp/wget2nand/
43 mkdir /tmp/wget2nand-boot
44 mount -t yaffs2 "$main" /tmp/wget2nand/
45 mount -t yaffs2 "$boot" /tmp/wget2nand-boot
46
47 echo "Erasing existing files."
48 rm -rf /tmp/wget2nand/*
49
50 echo "Copying filesystem..."
51 ( wget -O - $url/openwrt-adm5120-2.6-rootfs.tgz) | ( cd /tmp/wget2nand/; tar xvz )
52 # RouterBOOT is looking for a kernel named "kernel"
53 wget -O /tmp/wget2nand-boot/kernel $url/openwrt-adm5120-2.6-rb1xx-kernel
54
55 chmod +x /tmp/wget2nand-boot/kernel
56
57 # make sure everything is written before we unmount the partitions
58 echo "chmod ugo+x /" > /tmp/wget2nand/etc/uci-defaults/set_root_permission
59 sync
60 ls /tmp/wget2nand-boot/
61 ls /tmp/wget2nand/
62 # unmount the partitions and remove the directories into which they were mounted
63 umount /tmp/wget2nand-boot
64 umount /tmp/wget2nand
65 rmdir /tmp/wget2nand-boot
66 rmdir /tmp/wget2nand
67
68 # all done
69 echo "Image written, you can now reboot. Remember to change the boot source to Boot from Nand"
This page took 0.056477 seconds and 5 git commands to generate.