637f68896e295c864722dac837ac07a508900547
[openwrt/svn-archive/archive.git] / root / bin / firstboot
1 #!/bin/sh
2 # $Id$
3
4 exec 2>/dev/null
5
6 [ -f "/tmp/.firstboot" ] && {
7 echo "firstboot is already running"
8 return
9 }
10 touch /tmp/.firstboot
11
12 jdev=$(mount | awk '/jffs2/ {print $3}')
13
14 if [ -z "$jdev" ]; then
15 mtd erase OpenWrt
16 mount -t jffs2 /dev/mtdblock/4 /jffs
17 cd /jffs
18 else
19 echo "firstboot has already been run"
20 echo "fixing symlinks instead"
21 cd $jdev
22 fi
23
24 mount /dev/mtdblock/2 /rom -o ro
25
26 {
27 cd /rom
28 find . -type d
29 cd -
30 } | xargs mkdir
31
32 for file in $(cd /rom; find * -type f; find * -type l;)
33 do {
34 ln -sf /rom/$file $file
35 } done
36
37 touch /tmp/resolv.conf
38 ln -s /tmp/resolv.conf /etc/resolv.conf
39
40 umount /rom
41 mount none /jffs/proc -t proc
42 pivot_root /jffs /jffs/rom
43 mount none /dev -t devfs
44 mount none /tmp -t ramfs
45 umount /rom/proc
46 umount /rom/tmp
47 umount /rom/dev