Skip to content

Instantly share code, notes, and snippets.

@gdunstone
Created April 14, 2015 03:22
Show Gist options
  • Save gdunstone/bd5e64a3196f96f2989f to your computer and use it in GitHub Desktop.
Save gdunstone/bd5e64a3196f96f2989f to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -lt 1 ]
then
echo "USAGE: $0 <block device>"
exit 1
fi
devs=($1*)
read -p "about to format $1, Are you sure?" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo -e "o\nn\np\n\n\n+100M\nt\nc\nn\n\n\n\n\nw\n" | fdisk $1
mkfs.vfat $devs[1]
mkfs.ext4 $devs[2]
fi
read -p "copying over, erase everything in root and boot?" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
tmp=/tmp/spc_os_format_$RANDOM
mkdir -p $tmp/root
mkdir -p $tmp/boot
mount $devs[1] $tmp/boot
mount $devs[2] $tmp/root
tar -xf SPC-OS*.tar.gz -C $tmp
sync
umount $tmp/boot
umount $tmp/root
rm -rf $tmp
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment