All pastes #395105 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-03-14 20:15 UTC
rendered paste body
#!/bin/sh
#Created by Budh & TheX1le
#BackTrack 2 Installer
#Alpha 3.0
############################################################
#               Configs                                    #
############################################################
PROG=`basename $0`
############################################################
# display proper usage                                     #
############################################################
usage() {
    echo " usage: $PROG [options]"
    echo " "
    echo "  -f   --file FILE        Config file to be used"
    echo "  -h   --help             Show the help message"
    echo "  -i   --interactive      Interactive mode"
    echo "  -s   --scan             Scan for wireless networks"
    echo "  -v   --version          Show the version"
    echo " "
    exit 0
}
######################################################################################
#                                  Budh  Fdisk                                       #
######################################################################################
function budh_fdisk {
	#Simple shell script that creates the partition for Backtrack HD Install using Parallels
	#Author: Budh, budh -at- nagologic -dot- com
	echo "Welcome, this script will set up your hard drives to install Backtrack2"
	echo "First we need to know what sizes you want your partitions to be"
	echo -n "Boot Partition size in MB ie 1GB = 1024MB (default 50): "; read BOOTP 
	echo -n "Swap Partition size in MB ie 1GB = 1024MB (default 512)"; read SWAPP   
	#echo -n "ROOT Partition size in MB ie 1GB = 1024MB"; read ROOTP       
	#Warns the user that formatting procedure is taking place.
	clear
	echo "WARNING!!"
	echo "This procedure will wipe the content of the current hard drive."
	echo -n "Are you sure you want to continue. (y/n): "; read sAnswer
	if [ $sAnswer = "n" ] ; then
              echo "Leaving..."
              exit
	fi
      echo "Creating the partitions..."
	fdisk /dev/hda <<< $'n\np\n1\n\n+'"$BOOTP"$'M\nn\np\n2\n\n+'"$SWAPP"$'M\n\nn\np\n3\n\n\n\na\n1\nt\n2\n82\nw\nq\n' >/dev/null
	if [ "$?" != "0" ]; then
		echo "Partition creation failed on"
		exit
	else
		echo "Partition creation was successfull"
		fdisk /dev/hda <<< $'p\nq\n'
	fi;
      echo "Formating the drives..."
      mkfs.ext3 /dev/hda1 >/dev/null
	if [ "$?" != "0" ]; then
		echo "mkfs.ext3 failed"
		exit
	fi
	mkfs.ext3 /dev/hda3 >/dev/null
	if [ "$?" != "0" ]; then
		echo "mkfs.ext3 failed"
		exit
	fi
	mkswap /dev/hda2
	swapon /dev/hda2
	echo "Mounting partition..."
	mkdir /tmp/boot
	mkdir /tmp/BT2f
	mount /dev/hda1 /tmp/boot
	mount /dev/hda3 /tmp/BT2f
	echo "Script is completed..."
	exit 0
}
######################################################################################
# Error checking Function, based on ouput codes ie 0=success any thing is is failure #
######################################################################################
function errcsk {
if [ "$?" != "0" ]; then
	echo $ERRMSG
	exit
else
	echo $SUCMSG
fi
}
######################################################################################
#                             User Input Section                                     #
######################################################################################
function usr_input {
clear
echo "This simple script is just for installing bt2, it assumes you have created and formatted 
your partitions all ready. Version BETA 2" 
#Handles input of boot and root partitions
echo "Your Source for BT files EX. /"
read SOURCE
echo "Your boot partition EX. hda1" 
read BOOT
echo "Your root partition EX. hda3"
read ROOT
clear
}
######################################################################################
#                            Input Validation Chk                                    #
######################################################################################
function input_val {
if [ -z "$SOURCE" ]; then
	echo "Please set a source"
	exit
else
	if [ -z "$BOOT" ]; then
		echo "Please set a boot Destination"
		exit
	else
		if [ -z "$ROOT" ]; then
			echo "Please set a root Destination"
			exit
		fi
	fi
fi
}
######################################################################################
#                    Mounts Partitons and checks that they exist"                    #
######################################################################################
function mount_an_chk {
 if [ "$BOOT" == "$ROOT" ]; then
 	echo -e "This is not the best recomended install method. Continue? [y/n]"
	read YES
	if [ "y" != "$YES" ]; then
		exit
	fi
	echo "Mounting Drive"
 	ERRMSG=$(echo -e "\033[31m Mounting failed check your partitions")
 	SUCMSG=$(echo "Drive mounted sucessfully")
 	mount /dev/$ROOT /tmp/backtrack
 	errcsk
 else
 	echo "Mounting Drives"
 	mount /dev/$BOOT /tmp/backtrack/boot
 	mount /dev/$ROOT /tmp/backtrack
 	ERRMSG=$(echo -e "\033[31m Mounting failed check your partitions")
 	SUCMSG=$(echo "Drives mounted sucessfully")
 	mount /dev/$ROOT /tmp/backtrack
 	errcsk
 fi
}
######################################################################################
#                     Creats new install / with files and folders                    #
######################################################################################
function cp_root {
mkdir -p /tmp/backtrack/boot
cp --preserve -R -v $SOURCE/{bin,dev,home,pentest,root,usr,etc,lib,opt,sbin,var} /tmp/backtrack
ERRMSG=$(echo -e "\033[31m Files did not copy correctly there were some errors")
SUCMSG=$(echo "Backtrack files copied sucessfully")
errcsk
mkdir /tmp/backtrack/{mnt,proc,sys,tmp}
ERRMSG=$(echo -e "\033[31m mnt,proc,sys,tmp failed to be made there was an error")
SUCMSG=$(echo "mnt,proc,sys,tmp created sucessfully")
errcsk
cp "$SOURCE"/boot/vmlinuz /tmp/backtrack/boot
ERRMSG=$(echo -e "\033[31m Kernel did not copy correctly there was an error")
SUCMSG=$(echo "Kernel copied sucessfully")
errcsk
read -p "Backtrack copied to hard drive successfully press the ANY KEY to continue"
clear
echo "mounting dev and proc"
mount --bind /dev/ /tmp/backtrack/dev/
mount -t proc proc /tmp/backtrack/proc/
ERRMSG=$(echo -e "\033[31m dev or proc failed to mount there was an error")
SUCMSG=$(echo "dev and proc mounted sucessfully")
errcsk
}
######################################################################################
#                                    Chroot Function                                 #
######################################################################################
function chrooted {
echo "your next step is to chroot into your new install IE [chroot 
/tmp/backtrack/ /bin/bash], then edit /etc/lilo.conf and run lilo -v . 
Thats it your installed"
}
######################################################################################
#####     #############################   Main   ###########################     #####
######################################################################################
usage
#usr_input
#input_val
#mount_an_chk
#cp_root
#chrooted