Skip to content

Instantly share code, notes, and snippets.

@MaiLinhGroup
Created February 4, 2019 22:25
Show Gist options
  • Save MaiLinhGroup/c051d93cf0d517950037bd94d9c8e172 to your computer and use it in GitHub Desktop.
Save MaiLinhGroup/c051d93cf0d517950037bd94d9c8e172 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Set up raspbian image on sd card:"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
#use df -h to discover all partitions of the sd card
#umount all partitions first before keep going
df -h
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "unmount all partitions of the sd card first"
read -p "partitions: " partitions
umount $partitions
#setup raspbian image
echo "download latest raspbian image and decompresse it"
wget -S https://downloads.raspberrypi.org/raspbian_latest && unzip raspbian_latest -d .
raspbian_img=$(ls -t -U *-raspbian-jessie.img)
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "copying the image to the sd card"
read -p "dd destination:" destination
dd bs=4M if=$raspbian_img of=$destination
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "checking the image copy progress"
dd bs=4M if=$destination of=from-sd-card.img
truncate --reference $raspbian_img from-sd-card.img
diff -s from-sd-card.img $raspbian_img
sync
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Write cache is flushed, it is safe to unmount sd card now!"
echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
#remove image after setup
rm -f raspbian_latest && echo "rm raspbian_latest"
rm -f $raspbian_img && echo "rm raspbian_img"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment