Advertisement
fosser22

Untitled

Feb 1st, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.88 KB | None | 0 0
  1. #!/sbin/sh
  2.  
  3. # do logging, if not excluded with -x
  4. LOGFILE="/data/sdparted.log"
  5. [ "$1" != "-x" ] && echo "$0" "$@" >> "$LOGFILE" && "$0" -x "$@" 2>&1 | tee -a "$LOGFILE" && exit
  6. shift
  7.  
  8. ShowError() { echo ; echo " err: $1" ; echo ; exit 1 ; }
  9.  
  10. ShowMessage() { echo ; echo " msg: $1" ; }
  11.  
  12. ShowHelp() {
  13.  
  14. cat <<DONEHELP
  15.  
  16. $SCRIPTNAME v$SCRIPTREV created by $MYNAME
  17.  
  18. if you use this script in your work, please give some credit. thanks.
  19.  
  20. requirements: cm-recovery-v1.4
  21.  
  22. usage: $SCRIPTNAME [options]
  23.  
  24.  
  25. options:
  26.  
  27. --fatsize|-fs SIZE[MG] set the size of the fat32 partition to <SIZE>.
  28. default=total sdcard size - (ext + cache)
  29.  
  30. --extsize|-es SIZE[MG] set the size of the ext partition to <SIZE>.
  31. default=$EXTSIZE
  32.  
  33. --cachesize|-ss SIZE[MG] set the size of the cache partition to <SIZE>.
  34. if set to 0, no cache partition will be created.
  35. default=$CACHESIZE
  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.  
  62. examples:
  63. $SCRIPTNAME creates cache=$CACHESIZE ext2=$EXTSIZE fat32=remaining free space
  64. $SCRIPTNAME -efs ext4 creates cache=$CACHESIZE ext4=$EXTSIZE fat32=remaining free space
  65. $SCRIPTNAME -fs 1.5G -efs ext3 creates cache=$CACHESIZE ext3=$EXTSIZE fat32=1536
  66. $SCRIPTNAME -es 256M -ss 0 creates no cache ext2=256 fat32=remaining free space
  67. $SCRIPTNAME -ufs ext4 upgrades ext partition to ext4
  68.  
  69. DONEHELP
  70.  
  71. }
  72.  
  73. UserAbort() {
  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.  
  91. UnmountAll () {
  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 "$CACHEPATH" > /dev/null 2>&1 >>"$LOGFILE"
  100. echo "done"
  101. echo
  102.  
  103. }
  104.  
  105.  
  106. CheckReqs() {
  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.  
  125. CheckTableType() {
  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.  
  135. ValidateExtArg() {
  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.  
  150. ValidateSizeArg() {
  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.  
  191. CalculatePartitions() {
  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 - $CACHESIZE))
  197. EXTEND=$(($FATSIZE + $EXTSIZE))
  198. CACHEEND=$(($EXTEND + $CACHESIZE))
  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 + $CACHESIZE)) -gt $SDSIZE ] && [ -z "$IMODE" ] && ShowError "sum of requested partitions is greater than sdcard size"
  210.  
  211. }
  212.  
  213.  
  214. UpgradeDowngradeOnly() {
  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.  
  242. PrepareSdCard() {
  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.  
  277. ShowActions() {
  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. [ $CACHESIZE -gt 0 ] && echo " -create $CACHESIZE""MB cache 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.  
  293. ShowCardInfo() {
  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.  
  316. PartitionSdCard() {
  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"
  330. "$CMTUNE2FS" -L sd-ext "$EXTPATH" 2>&1 >>"$LOGFILE"
  331. echo "done"
  332. fi
  333.  
  334. if [ $CACHESIZE -gt 0 ] ; then
  335. echo -n "creating cache partition..."
  336. "$CMPARTED" -s "$SDPATH" mkpartfs primary ext2 "$EXTEND"MB "$CACHEEND"MB 2>&1 >>"$LOGFILE"
  337. "$CMTUNE2FS" -L cache "$CACHEPATH" 2>&1 >>"$LOGFILE"
  338. echo "done"
  339. fi
  340. echo
  341.  
  342. }
  343.  
  344. UpgradeExt() {
  345.  
  346. # check for no upgrade
  347. [ "$1" == "ext2" ] && return
  348. # check for ext partition
  349. [ ! -e "$EXTPATH" ] && ShowError "$EXTPATH does not exist"
  350.  
  351. # have to use -m switch for this check b/c parted incorrectly
  352. # reports all ext partitions as ext2 when running print <number>
  353. CHECKEXTFS=`"$CMPARTED" -m "$SDPATH" print | grep ext | cut -d":" -f5`
  354. [ "$CHECKEXTFS" == "$1" ] && ShowError "$EXTPATH is already $1"
  355.  
  356. # grabbed the code bits for ext3 from upgrade_fs(credit:cyanogen)
  357. # check for ext2...must upgrade to ext3 first b4 ext4
  358. if [ "$1" == "ext3" -o "$1" == "ext4" ] ; then
  359. echo -n "adding journaling to $EXTPATH..."
  360. umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
  361. "$CME2FSCK" -p "$EXTPATH" 2>&1 >>"$LOGFILE"
  362. "$CMTUNE2FS" -c0 -i0 -j "$EXTPATH" 2>&1 >>"$LOGFILE"
  363. echo "done"
  364. fi
  365.  
  366. # and got convert to ext4 from xda-forum(credit:Denkai)
  367. if [ "$1" == "ext4" ] ; then
  368. echo -n "converting $EXTPATH to ext4 filesystem..."
  369. umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
  370. "$CMTUNE2FS" -O extents,uninit_bg,dir_index "$EXTPATH" 2>&1 >>"$LOGFILE"
  371. "$CME2FSCK" -fpDC0 "$EXTPATH" 2>&1 >>"$LOGFILE"
  372. echo "done"
  373. fi
  374. echo
  375.  
  376. }
  377.  
  378. DowngradeExt() {
  379.  
  380. # check for ext partition
  381. [ ! -e "$EXTPATH" ] && ShowError "$EXTPATH does not exist"
  382.  
  383. # have to use print for this check b/c parted incorrectly
  384. # reports all ext partitions as ext2 when running print <number>
  385. CHECKEXTFS=`"$CMPARTED" -m "$SDPATH" print | grep ext | cut -d":" -f5`
  386. [ "$CHECKEXTFS" == "$1" ] && ShowError "$EXTPATH is already $1"
  387.  
  388. if [ "$CHECKEXTFS" == "ext4" -o "$1" == "ext3" ] ; then
  389. # interweb says downgrading from ext4 is not possible
  390. # without a backup/restore procedure.
  391. # if i figure it out, i'll implement it.
  392. ShowError "downgrading from ext4 is not currently supported"
  393. fi
  394.  
  395. if [ "$1" == "ext2" ] ; then
  396. echo -n "removing journaling from $EXTPATH..."
  397. umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
  398. "$CMTUNE2FS" -O ^has_journal "$EXTPATH" 2>&1 >>"$LOGFILE"
  399. "$CME2FSCK" -fp "$EXTPATH" 2>&1 >>"$LOGFILE"
  400. echo "done"
  401. fi
  402. echo
  403.  
  404. }
  405.  
  406.  
  407. Interactive() {
  408.  
  409. cat <<DONEINSTRUCT
  410.  
  411. sdparted interactive mode
  412.  
  413. rules:
  414. 1. no answer means you accept default value
  415. 2. enter '0' for no partition
  416.  
  417. DONEINSTRUCT
  418.  
  419. UserAbort && ShowError "script canceled by user"
  420.  
  421. CalculatePartitions
  422.  
  423. GetSwapSize
  424.  
  425. FATSIZE=
  426.  
  427. CalculatePartitions
  428.  
  429. GetExtSize
  430.  
  431. GetExtType
  432.  
  433. FATSIZE=
  434.  
  435. CalculatePartitions
  436.  
  437. GetFatSize
  438.  
  439. }
  440.  
  441. GetSwapSize() {
  442.  
  443. CACHETEST=
  444.  
  445. while [ -z "$CACHETEST" ]
  446. do
  447. echo
  448. echo -n "cache partition size [default=$CACHESIZE]: "
  449. read CACHERESP
  450.  
  451. [ -z "$CACHERESP" ] && CACHERESP="$CACHESIZE"
  452. echo "$CACHERESP" > /dev/null 2>&1 >>"$LOGFILE"
  453.  
  454. ValidateSizeArg "$CACHERESP"
  455. CACHETEST="$FUNC_RET"
  456. [ -n "$CACHETEST" ] && [ $CACHETEST -gt $SDSIZE ] && ShowMessage "$CACHERESP > available space($(($SDSIZE))M)." && CACHETEST=
  457. done
  458.  
  459. CACHESIZE=$CACHETEST
  460.  
  461. }
  462.  
  463. GetExtSize() {
  464.  
  465. EXTTEST=
  466.  
  467. while [ -z "$EXTTEST" ]
  468. do
  469. echo
  470. echo -n "ext partition size [default=$EXTSIZE]: "
  471. read EXTRESP
  472.  
  473. [ -z "$EXTRESP" ] && EXTRESP="$EXTSIZE"
  474. echo "$EXTRESP" > /dev/null 2>&1 >>"$LOGFILE"
  475.  
  476. ValidateSizeArg "$EXTRESP"
  477. EXTTEST="$FUNC_RET"
  478.  
  479. [ -n "$EXTTEST" ] && [ $EXTTEST -gt $(($SDSIZE - $CACHESIZE)) ] && ShowMessage "$EXTRESP > available space($(($SDSIZE - $CACHESIZE))M)." && EXTTEST=
  480. done
  481.  
  482. EXTSIZE=$EXTTEST
  483.  
  484. }
  485.  
  486. GetExtType() {
  487.  
  488. FSTEST=
  489.  
  490. while [ -z "$FSTEST" ]
  491. do
  492. echo
  493. echo -n "ext partition type [default=$EXTFS]: "
  494. read FSRESP
  495.  
  496. [ -z "$FSRESP" ] && FSRESP="$EXTFS"
  497. echo "$FSRESP" > /dev/null 2>&1 >>"$LOGFILE"
  498.  
  499. ValidateExtArg "$FSRESP"
  500. FSTEST="$FUNC_RET"
  501. done
  502.  
  503. EXTFS="$FSTEST"
  504.  
  505. }
  506.  
  507. GetFatSize() {
  508.  
  509. FATTEST=
  510.  
  511. while [ -z "$FATTEST" ]
  512. do
  513. echo
  514. echo -n "fat partition size [default=$FATSIZE]: "
  515. read FATRESP
  516.  
  517. [ -z "$FATRESP" ] && FATRESP="$FATSIZE"
  518. echo "$FATRESP" > /dev/null 2>&1 >>"$LOGFILE"
  519.  
  520. ValidateSizeArg "$FATRESP"
  521. FATTEST="$FUNC_RET"
  522.  
  523. [ -n "$FATTEST" ] && [ $FATTEST -gt $FATSIZE ] && ShowMessage "$FATRESP > available space($(($SDSIZE - $CACHESIZE - $EXTSIZE))M)." && FATTEST=
  524. [ -n "$FATTEST" ] && [ $FATTEST -le 0 ] && ShowMessage "must have a fat32 partition greater than 0MB" && FATTEST=
  525. done
  526.  
  527. FATSIZE=$FATTEST
  528.  
  529. }
  530.  
  531.  
  532. SCRIPTNAME="sdparted"
  533. SCRIPTREV="0.6"
  534. MYNAME="51dusty"
  535.  
  536. IMODE=
  537. SILENTRUN=
  538. CREATEPART=
  539. FUNC_RET=
  540.  
  541. UEXTFSONLY=
  542. DEXTFSONLY=
  543.  
  544. TTISOK=
  545. TTISLOOP=
  546. TTISMSDOS=
  547.  
  548. SDSIZE=
  549. SDSIZEMB=
  550.  
  551. #SDINFO=$(cat /etc/fstab | grep /sdcard | awk '{print $1}')
  552. #if [ -L "$SDINFO" ]
  553. #then
  554. # SDPATH=$(ls -l $SDINFO | awk '{print $11}')
  555. #else
  556. # SDPATH=$SDINFO
  557. #fi
  558.  
  559. # we may now have an SDPATH, let's make sure its on mmcblkX or mmcblkXp1
  560. CHECK_SDPATH1=$(echo $SDPATH | grep mmcblk.$)
  561. CHECK_SDPATH2=$(echo $SDPATH | grep mmcblk.p1$)
  562. if [ -z "$CHECK_SDPATH1" ]
  563. then
  564. if [ -z "$CHECK_SDPATH2" ]
  565. then
  566. echo fail1
  567. unset SDPATH
  568. else
  569. LEN=${#SDPATH}
  570. BLKLEN=$(expr $LEN - 2)
  571. SDPATH=${SDPATH:0:$BLKLEN}
  572. fi
  573. fi
  574.  
  575.  
  576. FATSIZE=
  577. FATTYPE="fat32"
  578. FATPATH=$SDPATH"p1"
  579.  
  580. EXTSIZE=512
  581. EXTFS="ext2"
  582. EXTPATH=$SDPATH"p2"
  583. EXTEND=
  584.  
  585. CACHESIZE=32
  586. CACHETYPE="ext2"
  587. CACHEPATH=$SDPATH"p3"
  588. CACHEEND=
  589.  
  590. CMPARTED="/sbin/parted"
  591. CMTUNE2FS="/sbin/tune2fs"
  592. CME2FSCK="/sbin/e2fsck"
  593.  
  594. # give the output some breathing room
  595. echo "$SCRIPTREV" >> "$LOGFILE"
  596. echo
  597.  
  598. # check for arguments
  599. while [ $# -gt 0 ] ; do
  600. case "$1" in
  601.  
  602. -h|--help) ShowHelp ; exit 0 ;;
  603.  
  604. -fs|--fatsize) shift ; ValidateSizeArg "$1" ; FATSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
  605. -es|--extsize) shift ; ValidateSizeArg "$1" ; EXTSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
  606. -ss|--cachesize) shift ; ValidateSizeArg "$1" ; CACHESIZE="$FUNC_RET" ; CREATEPART="$1" ;;
  607. -efs|--extfs) shift ; ValidateExtArg "$1" ; EXTFS="$FUNC_RET" ; CREATEPART="$1" ;;
  608.  
  609. -ufs|--upgradefs) shift ; ValidateExtArg "$1" ; UEXTFSONLY="$FUNC_RET" ;;
  610. -dfs|--downgradefs) shift ; ValidateExtArg "$1" ; DEXTFSONLY="$FUNC_RET" ;;
  611.  
  612. -i|--interactive) IMODE="$1" ;;
  613.  
  614. -s|--silent) SILENTRUN="$1" ;;
  615.  
  616. -po|--printonly) ShowCardInfo ;;
  617.  
  618. *) ShowHelp ; ShowError "unknown argument '$1'" ;;
  619.  
  620. esac
  621. shift
  622. done
  623.  
  624. # can't do silent when in interactive mode
  625. [ -n "$IMODE" ] && SILENTRUN=
  626.  
  627. # make sure sdcard exists and all needed files are here
  628. CheckReqs
  629.  
  630. # unmount all
  631. UnmountAll
  632.  
  633. # upgrade only? downgrade only?
  634. UpgradeDowngradeOnly
  635.  
  636. # check table
  637. CheckTableType
  638.  
  639. # prep card
  640. PrepareSdCard
  641.  
  642. # check for interactive mode
  643. [ -n "$IMODE" ] && Interactive
  644.  
  645. # do some math
  646. CalculatePartitions
  647.  
  648. # last chance to cancel
  649. ShowActions
  650.  
  651. # partition card
  652. PartitionSdCard
  653.  
  654. # upgrade fs if necessary
  655. UpgradeExt "$EXTFS"
  656.  
  657. # say goodbye and show print output
  658. ShowCardInfo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement