Skip to content

Instantly share code, notes, and snippets.

@gdunstone
Created April 14, 2015 07:45
Show Gist options
  • Save gdunstone/222f67f4446e2d8fb0d0 to your computer and use it in GitHub Desktop.
Save gdunstone/222f67f4446e2d8fb0d0 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -lt 1 ]
then
echo "USAGE: $0 <block device>"
exit 1
fi
read -p "About to format $1, Are you sure (y/N)?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo -e "o\nn\np\n\n\n+100M\nt\nc\nn\n\n\n\n\nw\n" | fdisk $1
devs=($1*)
echo "using $devs[1] for /boot AND $devs[2] for /root"
mkfs.vfat $devs[1]
mkfs.ext4 $devs[2]
fi
read -p "Mounting and untarring. Continue (y/N)?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
tmp=/tmp/spc_os_format_$RANDOM
echo "Mounting ..."
mkdir -p $tmp/root
mkdir -p $tmp/boot
mount $devs[1] $tmp/boot
mount $devs[2] $tmp/root
echo "Untarring: "
tar -xvf SPC-OS*.tar.gz -C $tmp --totals
echo "Syncing fs"
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