]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/altboot/files/altboot-menu/Advanced/80-copyrootfs
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 / 80-copyrootfs
1 # !/bin/sh
2 M_TITLE="Copy rootfs to SD/CF"
3
4 # Unfinished script.
5 exit 0
6
7 die() {
8         echo "ERROR: $1" >/dev/tty0
9         exec $SH_SHELL </dev/tty0 >/dev/tty0 2>&1
10 }
11
12 ask_target() {
13         available_disks="`mount | grep "/media" | grep -v ram | awk '{print $3}'`"
14         
15         if test -z "$available_disks" 
16         then
17                 die "No mounted targets found!"
18         fi
19         
20         cnt=1
21         for d in $available_disks
22         do
23                 echo -e "\t[$cnt] $d"
24                 let cnt=$cnt+1
25         done
26
27         while test -z "$ROOTFS_TARGET"
28         do      
29                 echo -n "Target: "
30                 read junk </dev/tty1
31                 
32                 x=1
33                 for d in $available_disks
34                 do                      
35                         if test "$junk" = "$x"
36                         then
37                                 ROOTFS_TARGET="$d"                              
38                                 break
39                         fi
40                         let x=$x+1
41                 done
42                 
43                 
44         done    
45         
46         ROOTFS_TARGET_DEV="`mount | grep "$ROOTFS_TARGET " | awk '{print $1}'`"
47         ROOTFS_TARGET_FS="`mount | grep "$ROOTFS_TARGET " | awk '{print $5}'`"
48         
49         echo "Using [$ROOTFS_TARGET] on [$ROOTFS_TARGET_DEV] with [$ROOTFS_TARGET_FS] filesystem"                               
50 }
51
52 ask_format() {
53         if test "$ROOTFS_TARGET_FS" != ext2
54         then
55                 echo -e "\nYou are not using the ext2 filesystem on your target ($ROOTFS_TARGET_FS)$.\nYou now have two choices:"
56                 echo -e "\t[1] Reformat to ext2"
57                 echo -e "\t[2] Use an image-file ontop of the existing filesystem"
58                 
59                 while true
60                 do
61                         echo -n "Your choice: "
62                         read junk </dev/tty1
63                         
64                         case "$junk" in
65                         1)      ROOTFS_TARGET_TYPE="ext2"
66                                 break ;;
67                         2)      ROOTFS_TARGET_TYPE="image"
68                                 break ;;
69                         esac
70                 done                    
71                         
72                 echo "Mode: [$ROOTFS_TARGET_TYPE]"
73         else
74                 echo -e "\nYou are using the ext2 filesystem on your target.\nYou now have two choices:"
75                 echo -e "\t[1] Install to the target directly"
76                 echo -e "\t[2] Use an image-file ontop of the existing filesystem\n"
77                 
78                 while true
79                 do
80                         echo -n "Your choice: "
81                         read junk </dev/tty1
82                         
83                         case "$junk" in
84                         1)      ROOTFS_TARGET_TYPE="direct"
85                                 break ;;
86                         2)      ROOTFS_TARGET_TYPE="image"
87                                 break ;;
88                         esac
89                 done                    
90                         
91                 echo "Mode: [$ROOTFS_TARGET_TYPE]"
92                 
93         fi
94 }
95
96 ask_confirm() {
97         echo -e "\nYour choices are:"
98         echo -e "\tTarget:\t$ROOTFS_TARGET_DEV (currently mounted as $ROOTFS_TARGET)"
99         case "$ROOTFS_TARGET_TYPE" in
100                 direct) echo -e "\tType:\t${C_RED}direct install, reformat if required${C_RESET}";;
101                 image) echo -e "\tType:\tinstall into image-file";;
102         esac
103         
104         while true
105         do
106                 echo -n "Continue? [y|n] "
107                 read junk </dev/tty1
108                 
109                 case "$junk" in
110                 y)      break ;;
111                 n)      exit 1
112                 esac
113         done
114 }
115
116 direct_install() {
117
118         #format_target
119                 
120         echo -n "Creating temporary directory..."
121         mkdir -p /media/temp && echo ok || die "mkdir -p /media/temp failed!"
122         
123         echo -n "Mounting [$ROOTFS_TARGET_DEV] as /media/temp..."
124         mount "$ROOTFS_TARGET_DEV" /media/temp && echo "ok" || die "mount "$ROOTFS_TARGET_DEV" /media/temp FAILED"
125         
126         copy_files
127 }
128
129 format_target() {
130         echo -e "\n\nI'm about to format your target ($ROOTFS_TARGET_DEV) to the ext2 filesystem\n"
131         echo -e "${C_RED}YOU WILL LOSE ALL DATA ON YOUR TARGET IF YOU CONTINUE${C_RESET}\n"
132         
133         while true
134         do
135                 echo -n "Continue? [y|n] "
136                 read junk </dev/tty1
137                 
138                 case "$junk" in
139                 y)      break ;;
140                 n)      die "User aborted mkfs"
141                         break ;;
142                 esac
143         done
144         
145         echo -n "Umounting $ROOTFS_TARGET_DEV..."
146         umount "$ROOTFS_TARGET_DEV" && echo "ok" || die "umount $ROOTFS_TARGET_DEV failed!"
147         
148         
149         echo "Formatting..."
150         /sbin/mkfs.ext2 -m0 "$ROOTFS_TARGET_DEV" && echo -e "\nmkfs.ext2 finished" || die "\nmkfs.ext2 FAILED"
151  }
152
153 image_install() {
154         flash_size="` df -h | grep "/"$| awk '{print $3}'| sed s/M//`"
155         
156         echo -e "\nHow many MB do you want to configure for the image file?"
157         echo -e "It is generally a good idea to use 2.5x the used flash size ($flash_size)\n"
158         
159         while test -z "$ROOTFS_IMAGE_SIZE"
160         do
161                 echo -n "Size in MegaBytes: "
162                 read junk
163                 
164                 # test fails if $junk isn't a number
165                 if test "$junk" -gt 0 >/dev/null 2>&1
166                 then
167                         echo -n "Use [$junk]MB? [y|n] "
168                         read junk2
169                         if test "$junk2" = y
170                         then
171                                 ROOTFS_IMAGE_SIZE="$junk"
172                         fi
173                 fi
174         done
175         
176         echo -e "\nPlease enter a name for the image file."
177         echo "The name must _not_ contain whitespaces or the '-' sign."
178         
179         while test -z "$ROOTFS_IMAGE_NAME"
180         do
181                 echo -n "File name: "
182                 read junk
183                 
184                 if ! test -z "$junk"
185                 then
186                         echo -n "Use [$junk] as image name? [y|n] "
187                         read junk2
188                         
189                         if test "$junk2" = y
190                         then
191                                 ROOTFS_IMAGE_NAME="$junk"                       
192                         fi
193                 fi
194         done                    
195         
196         echo -e "\nDo you want to format [$ROOTFS_TARGET_DEV] to the ext2 filesystem?"
197         
198         while true
199         do
200                 echo -n "Format to ext2? [y|n] "
201                 read junk
202                 case "$junk" in
203                 y)      format_target
204                         break ;;
205                 n)      break ;;
206                 esac
207         done
208         
209         /etc/init.d/devices start
210         
211         echo -en "\nCreating image file [$ROOTFS_TARGET/$IMAGE_PATH/$ROOTFS_IMAGE_NAME-rootfs.bin] (${ROOTFS_IMAGE_SIZE}MB)..."
212         mkdir -p "$ROOTFS_TARGET/$IMAGE_PATH"
213         
214         dd if=/dev/zero of="$ROOTFS_TARGET/$IMAGE_PATH/$ROOTFS_IMAGE_NAME-rootfs.bin" bs=1024k count=$ROOTFS_IMAGE_SIZE  >/dev/null 2>&1 && echo ok || die "FAILED"
215         losetup /dev/loop1 "$ROOTFS_TARGET/$IMAGE_PATH/$ROOTFS_IMAGE_NAME-rootfs.bin"
216         
217         echo -n "Creating filesystem..."
218         mkfs.ext2 -m0 /dev/loop1 >/dev/null 2>&1 && echo ok || die FAILED
219         
220         mkdir -p /media/temp
221         mount /dev/loop1 /media/temp || die "mount /dev/loop1 /media/temo FAILED!"
222         
223         copy_files
224                         
225 }
226
227 copy_files() {
228         echo -e "\nCopying files..."
229         
230         exclude_list="tmp sys proc var dev media root"
231         mkdir_list="var proc sys dev media/card media/cf /media/hdd"
232                 
233         if (cat /etc/fstab | grep -q "/home")
234         then
235                 echo "Note: /home appears to be mounted on a different flash partition: not copying /home"
236                 exclude_list="$exclude_list home"
237                 mkdir_list="$mkdir_list home/root"
238                 
239         fi
240         
241
242         
243         source_dirs="`ls -1 /`"
244         
245         echo -n "Excluding ["
246         for d in $exclude_list
247         do
248                 echo -n "$d "
249                 source_dirs="`echo "$source_dirs" | grep -v "$d"`"
250         done
251         echo "] from copy"
252                                 
253         
254         cd /
255         for dir in $source_dirs
256         do
257                 if test -d "$dir"
258                 then
259                         echo -n "Copying [$dir]..."
260                         cp -a $dir /media/temp && echo ok || echo FAILED
261                 fi
262         done
263         
264         for dir in $mkdir_list
265         do
266                 mkdir -p /media/temp/$dir
267         done
268         
269         rm /media/temp/etc/rcS.s/S39sd
270         
271 }
272 run_module() {
273         
274         test -e /etc/altboot.func && . /etc/altboot.func || die "ERROR: /etc/altboot.func not found. Check your installation!"
275         
276         echo -e "${C_RED}* * * * * WARNING * * * * *${C_RESET}"
277         echo -e "${C_RED}Continueing will delete the content of the selected target device.\nTHIS IS NO JOKE. If you do now know what this menu-item does, exit NOW${C_RESET}"
278         
279         mount -o remount,rw /
280         
281         while true
282         do
283                 echo -en "\nContinue? [y|n] "
284                 read junk </dev/tty1
285                 
286                 if test "$junk" = n
287                 then
288                         exit 0
289                 fi
290                 
291                 if test "$junk" = y
292                 then
293                         break
294                 fi
295         done    
296         
297 #       echo -n "Trying to activate PCMCIA..."
298 #       cardmgr -o >/dev/null 2>&1 && echo ok || echo "FAILED"
299 #       
300 #       echo -n "Trying to mount SD card..."
301 #       /etc/init.d/sd start >/dev/null 2>&1
302 #       sleep 3
303 #       /etc/sdcontrol insert >/dev/null 2>&1 && echo ok || echo "FAILED"
304         
305         #exit 0
306         echo -e "\nPlease select the target device:"    
307         
308         # Sets ROOTFS_TARGET*
309         ask_target
310         
311         # Sets ROOTFS_TARGET_TYPE ([direct | image]
312         ask_format
313         
314         # Ask confirmation
315         ask_confirm
316         
317         case "$ROOTFS_TARGET_TYPE" in
318         direct) direct_install;;
319         image)  image_install;;
320         esac
321 }
322
323 case "$1" in
324 title)  echo "$M_TITLE";;
325 run)    run_module;;
326 esac