]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/altboot/files/altboot-menu/Advanced/40-bootNFS
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / altboot / files / altboot-menu / Advanced / 40-bootNFS
1 # !/bin/sh
2 #
3 # Copyright Matthias Hentges (c) 2005
4 #
5 # License: GPL (see http://www.gnu.org/licenses/gpl.txt for a copy of the GPL)
6
7 M_TITLE="Boot from NFS"
8
9 die() {
10         echo "ERROR: $1" >/dev/tty0
11         exec $SH_SHELL </dev/tty0 >/dev/tty0 2>&1
12 }
13
14 # This function is activated by init.altboot by calling this script with the "run" option
15 run_module() {
16
17         test -e /etc/altboot.func && . /etc/altboot.func || die "ERROR: /etc/altboot.func not found. Check your installation!"
18
19         # Mount /proc, etc
20         init_rootfs
21
22         # Needed for NFS
23         /etc/init.d/portmap start >/dev/tty1 2>&1 || die "/etc/init.d/portmap start failed!"
24         
25         # For some reason NFS mounts hang if /e/i/networking is not run.
26         # For the time beeing I'm too lazy to investigate ;)
27         /etc/init.d/networking start || die "/etc/init.d/networking start failed!"
28         
29         sleep 2
30         
31         # After the PCMCIA service is started, an inserted WLAN card should automatically
32         # activate itself.
33         /etc/init.d/pcmcia start >/dev/null 2>&1 || die "/etc/init.d/pcmcia/start failed!"
34
35         nfs_host="`cat /etc/fstab | grep -v ^# | grep nfs | awk '{print $1}'|sed -n "s/\(.*\)\:\(.*\)/\1/p" `"
36         nfs_mounts="`cat /etc/fstab | grep -v ^# | grep nfs | awk '{print $1}'`"
37         nfs_mountpoints="`cat /etc/fstab | grep -v ^# | grep nfs | awk '{print $2}'`"   
38         
39         if test -z "$nfs_host"
40         then
41                 die "${C_RED}No configured NFS drives found in /etc/fstab$C_RESET"
42                 
43         fi
44         
45         # WLAN with DHCP needs some time to get a lease, set up the routing, etc.       
46         echo -n "Waiting for WLAN"
47         cnt=0
48         while true
49         do
50                 if (ping -c 1 $nfs_host) >/dev/null 2>&1
51                 then
52                         echo " found"
53                         break
54                 else
55                         if test "$cnt" = 30 -o "$cnt" = 60
56                         then
57                                 echo ""
58                                 echo "WARNING: WLAN didn't activate in $cnt seconds!"
59                                 
60                                 if test "$cnt" = 30
61                                 then
62                                         echo "Restarting udhcpc"
63                                         killall udhcpc
64                                         udhcpc -i wlan0 -H `cat /etc/hostname` >/dev/null 2>&1
65                                 else
66                                         die "Failed to activate WLAN!"
67                                         break                   
68                                 fi
69                         else
70                                 echo -n "."
71                                 let cnt=$cnt+1
72                         fi
73                 fi
74                 sleep 1
75         done                            
76         
77         if test "` echo "$nfs_mountpoints" |wc -l | tr -d " "`" -gt 1
78         then
79                 echo -e "Please select your NFS root:\n"
80
81                 cnt=1
82                 for nfs_mount in $nfs_mountpoints
83                 do
84                         echo -e "\t[$cnt] $nfs_mount"
85                         let cnt=$cnt+1
86                 done
87                 
88                 echo ""
89                 
90                 while test -z "$selection"
91                 do
92                         stty echo
93                         echo -n "Boot NFS root: "
94                         read junk < /dev/tty1
95                         
96                         cnt=1
97                         for nfs_mount in $nfs_mounts
98                         do
99                                 if test "$junk" = "$cnt"
100                                 then
101                                         selection="$nfs_mount"
102                                 fi
103                                 let cnt=$cnt+1
104                         done                    
105                         
106                 done
107         else
108                 test -z "$nfs_mounts" && die "No NFS mounts configured in /etc/fstab!"  
109                 selection="$nfs_mounts"
110         fi
111         
112         mkdir -p /media/nfsroot || die "mkdir -p /media/nfsroot failed!"
113         
114         echo -n "Mounting NFS root..."
115         mount -t nfs "$selection" /media/nfsroot && echo ok || die "mount -t nfs "$selection" /media/nfsroot failed!"
116         
117         # Use configured resolv.conf in the pivoted rootfs
118         echo -n "Copying resolv.conf..."
119         #cp /etc/resolv.conf /media/nfsroot/etc && echo ok || echo "FAILED"
120         
121         check_target "/media/nfsroot"
122         
123 }       
124
125 case "$1" in
126 title)  echo "$M_TITLE";;
127 run)    run_module "$2";;
128 esac
129