#! /bin/bash
#this is a script to completely install NITdroid on an internet tablet
echo Welcome to the NITdroid downloader/installer script.
echo This program will do all of the following:
echo *Download the nescessary files.
echo *Create the proper filesystems and partitions.
echo *Install the rootfs and flash the proper kernel.
echo Before beginning, please remove the external SD card and plug the USB cable into the computer.
echo Downloads will begin in 30 seconds...
echo NOTE: This program should NOT be run as root.
echo It has specific parts that need to run as root.
sleep 30
#beginning of downloader script
cd /home/$USER/Desktop/
mkdir nitdroid
mkdir adb
cd nitdroid
echo Beginning downloads...
wget http://www.jakemaheu.com/flasher-3.0-static
wget http://guug.org/nit/nitdroid/rootfs-nitdroid.tar.bz2
wget http://guug.org/nit/nitdroid/zImage-nitdroid-n8x0
cd ../adb
wget http://guug.org/nit/nitdroid/adb.bz2
wget http://guug.org/nit/nitdroid/Internal_keypad.kl
bunzip2 adb.bz2
chmod a+x adb
cd ../nitdroid
#beginning of partitioning
echo Files acquired.
echo Creating filesystems...
echo [**************************************************************]
mount|grep -e /dev/sd
echo What is the last entry on that list?
echo It should look like '/dev/sd*1'.
echo Enter the answer in lowercase, with the number included.
echo [**************************************************************]
read action1
echo Now enter the same answer, but without the number on the end.
read action2
echo Once, more, enter the answer, this time with a '3' on the end.
read action3
sudo umount /dev/$action1
((sleep 10; sudo umount /dev/$action1) &)
echo [**************************************************************]
echo Wait like 10 seconds on OSes that automatically mount paritions.
echo 			*cough*ubuntu*cough*
echo [**************************************************************]
sudo sfdisk -uM /dev/$action2
sleep 10
sudo umount /dev/$action1
sleep 5
echo Creating filesystems...
sudo mkfs.msdos /dev/$action1
sudo umount /dev/$action3
sleep 5
sudo mkfs.ext3 /dev/$action3
sleep 5
echo Filesystems created...
sudo mount -t ext3 /dev/$action3 /mnt
#beginning of extraction
echo Extracting files...
sleep 3
cd /mnt
sudo tar -xjpvf /home/$USER/Desktop/nitdroid/rootfs-nitdroid.tar.bz2
ls
echo File extraction completed.
cd /
sudo umount /mnt
#beginning of flashing script
cd /home/$USER/Desktop/nitdroid/
chmod a+x flasher-3.0-static
echo Now flashing...
echo Unplug your tablet from all power sources and USB connections.
echo Plug in the USB cable without turning on the tablet.
echo Next, turn on the tablet with the USB cable plugged in by pressing
echo and holding the Home and Power buttons.
sudo ./flasher-3.0-static -f -k zImage-nitdroid-n8x0 --enable-rd-mode -R
echo Beginning cleanup...
cd ..
rm -r nitdroid
echo Cleanup complete.

