All pastes #396974 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-03-16 03:34 UTC
rendered paste body
#!/bin/sh
#Created by Budh & TheX1le
#With a few code segments from Jabra and Muts
#BackTrack 2 Installer
###########################################################
#             Values                                      #
###########################################################
VERSION="0.0.3 ALPHA!"
BOOTPS=50
SWAPPS=512
ROOTPS=3072                 #not implimented yet
#SOURCE=
#ROOT=
#BOOT=
INPUT=$*
PROG=`basename $0`
###########################################################
# Displays script version                                 #
###########################################################
pversion() {
	echo "version $VERSION"
	exit 0
}
###########################################################
#                display script proper usage              #
###########################################################
usage() {
	clear
	echo " usage: $PROG [options]"
	echo " "
	echo "  -f   --format           Format Disk"
	echo "  -h   --help             Show the help message"
	echo "  -i   --interactive      Interactive step by step install mode"
	echo "  -d   --disk             Install Disk IE hda or sda"
	echo "  -v   --version          Show the version"
	echo " "
	exit 0
}
###########################################################
#user input for commandline arguments                     #
###########################################################
script_arg() {
	case "$INPUT" in
		-f|--format)
			budh_fdisk
		;;
		-i|--interactive)
			usr_input
		;;
		-d|--disk)
			non_usr_input
		;;
		-h|--help)
			echo "NOT YET CREATED"
		;;
		-v|--version)
			pversion
		;;
		*)
			usage
		;;
	esac
}
###########################################################
# NonInteractive Input                                    #
###########################################################
#should read the install disk to feed to rest of script not sure how to impliment yet
non_usr_input() {
	echo "Place Holder"
}
###########################################################
#                     Budh's Fdisk                        #
###########################################################
# NOT FULLY DYNAMIC YET!
budh_fdisk() {
	#Simple shell function that creates the partition for Backtrack HD Install using Parallels
	#Author: Budh, budh -at- nagologic -dot- com
	echo "Welcome, this 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 BOOTPS 
	echo -n "Swap Partition size in MB ie 1GB = 1024MB (default 512) "; read SWAPPS   
	echo -n "ROOT Partition size in MB ie 1GB = 1024MB"; read ROOTPS       
	#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 0
		fi
	echo "Creating the partitions..."
	ERRMSG=$(echo -e "\033[31m Partition creation failed on")
	SUCMSG=$(echo "Partition creation was successfull")
	fdisk /dev/hda <<< $'n\np\n1\n\n+'"$BOOTPS"$'M\nn\np\n2\n\n+'"$SWAPPS"$'M\n\nn\np\n3\n\n\n\na\n1\nt\n2\n82\nw\nq\n' >/dev/null
	errcsk
	fdisk /dev/hda <<< $'p\nq\n'
	echo "Formating the drives..."	
	ERRMSG=$(echo -e "\033[31m mkfs.ext3 failed")
	SUCMSG=$()
	mkfs.ext3 /dev/hda1 >/dev/null
	errcsk
	ERRMSG=$(echo -e "\033[31m mkfs.ext3 failed")
	SUCMSG=$()
	mkfs.ext3 /dev/hda3 >/dev/null
	errcsk
	mkswap /dev/hda2
	swapon /dev/hda2
exit 0
}
###########################################################r
# Error checking Function, based on ouput codes ie        #
#       0=success any thing is is failure                 #
###########################################################
errcsk() {
	if [ "$?" -na 0 ]; then
		echo $ERRMSG
		exit
	else
		echo $SUCMSG
	fi
}
###########################################################
#          Interactive User Input                         #
###########################################################
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_val
}
###########################################################
#    Input Validation Chk for null value                  #
###########################################################
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
	mount_an_chk
}
###########################################################
#  Mounts Partitons and checks that they exist"           #
###########################################################
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
cp_root
}
###########################################################
# Creats new install / with files and folder              #
###########################################################
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
	chrooted
}
###########################################################
#         Chroot Function                                 #
###########################################################
#Not yet Implimented BUDH WHERE IS MY SOLUTION!
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   ###############     #####
###########################################################
script_arg