Advertisement
Guest User

Untitled

a guest
Dec 30th, 2011
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #!/bin/bash
  2. #Defaults
  3. TEMPFILE=/tmp/rpsb
  4. BACKTITLE="Raspberry Pi SDCard Builder v0.1"
  5.  
  6. IMGFILE=sdcard.img
  7. ROOTFS=raspberrypi-rootfs.tar.gz
  8. KERNELBLOB=kernelblob.tar.gz
  9.  
  10. #TODO:Change to be calculated at runtime
  11. SDCARD=/dev/mmcblk1
  12.  
  13. #Functions
  14. #TODO: create fdisk script to partition and format sdcard as 1st part FAT (200MB?), 2nd part ext3/4 (rest of sdcard)
  15. prep_sdcard () {
  16. echo "TBD:fdisk script & format"
  17. }
  18.  
  19. make_mountpoints () {
  20. mkdir -p /mnt/p1
  21. mkdir -p /mnt/p2
  22. mount ${SDCARD}p1 /mnt/p1
  23. mount ${SDCARD}p2 /mnt/p2
  24. }
  25.  
  26. remove_mountpoints () {
  27. umount /mnt/p1
  28. umount /mnt/p2
  29. rmdir /mnt/p1
  30. rmdir /mnt/p2
  31. }
  32.  
  33. dd_imagefile () {
  34. # dd if=./$1 of=$2
  35. echo "dd if=$1 of=./$2"
  36. echo "TBD:dialog progress bar"
  37. }
  38.  
  39. extract_tarballs () {
  40. tar xzvpf ./$1 -C /mnt/p1
  41. tar xzvpf ./$2 -C /mnt/p2
  42. }
  43.  
  44. clone () {
  45. echo "Clone SDCard:TBD"
  46. }
  47. #Main()
  48.  
  49. dialog --colors --backtitle "$BACKTITLE" --msgbox "This script will assist you in creating a backup \
  50. or new copy of your raspberry pi sd card.\nYou will need to plug a usb sdcard reader/writer \
  51. in to an empty usb slot on your raspberry pi or into an attached usb hub and insert a blank \
  52. sd card into it" -1 -1
  53.  
  54. dialog --colors --backtitle "$BACKTITLE" --radiolist "What method of sd card creation do you want to use?" 0 0 3 \
  55. 1 "raw disk image " on \
  56. 2 "tarball" off \
  57. 3 "Clone" off 2>$TEMPFILE
  58.  
  59. retval=$?
  60. if [ $retval -eq 0 ]; then
  61. choice=`cat /tmp/rpsb`
  62. case "$choice" in
  63. 1)
  64. dd_imagefile $SDCARD $IMGFILE
  65. ;;
  66. 2)
  67. prep_sdcard $SDCARD
  68. make_mountpoints $SDCARD
  69. extract_tarballs $KERNELBLOB $ROOTFS
  70. sync
  71. remove_mountpoints
  72. ;;
  73. 3)
  74. prep_sdcard $SDCARD
  75. make_mountpoints $SDCARD
  76. clone
  77. sync
  78. remove_mountpoints
  79. ;;
  80. esac
  81. else
  82. dialog --colors --backtitle "$BACKTITLE" --msgbox "You have decided to not build an sd card at this time \
  83. \n\Zb\Z1GOODBYE!\Zn" -1 -1
  84. fi
  85.  
  86. dialog --colors --backtitle "$BACKTITLE" --infobox "You may now remove your usb sdcard reader/writer from your raspberry pi\
  87. and then remove the sd card from it." -1 -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement