]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/altboot/files/altboot-menu/Advanced/70-install-tgz
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 / 70-install-tgz
1 #!/bin/sh
2
3 M_TITLE="Install RootFS from tar.gz"
4
5 # die() {
6 #       echo "ERROR: $1" >/dev/tty0
7 #       exec $SH_SHELL </dev/tty0 >/dev/tty0 2>&1
8 # }
9
10 run_module(){
11         test -e /etc/altboot.func && . /etc/altboot.func || die "ERROR: /etc/altboot.func not found. Check your installation!"  
12         
13         # Mount /proc, etc
14         init_rootfs
15         
16         # Mount
17         mount_sd        
18         mount_cf
19         mount_home
20         
21         for source in /home /media/card /media/cf
22         do
23                 #echo "source: [$source]"
24                 rootfs_files="`ls -1 $source | grep "rootfs.tar.gz"`"
25                 
26                 #echo "rootfs_file: [$rootfs_files]"
27                 if test "`echo "$rootfs_files" | wc -l | tr -d " "`" -gt 1
28                 then
29                         echo "Multiple rootfs files not supported, yet"
30                 else            
31                         if test -n "$rootfs_files"
32                         then
33                                 rootfs_source="$source/$rootfs_files"
34                                 echo "Using [$rootfs_source]"                           
35                                 break
36                         fi
37                 fi                              
38         done
39         
40         test -z "$rootfs_source" && die "No rootfs.tar.gz found" 
41         
42         echo -e "\nPlease choose the target of this installation:\n"
43
44         echo -e "\t [1] SD / MMC"
45         echo -e "\t [2] Compact Flash"
46         
47         echo ""
48         while true
49         do
50                 echo -n "Your target: "
51                 read junk
52                 
53                 case "$junk" in
54                 1)      if (mount | grep -q "/media/card ")
55                         then
56                                 rootfs_target="/media/card"; break 
57                         else
58                                 echo -e "\nInstallation target [/media/card] not mounted\n"
59                         fi ;;
60                 2)      if (mount | grep -q "/media/cf ")
61                         then
62                                 rootfs_target="/media/cf"; break 
63                         else
64                                 echo -e "\nInstallation target [/media/cf] not mounted\n"
65                         fi ;;
66                 esac
67         done
68
69         echo -e "\nPlease choose the type of this installation:\n"
70
71         echo -e "\t [1] Imagefile (loopfile)"
72         echo -e "\t [2] Direct Install"
73         
74         echo ""
75         while true
76         do
77                 echo -n "Install type: "
78                 read junk
79                 
80                 case "$junk" in
81                 1)      if test -x /sbin/mkfs.ext2
82                         then
83                                 rootfs_type="image"
84                                  break 
85                         else
86                                 echo -e "\nNOTE: mkfs.ext2 (from e2fsprogs-mke2fs) not found, loop-images not supported\n"
87                         fi ;;                   
88                 2)      rootfs_type="direct" ; break ;;
89                 esac
90         done
91         
92         case "$rootfs_type" in
93         image)  install_rootfs_image "$rootfs_target";;
94         direct) install_rootfs_direct "$rootfs_target";;
95         esac
96 }
97
98 clear_directories(){
99         test "$1" = "/" -o "$1" = "/ " && die "clear_directories(): You don't want to do that."
100         
101         ! test -d "$1" && die "clear_directories(): [$1] not found."
102         
103         for d in bin dev media proc sys usr boot etc lib mnt sbin tmp var
104         do
105                 if test -d "$1/$d"
106                 then
107                         echo "Removing [$1/$d]..."
108                         rm -rf "$1/$d"
109                 fi
110         done
111
112 }
113
114
115 install_rootfs_direct(){
116         
117         mount | grep -q "$1 " || die "Installation target [$1] not mounted"
118         
119         echo -e "Do you want to remove existing directories from [$1]\n before installing the new rootfs?"
120         echo ""
121         
122         while true
123         do
124                 echo -n "Remove old directories? [Y|n] "
125                 read junk </dev/tty0 >/dev/tty0 2>&1            
126                                 
127                 case "$junk" in
128                 Y|y|"") clear_directories "$1"; break ;;
129                 esac
130         done            
131
132         echo "Please press <ENTER> to begin the installation"
133         read junk </dev/tty0 >/dev/tty0 2>&1
134                 
135         test -d "$1" || die "Directory [$1] not found"
136         
137         echo -n "Installing rootfs, please wait..."
138         tar -xzf "$rootfs_source" -C "$1" >/dev/null 2>&1 && echo ok || die "tar -xzf \"$rootfs_source\" -C \"$1\" failed!"
139         
140         echo -n "Syncing drives..."
141         sync
142         echo "done"
143         
144 #       umount "$1"
145         
146         echo "Press <ENTER> to bring up the altboot menu"
147         read junk </dev/tty0 >/dev/tty0 2>&1
148         exec /sbin/init.altboot -force
149         
150 }
151
152 install_rootfs_image(){
153
154         mount | grep -q "$1 " || die "Installation target [$1] not mounted"
155
156         echo ""
157         echo "Please enter a name for the image file."
158         echo "Do not use the <space> character"
159         echo ""
160                 
161         
162         while true
163         do
164                 echo -n "Image name: "
165                 read junk
166                 
167                 if test -n "$junk"
168                 then                                    
169                         if test -e "$1/boot-images/${junk}-rootfs.bin"
170                         then                    
171                                 echo -e "\nFile [$1/boot-images/${junk}-rootfs.bin] already exists."
172                                 
173                                 while true 
174                                 do
175                                         echo -n "Overwrite? [y|N] "
176                                         read junk2
177                                         
178                                         case "$junk2" in
179                                         Y|y)    break;;
180                                         n|N|"") install_rootfs_image "$1"
181                                                 exit 0;;
182                                         esac
183                                 done
184                                 rootfs_image_name="${junk}-rootfs.bin"
185                                 break                                                                                                                   
186                         else                                            
187                                  echo -n "Use [$junk] as name? [Y|n] "
188                                  read junk2
189
190                                  case "$junk2"  in
191                                  "Y"|"y"|"")    rootfs_image_name="${junk}-rootfs.bin"
192                                                  break ;;
193                                  *)             echo "err ]$junk]";;
194                                  esac
195                         fi
196                 fi
197         done
198         
199         echo ""
200         echo "Please enter the image size in MegaBytes"
201         echo "Must be at least 30Mb"
202         echo ""
203         
204         while true
205         do
206                 echo -n "Image size: "          
207                 read junk
208                                 
209                 junk="`echo "$junk" | sed "s/[a-zA-Z]//g"`"
210                 
211                 if test -n "$junk"
212                 then
213                         if test "$junk" -gt 29
214                         then
215                                 echo -n "Is [${junk}Mb] correct? [Y|n] "
216                                 read junk2
217         
218                                 case "$junk2"  in
219                                         Y|y|"") rootfs_image_size="$junk"
220                                                 break ;;
221                                 esac                                            
222                 
223                         else
224                                 echo "Image size of [${junk}Mb] is too small!"
225                         fi
226                 fi
227         done
228         
229         test -z "$rootfs_image_name" -o -z "$rootfs_image_size" && die "DEBUG: Empty VAR in install_rootfs_image()" 
230         
231         echo ""
232         echo "Creating [$rootfs_image_name] (${rootfs_image_size}Mb) on [$1]"
233         echo "Please wait..."
234         mkdir -p "$1/boot-images"
235                 
236         dd if=/dev/zero of="$1/boot-images/$rootfs_image_name" bs=1024k count=$rootfs_image_size >/dev/null
237         
238         echo -n "Creating an ext2 filesystem on $rootfs_image_name..."
239         losetup /dev/loop0 "$1/boot-images/$rootfs_image_name" || die "losetup /dev/loop0 \"$1/boot-images/$rootfs_image_name\" failed!"
240         mkfs.ext2 -m0 /dev/loop0 >/dev/null 2>&1 && echo done || die "mkfs.ext2 -m0 /dev/loop0 failed!"
241         
242         echo -n "Mounting loopfile..."
243         mkdir -p /media/image
244         mount /dev/loop0 /media/image && echo ok || die "mount /dev/loop0 /media/image failed!"
245         
246         echo -n "Installing rootfs, please wait..."
247         tar -xzf "$rootfs_source" -C "/media/image" >/dev/null 2>&1 && echo ok || die "tar -xzf \"$rootfs_source\" -C \"$1\" failed!"
248         
249         echo -n "Syncing drives..."
250         sync
251         echo "done"
252         
253         umount "/media/image" && losetup -d /dev/loop0
254         
255         echo "Press <ENTER> to bring up the altboot menu"
256         read junk </dev/tty0 >/dev/tty0 2>&1
257         exec /sbin/init.altboot -force
258         
259 }
260
261
262
263 #run_module
264
265 case "$1" in
266 title)  echo "$M_TITLE";;
267 run)    run_module "$2";;
268 esac