#!/bin/sh #Created by TheX1le #Fdisk Function by Budh & ? #With a few code segments from Jabra and Muts #BackTrack 2 Installer ########################################################### # Scirpt Config # ########################################################### VERSION="0.0.4 ALPHA!" #Srcipt Version number BOOTPS=50 #Boot Partition Size from user SWAPPS=512 #Swap Partiton Size from user ROOTPS=3072 #not implimented yet "Root Partion size from user SOURCE=/ #Source B|T is installing from ROOT= #Root Partion BT is installing to BOOT= #Boot Partion BT is installing to INPUT=$* # Used for taking command line arugments for Case ERRMSG="This is an error message" #general variable for storing error messages SUCMSG="This is a success message" #general variable for storing success messages YESNO= #general variable for stroing yes no responces from user PROG=`basename $0` #echos script name when script is run ########################################################### # Displays script version # ########################################################### pversion() { echo "version $VERSION" exit 0 } ########################################################### # display script proper usage # ########################################################### usage() { clear echo "WELCOME to the Back|Track 2 Installer" echo "" echo -e "\033[31m WARNING! THIS WILL FORMAT YOUR HARD DRIVE AND ERASE ALL DATA MAKE SURE YOU BACK UP YOUR SYSTEM" echo -e "\033[0m" 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() { #reads inputs from new script arguments #stores them into variables for fdisk budh_fdisk } ########################################################### # 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 YESNO if [ $YESNO = "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 #export to BOOT and ROOT #call input val to check for null variables exit 0 } ########################################################### # 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 "WELCOME to the Back|Track 2 Installer" echo -e "\033[31m WARNING! THIS WILL FORMAT YOUR HARD DRIVE AND ERASE ALL DATA MAKE SURE YOU BACK UP YOUR SYSTEM" echo "" echo -e "\033[0m 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 } ########################################################### # yesno() { if test "$YESNO" = "y" -o "$YESNO" = "yes" ; then echo "" else exit 0 fi } ########################################################### # 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 YESNO yesno 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