Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Defaults
- TEMPFILE=/tmp/rpsb
- BACKTITLE="Raspberry Pi SDCard Builder v0.1"
- IMGFILE=sdcard.img
- ROOTFS=raspberrypi-rootfs.tar.gz
- KERNELBLOB=kernelblob.tar.gz
- #TODO:Change to be calculated at runtime
- SDCARD=/dev/mmcblk1
- #Functions
- #TODO: create fdisk script to partition and format sdcard as 1st part FAT (200MB?), 2nd part ext3/4 (rest of sdcard)
- prep_sdcard () {
- echo "TBD:fdisk script & format"
- }
- make_mountpoints () {
- mkdir -p /mnt/p1
- mkdir -p /mnt/p2
- mount ${SDCARD}p1 /mnt/p1
- mount ${SDCARD}p2 /mnt/p2
- }
- remove_mountpoints () {
- umount /mnt/p1
- umount /mnt/p2
- rmdir /mnt/p1
- rmdir /mnt/p2
- }
- dd_imagefile () {
- # dd if=./$1 of=$2
- echo "dd if=$1 of=./$2"
- echo "TBD:dialog progress bar"
- }
- extract_tarballs () {
- tar xzvpf ./$1 -C /mnt/p1
- tar xzvpf ./$2 -C /mnt/p2
- }
- clone () {
- echo "Clone SDCard:TBD"
- }
- #Main()
- dialog --colors --backtitle "$BACKTITLE" --msgbox "This script will assist you in creating a backup \
- or new copy of your raspberry pi sd card.\nYou will need to plug a usb sdcard reader/writer \
- in to an empty usb slot on your raspberry pi or into an attached usb hub and insert a blank \
- sd card into it" -1 -1
- dialog --colors --backtitle "$BACKTITLE" --radiolist "What method of sd card creation do you want to use?" 0 0 3 \
- 1 "raw disk image " on \
- 2 "tarball" off \
- 3 "Clone" off 2>$TEMPFILE
- retval=$?
- if [ $retval -eq 0 ]; then
- choice=`cat /tmp/rpsb`
- case "$choice" in
- 1)
- dd_imagefile $SDCARD $IMGFILE
- ;;
- 2)
- prep_sdcard $SDCARD
- make_mountpoints $SDCARD
- extract_tarballs $KERNELBLOB $ROOTFS
- sync
- remove_mountpoints
- ;;
- 3)
- prep_sdcard $SDCARD
- make_mountpoints $SDCARD
- clone
- sync
- remove_mountpoints
- ;;
- esac
- else
- dialog --colors --backtitle "$BACKTITLE" --msgbox "You have decided to not build an sd card at this time \
- \n\Zb\Z1GOODBYE!\Zn" -1 -1
- fi
- dialog --colors --backtitle "$BACKTITLE" --infobox "You may now remove your usb sdcard reader/writer from your raspberry pi\
- and then remove the sd card from it." -1 -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement