blob: 74e24a64ec3748c737efdd4dbc3642106a594b57 [file] [log] [blame]
Koushik Duttaceddcd52010-08-23 16:13:14 -07001#!/sbin/sh
2
3# do logging, if not excluded with -x
4LOGFILE="/data/sdparted.log"
5[ "$1" != "-x" ] && echo "$0" "$@" >> "$LOGFILE" && "$0" -x "$@" 2>&1 | tee -a "$LOGFILE" && exit
6shift
7
8ShowError() { echo ; echo " err: $1" ; echo ; exit 1 ; }
9
10ShowMessage() { echo ; echo " msg: $1" ; }
11
12ShowHelp() {
13
14cat <<DONEHELP
15
16$SCRIPTNAME v$SCRIPTREV created by $MYNAME
17
18if you use this script in your work, please give some credit. thanks.
19
20requirements: cm-recovery-v1.4
21
22usage: $SCRIPTNAME [options]
23
24
25options:
26
27 --fatsize|-fs SIZE[MG] set the size of the fat32 partition to <SIZE>.
28 default=total sdcard size - (ext + swap)
29
30 --extsize|-es SIZE[MG] set the size of the ext partition to <SIZE>.
31 default=$EXTSIZE
32
33 --swapsize|-ss SIZE[MG] set the size of the swap partition to <SIZE>.
34 if set to 0, no swap partition will be created.
35 default=$SWAPSIZE
36
37 --extfs|-efs TYPE set the filesystem of ext partition to <TYPE>.
38 valid types=ext2, ext3, ext4
39 default=$EXTFS
40
41
42 --upgradefs|-ufs TYPE upgrades existing ext partition to <TYPE>.
43 this operation will NOT wipe your sdcard and
44 cannot be used with any partition creation options.
45 valid types=ext3, ext4
46
47 --downgradefs|-dfs TYPE downgrades existing ext partition to <TYPE>.
48 this operation will NOT wipe your sdcard and
49 cannot be used with any partition creation options.
50 valid types=ext2
51
52
53 --interactive|-i interactive mode
54
55 --help|-h display this help
56
57 --printonly|-po display sdcard information
58
59 --silent|-s do not prompt user, not even initial warning.
60
61
62examples:
63 $SCRIPTNAME creates swap=$SWAPSIZE ext2=$EXTSIZE fat32=remaining free space
64 $SCRIPTNAME -efs ext4 creates swap=$SWAPSIZE ext4=$EXTSIZE fat32=remaining free space
65 $SCRIPTNAME -fs 1.5G -efs ext3 creates swap=$SWAPSIZE ext3=$EXTSIZE fat32=1536
66 $SCRIPTNAME -es 256M -ss 0 creates no swap ext2=256 fat32=remaining free space
67 $SCRIPTNAME -ufs ext4 upgrades ext partition to ext4
68
69DONEHELP
70
71}
72
73UserAbort() {
74
75 WHILEEXIT=
76
77 while [ -z "$WHILEEXIT" ]
78 do
79 echo -n "do you want to continue? (Y/n) "
80 read response
81 echo
82 [ "$response" = "Y" ] || [ "$response" = "n" ] || [ "$response" = "N" ] && WHILEEXIT="$response"
83 done
84
85 echo "$response" > /dev/null 2>&1 >>"$LOGFILE"
86
87 [ "$response" != "Y" ]
88
89}
90
91UnmountAll () {
92
93 # unmount all partitions so we can work with $SDPATH
94 # i'm assuming no more than 3 partitions
95 # maybe make a little more elegant later
96 echo -n "unmounting all partitions..."
97 umount "$FATPATH" > /dev/null 2>&1 >>"$LOGFILE"
98 umount "$EXTPATH" > /dev/null 2>&1 >>"$LOGFILE"
99 umount "$SWAPPATH" > /dev/null 2>&1 >>"$LOGFILE"
100 echo "done"
101 echo
102
103}
104
105
106CheckReqs() {
107
108 echo -n "checking script requirements..."
109 # check for valid sdcard
110 [ -e $SDPATH ] || ShowError "$SDPATH does not exist!"
111
112 # look for necessary programs
113 [ -e $CMPARTED ] || ShowError "$CMPARTED does not exist!"
114 [ -e $CMTUNE2FS ] || ShowError "$CMTUNE2FS does not exist!"
115 [ -e $CME2FSCK ] || ShowError "$CME2FSCK does not exist!"
116
117 # verify cm-v1.4
118 PARTEDREV=`"$CMPARTED" "$SDPATH" version | grep Parted | cut -d" " -f3`
119 [ "$PARTEDREV" == "1.8.8.1.179-aef3" ] || ShowError "you are not using parted v1.8.8.1.179-aef3!"
120 echo "done"
121 echo
122
123}
124
125CheckTableType() {
126
127 TABLETYPE=`"$CMPARTED" "$SDPATH" print | grep Table: | cut -d" " -f3`
128
129 [ "$TABLETYPE" == "loop" -o "$TABLETYPE" == "msdos" ] && TTISOK=1 || TTISOK=0
130 [ "$TABLETYPE" == "loop" ] && TTISLOOP=1 || TTISLOOP=0
131 [ "$TABLETYPE" == "msdos" ] && TTISMSDOS=1 || TTISMOSDOS=0
132
133}
134
135ValidateExtArg() {
136
137 FUNC_RET="nonzero"
138
139 # validating argument
140 [ "$1" != "ext2" ] && [ "$1" != "ext3" ] && [ "$1" != "ext4" ] && FUNC_RET=
141
142 [ -z "$FUNC_RET" ] && [ -z "$IMODE" ] && ShowError "$1 is not a valid filesystem."
143 [ -z "$FUNC_RET" ] && [ -n "$IMODE" ] && ShowMessage "$1 is not a valid filesystem."
144
145 # return valid argument
146 [ -n "$FUNC_RET" ] && FUNC_RET="$1"
147
148}
149
150ValidateSizeArg() {
151
152 # check for zero-length arg to protect expr length
153 [ -z "$1" ] && ShowError "zero-length argument passed to size-validator"
154
155 SIZEMB=
156 ARGLEN=`expr length $1`
157 SIZELEN=$(($ARGLEN-1))
158 SIZEARG=`expr substr $1 1 $SIZELEN`
159 SIZEUNIT=`expr substr $1 $ARGLEN 1`
160
161 # check if SIZEARG is an integer
162 if [ $SIZEARG -eq $SIZEARG 2> /dev/null ] ; then
163 # look for G
164 [ "$SIZEUNIT" == "G" ] && SIZEMB=$(($SIZEARG * 1024))
165 # look for M
166 [ "$SIZEUNIT" == "M" ] && SIZEMB=$SIZEARG
167 # no units on arg AND prevents using bogus size units
168 [ -z "$SIZEMB" ] && [ $SIZEUNIT -eq $SIZEUNIT 2> /dev/null ] && SIZEMB=$1
169 # check if SIZEARG is a floating point number, GB only
170 elif [ `expr index "$SIZEARG" .` != 0 ] && [ "$SIZEUNIT" == "G" ] ; then
171 INT=`echo "$SIZEARG" | cut -d"." -f1`
172 FRAC=`echo "$SIZEARG" | cut -d"." -f2`
173 SIGDIGITS=`expr length $FRAC`
174
175 [ -z "$INT" ] && INT=0
176 INTMB=$(($INT * 1024))
177 FRACMB=$((($FRAC * 1024) / (10**$SIGDIGITS)))
178 SIZEMB=$(($INTMB + $FRACMB))
179 # it's not a valid size
180 else
181 [ -z "$IMODE" ] && ShowError "$1 is not a valid size"
182 fi
183
184 [ -z "$SIZEMB" ] && [ -n "$IMODE" ] && ShowMessage "$1 is not a valid size"
185
186 # return valid argument in MB
187 FUNC_RET=$SIZEMB
188
189}
190
191CalculatePartitions() {
192
193 # get size of sdcard in MB & do some math
194 SDSIZEMB=`"$CMPARTED" "$SDPATH" unit MB print | grep $SDPATH | cut -d" " -f3`
195 SDSIZE=${SDSIZEMB%MB}
196 [ -n "$FATSIZE" ] || FATSIZE=$(($SDSIZE - $EXTSIZE - $SWAPSIZE))
197 EXTEND=$(($FATSIZE + $EXTSIZE))
198 SWAPEND=$(($EXTEND + $SWAPSIZE))
199
200 # check for fatsize of 0
201 [ $FATSIZE -le 0 ] && ShowError "must have a fat32 partition greater than 0MB"
202
203 # check for zero-length sdsize...
204 # indicative of parted not reporting length
205 # correctly b/c of error on sdcard
206 [ -z "$SDSIZE" ] && ShowError "zero-length argument passed to partition-calculator"
207
208 # make sure we're not being asked to do the impossible
209 [ $(($FATSIZE + $EXTSIZE + $SWAPSIZE)) -gt $SDSIZE ] && [ -z "$IMODE" ] && ShowError "sum of requested partitions is greater than sdcard size"
210
211}
212
213
214UpgradeDowngradeOnly() {
215
216 if [ -n "$UEXTFSONLY" ] ; then
217 echo
218 [ -n "$CREATEPART" ] && ShowError "cannot use upgrade option when creating partitions, use -efs instead"
219 [ -n "$DEXTFSONLY" ] && ShowError "cannot upgrade AND downgrade, it just doesn't make sense"
220 echo "you have chosen to upgrade $EXTPATH to $UEXTFSONLY."
221 echo "this action will NOT delete any data from sdcard."
222 echo
223 [ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
224 echo
225 UpgradeExt "$UEXTFSONLY"
226 ShowCardInfo
227 elif [ -n "$DEXTFSONLY" ] ; then
228 echo
229 [ -n "$CREATEPART" ] && ShowError "cannot use downgrade option when creating partitions."
230 [ -n "$UEXTFSONLY" ] && ShowError "cannot downgrade AND upgrade, it just doesn't make sense."
231 echo "you have chosen to downgrade $EXTPATH to $DEXTFSONLY."
232 echo "this action will NOT delete any data from sdcard."
233 echo
234 [ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
235 echo
236 DowngradeExt "$DEXTFSONLY"
237 ShowCardInfo
238 fi
239
240}
241
242PrepareSdCard() {
243
244 echo
245 if [ $TTISOK -eq 0 ] ; then
246 echo "partition 1 may not be aligned to cylinder boundaries."
247 echo "to continue, this must be corrected."
248 elif [ $TTISLOOP -gt 0 ] ; then
249 echo "your sdcard's partition table type is $TABLETYPE."
250 echo "to continue, partition table must be set to 'msdos'."
251 elif [ $TTISMSDOS -gt 0 ] ; then
252 # just a reminder..in a later version,
253 # i may implement resizing of partitions,
254 # so this will be unnecessary. but until then...
255 echo "to continue, all existing partitions must be removed."
256 else
257 # this is not good, and should never happen
258 # if it does, there is a serious problem
259 ShowError "sdcard failed table type check."
260 fi
261
262 echo
263 echo "this action will remove all data from your sdcard."
264 echo
265 [ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
266
267 [ $TTISOK -eq 0 ] && echo -n "correcting cylinder boundaries..."
268 [ $TTISLOOP -gt 0 ] && echo -n "setting partition table to msdos..."
269 [ $TTISMSDOS -gt 0 ] && echo -n "removing all partitions..."
270
271 "$CMPARTED" -s "$SDPATH" mklabel msdos 2>&1 >>"$LOGFILE"
272 echo "done"
273 echo
274
275}
276
277ShowActions() {
278
279 echo
280 echo "total size of sdcard=$SDSIZEMB"
281 echo
282 echo "the following actions will be performed:"
283 echo " -create $FATSIZE""MB fat32 partition"
284 [ $EXTSIZE -gt 0 ] && echo " -create $EXTSIZE""MB ext2 partition"
285 [ $SWAPSIZE -gt 0 ] && echo " -create $SWAPSIZE""MB swap partition"
286 [ "$EXTFS" != "ext2" ] && echo " -ext2 partition will be upgraded to $EXTFS"
287 echo
288 [ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
289 echo
290
291}
292
293ShowCardInfo() {
294
295 CheckTableType
296
297 echo
298 echo "retrieving current sdcard information..."
299
300 if [ $TTISOK -gt 0 ] ; then
301 echo
302 parted "$SDPATH" print
303 echo
304 echo "script log is located @ /data/sdparted.log"
305 exit 0
306 else
307 echo
308 echo "partition 1 may not be aligned to cylinder boundaries."
309 ShowError "cannot complete print operation."
310 fi
311 echo
312
313}
314
315
316PartitionSdCard() {
317
318 echo "performing selected actions..."
319 echo
320
321 if [ $FATSIZE -gt 0 ] ; then
322 echo -n "creating fat32 partition..."
323 "$CMPARTED" -s "$SDPATH" mkpartfs primary fat32 0 "$FATSIZE"MB 2>&1 >>"$LOGFILE"
324 echo "done"
325 fi
326
327 if [ $EXTSIZE -gt 0 ] ; then
328 echo -n "creating ext2 partition..."
329 "$CMPARTED" -s "$SDPATH" mkpartfs primary ext2 "$FATSIZE"MB "$EXTEND"MB 2>&1 >>"$LOGFILE"
Giulio Cervera15b06182010-12-30 22:49:34 +0100330 "$CMTUNE2FS" -L sd-ext "$EXTPATH" 2>&1 >>"$LOGFILE"
Koushik Duttaceddcd52010-08-23 16:13:14 -0700331 echo "done"
332 fi
333
334 if [ $SWAPSIZE -gt 0 ] ; then
335 echo -n "creating swap partition..."
336 "$CMPARTED" -s "$SDPATH" mkpartfs primary linux-swap "$EXTEND"MB "$SWAPEND"MB 2>&1 >>"$LOGFILE"
337 echo "done"
338 fi
339 echo
340
341}
342
343UpgradeExt() {
344
345 # check for no upgrade
346 [ "$1" == "ext2" ] && return
347 # check for ext partition
348 [ ! -e "$EXTPATH" ] && ShowError "$EXTPATH does not exist"
349
350 # have to use -m switch for this check b/c parted incorrectly
351 # reports all ext partitions as ext2 when running print <number>
352 CHECKEXTFS=`"$CMPARTED" -m "$SDPATH" print | grep ext | cut -d":" -f5`
353 [ "$CHECKEXTFS" == "$1" ] && ShowError "$EXTPATH is already $1"
354
355 # grabbed the code bits for ext3 from upgrade_fs(credit:cyanogen)
356 # check for ext2...must upgrade to ext3 first b4 ext4
357 if [ "$1" == "ext3" -o "$1" == "ext4" ] ; then
358 echo -n "adding journaling to $EXTPATH..."
359 umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
360 "$CME2FSCK" -p "$EXTPATH" 2>&1 >>"$LOGFILE"
361 "$CMTUNE2FS" -c0 -i0 -j "$EXTPATH" 2>&1 >>"$LOGFILE"
362 echo "done"
363 fi
364
365 # and got convert to ext4 from xda-forum(credit:Denkai)
366 if [ "$1" == "ext4" ] ; then
367 echo -n "converting $EXTPATH to ext4 filesystem..."
368 umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
369 "$CMTUNE2FS" -O extents,uninit_bg,dir_index "$EXTPATH" 2>&1 >>"$LOGFILE"
370 "$CME2FSCK" -fpDC0 "$EXTPATH" 2>&1 >>"$LOGFILE"
371 echo "done"
372 fi
373 echo
374
375}
376
377DowngradeExt() {
378
379 # check for ext partition
380 [ ! -e "$EXTPATH" ] && ShowError "$EXTPATH does not exist"
381
382 # have to use print for this check b/c parted incorrectly
383 # reports all ext partitions as ext2 when running print <number>
384 CHECKEXTFS=`"$CMPARTED" -m "$SDPATH" print | grep ext | cut -d":" -f5`
385 [ "$CHECKEXTFS" == "$1" ] && ShowError "$EXTPATH is already $1"
386
387 if [ "$CHECKEXTFS" == "ext4" -o "$1" == "ext3" ] ; then
388 # interweb says downgrading from ext4 is not possible
389 # without a backup/restore procedure.
390 # if i figure it out, i'll implement it.
391 ShowError "downgrading from ext4 is not currently supported"
392 fi
393
394 if [ "$1" == "ext2" ] ; then
395 echo -n "removing journaling from $EXTPATH..."
396 umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
397 "$CMTUNE2FS" -O ^has_journal "$EXTPATH" 2>&1 >>"$LOGFILE"
398 "$CME2FSCK" -fp "$EXTPATH" 2>&1 >>"$LOGFILE"
399 echo "done"
400 fi
401 echo
402
403}
404
405
406Interactive() {
407
408cat <<DONEINSTRUCT
409
410sdparted interactive mode
411
412rules:
4131. no answer means you accept default value
4142. enter '0' for no partition
415
416DONEINSTRUCT
417
418 UserAbort && ShowError "script canceled by user"
419
420 CalculatePartitions
421
422 GetSwapSize
423
424 FATSIZE=
425
426 CalculatePartitions
427
428 GetExtSize
429
430 GetExtType
431
432 FATSIZE=
433
434 CalculatePartitions
435
436 GetFatSize
437
438}
439
440GetSwapSize() {
441
442 SWAPTEST=
443
444 while [ -z "$SWAPTEST" ]
445 do
446 echo
447 echo -n "swap partition size [default=$SWAPSIZE]: "
448 read SWAPRESP
449
450 [ -z "$SWAPRESP" ] && SWAPRESP="$SWAPSIZE"
451 echo "$SWAPRESP" > /dev/null 2>&1 >>"$LOGFILE"
452
453 ValidateSizeArg "$SWAPRESP"
454 SWAPTEST="$FUNC_RET"
455 [ -n "$SWAPTEST" ] && [ $SWAPTEST -gt $SDSIZE ] && ShowMessage "$SWAPRESP > available space($(($SDSIZE))M)." && SWAPTEST=
456 done
457
458 SWAPSIZE=$SWAPTEST
459
460}
461
462GetExtSize() {
463
464 EXTTEST=
465
466 while [ -z "$EXTTEST" ]
467 do
468 echo
469 echo -n "ext partition size [default=$EXTSIZE]: "
470 read EXTRESP
471
472 [ -z "$EXTRESP" ] && EXTRESP="$EXTSIZE"
473 echo "$EXTRESP" > /dev/null 2>&1 >>"$LOGFILE"
474
475 ValidateSizeArg "$EXTRESP"
476 EXTTEST="$FUNC_RET"
477
478 [ -n "$EXTTEST" ] && [ $EXTTEST -gt $(($SDSIZE - $SWAPSIZE)) ] && ShowMessage "$EXTRESP > available space($(($SDSIZE - $SWAPSIZE))M)." && EXTTEST=
479 done
480
481 EXTSIZE=$EXTTEST
482
483}
484
485GetExtType() {
486
487 FSTEST=
488
489 while [ -z "$FSTEST" ]
490 do
491 echo
492 echo -n "ext partition type [default=$EXTFS]: "
493 read FSRESP
494
495 [ -z "$FSRESP" ] && FSRESP="$EXTFS"
496 echo "$FSRESP" > /dev/null 2>&1 >>"$LOGFILE"
497
498 ValidateExtArg "$FSRESP"
499 FSTEST="$FUNC_RET"
500 done
501
502 EXTFS="$FSTEST"
503
504}
505
506GetFatSize() {
507
508 FATTEST=
509
510 while [ -z "$FATTEST" ]
511 do
512 echo
513 echo -n "fat partition size [default=$FATSIZE]: "
514 read FATRESP
515
516 [ -z "$FATRESP" ] && FATRESP="$FATSIZE"
517 echo "$FATRESP" > /dev/null 2>&1 >>"$LOGFILE"
518
519 ValidateSizeArg "$FATRESP"
520 FATTEST="$FUNC_RET"
521
522 [ -n "$FATTEST" ] && [ $FATTEST -gt $FATSIZE ] && ShowMessage "$FATRESP > available space($(($SDSIZE - $SWAPSIZE - $EXTSIZE))M)." && FATTEST=
523 [ -n "$FATTEST" ] && [ $FATTEST -le 0 ] && ShowMessage "must have a fat32 partition greater than 0MB" && FATTEST=
524 done
525
526 FATSIZE=$FATTEST
527
528}
529
530
531SCRIPTNAME="sdparted"
532SCRIPTREV="0.6"
533MYNAME="51dusty"
534
535IMODE=
536SILENTRUN=
537CREATEPART=
538FUNC_RET=
539
540UEXTFSONLY=
541DEXTFSONLY=
542
543TTISOK=
544TTISLOOP=
545TTISMSDOS=
546
547SDSIZE=
548SDSIZEMB=
Koushik Duttaf1bde362011-04-22 11:26:03 -0700549SDINFO=$(cat /etc/fstab | grep /sdcard | awk '{print $1}')
550if [ -L "$SDINFO" ]
Koushik Duttaceddcd52010-08-23 16:13:14 -0700551then
Koushik Duttaf1bde362011-04-22 11:26:03 -0700552 SDPATH=$(ls -l $SDINFO | awk '{print $11}')
Koushik Duttaceddcd52010-08-23 16:13:14 -0700553else
Koushik Duttaf1bde362011-04-22 11:26:03 -0700554 SDPATH=$SDINFO
Koushik Duttaceddcd52010-08-23 16:13:14 -0700555fi
Koushik Duttaf1bde362011-04-22 11:26:03 -0700556# we may now have an SDPATH, let's make sure its on mmcblkX or mmcblkXp1
557CHECK_SDPATH1=$(echo $SDPATH | grep mmcblk.$)
558CHECK_SDPATH2=$(echo $SDPATH | grep mmcblk.p1$)
559if [ -z "$CHECK_SDPATH1" ]
560then
561 if [ -z "$CHECK_SDPATH2" ]
562 then
563 echo fail1
564 unset SDPATH
565 else
566 LEN=${#SDPATH}
567 BLKLEN=$(expr $LEN - 2)
568 SDPATH=${SDPATH:0:$BLKLEN}
569 fi
570fi
571
Koushik Duttaceddcd52010-08-23 16:13:14 -0700572
573FATSIZE=
574FATTYPE="fat32"
575FATPATH=$SDPATH"p1"
576
577EXTSIZE=512
578EXTFS="ext2"
579EXTPATH=$SDPATH"p2"
580EXTEND=
581
582SWAPSIZE=32
583SWAPTYPE="linux-swap"
584SWAPPATH=$SDPATH"p3"
585SWAPEND=
586
587CMPARTED="/sbin/parted"
588CMTUNE2FS="/sbin/tune2fs"
589CME2FSCK="/sbin/e2fsck"
590
591# give the output some breathing room
592echo "$SCRIPTREV" >> "$LOGFILE"
593echo
594
595# check for arguments
596while [ $# -gt 0 ] ; do
597 case "$1" in
598
599 -h|--help) ShowHelp ; exit 0 ;;
600
601 -fs|--fatsize) shift ; ValidateSizeArg "$1" ; FATSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
602 -es|--extsize) shift ; ValidateSizeArg "$1" ; EXTSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
603 -ss|--swapsize) shift ; ValidateSizeArg "$1" ; SWAPSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
604 -efs|--extfs) shift ; ValidateExtArg "$1" ; EXTFS="$FUNC_RET" ; CREATEPART="$1" ;;
605
606 -ufs|--upgradefs) shift ; ValidateExtArg "$1" ; UEXTFSONLY="$FUNC_RET" ;;
607 -dfs|--downgradefs) shift ; ValidateExtArg "$1" ; DEXTFSONLY="$FUNC_RET" ;;
608
609 -i|--interactive) IMODE="$1" ;;
610
611 -s|--silent) SILENTRUN="$1" ;;
612
613 -po|--printonly) ShowCardInfo ;;
614
615 *) ShowHelp ; ShowError "unknown argument '$1'" ;;
616
617 esac
618 shift
619done
620
621# can't do silent when in interactive mode
622[ -n "$IMODE" ] && SILENTRUN=
623
624# make sure sdcard exists and all needed files are here
625CheckReqs
626
627# unmount all
628UnmountAll
629
630# upgrade only? downgrade only?
631UpgradeDowngradeOnly
632
633# check table
634CheckTableType
635
636# prep card
637PrepareSdCard
638
639# check for interactive mode
640[ -n "$IMODE" ] && Interactive
641
642# do some math
643CalculatePartitions
644
645# last chance to cancel
646ShowActions
647
648# partition card
649PartitionSdCard
650
651# upgrade fs if necessary
652UpgradeExt "$EXTFS"
653
654# say goodbye and show print output
655ShowCardInfo