various cosmetic fixes
[oweals/openwrt.git] / openwrt / target / default / target_skeleton / bin / firstboot
1 #!/bin/sh
2 # $Id$
3
4
5 [ -f "/tmp/.firstboot" ] && {
6         echo "firstboot is already running"
7         return
8 }
9 touch /tmp/.firstboot
10
11 jdev=$(mount | awk '/jffs2/ {print $3}')
12
13 if [ -z "$jdev" ]; then
14         echo -n "Creating jffs2 partition... "
15         mtd erase OpenWrt >&- 
16         mount -t jffs2 /dev/mtdblock/4 /jffs
17         echo "done"
18         cd /jffs
19 else
20         echo "firstboot has already been run"
21         echo "jffs2 partition is mounted, only resetting files"
22         cd $jdev
23 fi
24
25 exec 2>/dev/null
26
27 mount /dev/mtdblock/2 /rom -o ro
28
29 echo -n "creating directories... "
30 {
31         cd /rom
32         find . -type d
33         cd -
34 } | xargs mkdir
35 echo "done"
36
37 echo -n "setting up symlinks... "
38 for file in $(cd /rom; find *  -type f; find *  -type l;)
39 do {
40   [ "${file%/*}" = "usr/lib/ipkg/info" ] && {
41     cp -f /rom/$file $file
42   } || {
43     ln -sf /rom/$file $file
44   }
45 } done
46 echo "done"
47
48 touch /tmp/resolv.conf
49 ln -s /tmp/resolv.conf /etc/resolv.conf
50
51 umount /rom
52 mount none /jffs/proc -t proc
53 pivot_root /jffs /jffs/rom
54 mount none /dev  -t devfs
55 mount none /tmp  -t ramfs
56 umount /rom/proc
57 umount /rom/tmp
58 umount /rom/dev