164 lines
4.7 KiB
Bash
164 lines
4.7 KiB
Bash
#!/bin/bash
|
|
#Check for root
|
|
if [[ $EUID -ne "0" ]]
|
|
then
|
|
echo "You must be root - try: sudo $0 or sudo bash $0"
|
|
exit 1
|
|
fi
|
|
|
|
#check for wipefs
|
|
command -v wipefs >/dev/null 2>&1 || { echo >&2 "I require wipefs but it's not installed. Aborting."; exit 1; }
|
|
|
|
script="$0"
|
|
basename="$(dirname $script)"
|
|
DIR="/home/temp/smrusb"
|
|
|
|
#Warn user that this will detroit the things
|
|
echo "This will destroy all data and partitions on the device name you enter without further warning!!"
|
|
|
|
#get device name
|
|
echo "Please enter the device you wish to use (/dev/sdX):"
|
|
read dev
|
|
device=${dev}1
|
|
|
|
echo "Unmounting $device Partitions..."
|
|
for part in $dev*
|
|
do umount $part > /dev/null 2>&1
|
|
done
|
|
#umount $device
|
|
DD="${device:0:7}"
|
|
if [ "$DD" == "/dev/sd" ];
|
|
then
|
|
echo ""
|
|
else
|
|
echo "Bad device - must start with /dev/sd"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ${device:8:1} == 0 ]
|
|
then
|
|
echo "Bad Partition! should end in the number 1 or 2 - e.g. /dev/sdc1"
|
|
exit1
|
|
fi
|
|
|
|
#format device
|
|
|
|
echo "Partitioning: $dev"
|
|
read -p "Proceed with partitioning (y/n): " opinion2
|
|
if [[ $opinion2 == 'y' ]] || [[ $opinion2 == 'yes' ]]
|
|
|
|
then
|
|
|
|
#umount $device > /dev/null 2>&1
|
|
label="RESCUE-USB"
|
|
|
|
##Remove existing data/partitions
|
|
echo "Removing existing partitions and data from $dev..."
|
|
#dd if=/dev/zero of=$dev bs=512 count=1 conv=notrunc > /dev/null 2>&1
|
|
wipefs -a $dev > /dev/null 2>&1
|
|
|
|
##Create partition table
|
|
echo "Creating partition table..."
|
|
parted $dev --script -- mklabel msdos > /dev/null 2>&1
|
|
|
|
##Create partitions
|
|
echo "Creating partitions on $device..."
|
|
parted $dev --script -- mkpart primary 0% 90% > /dev/null 2>&1
|
|
parted $dev --script -- mkpart primary 91% 100% > /dev/null 2>&1
|
|
|
|
#Create /home/temp if it doesn't exist
|
|
echo "Creating working directory of $DIR..."
|
|
mkdir -p $DIR
|
|
|
|
#Fetch Easy2Boot
|
|
echo "Fetching Easy2Boot..."
|
|
wget -O $DIR/E2B.zip "http://files.sysres.liquidweb.com/usbkey/smrusb-4-0/Easy2Boot_v1.93A.zip" > /dev/null 2>&1
|
|
|
|
#Extract it
|
|
echo "Extracting Easy2Boot..."
|
|
unzip -d $DIR/ $DIR/E2B.zip > /dev/null 2>&1
|
|
|
|
#Remove the zip
|
|
echo "Removing Easy2Boot zip..."
|
|
rm -f $DIR/E2B.zip > /dev/null 2>&1
|
|
|
|
echo "Formatting primary partition..."
|
|
#Run E2B's fmt.sh
|
|
/sbin/mkfs.vfat -F32 -n "$label" $device > /dev/null 2>&1
|
|
ptn=${device: -1}
|
|
echo Making partition "$ptn" active using parted...
|
|
sudo parted -s ${device%?} set $ptn boot on > /dev/null 2>&1
|
|
sleep 2
|
|
sync
|
|
sleep 5
|
|
|
|
echo "Mounting $device as /mnt/myusb"
|
|
mkdir -p /mnt/myusb 2>/dev/null
|
|
mount $device /mnt/myusb > /dev/null 2>&1
|
|
|
|
|
|
echo "Installing grub4dos to MBR"
|
|
chmod +rwx $DIR/_ISO/docs/linux_utils/bootlace.com > /dev/null 2>&1
|
|
$DIR/_ISO/docs/linux_utils/bootlace.com --time-out=0 ${device%?} > /dev/null 2>&1
|
|
echo "Installing grub4dos to PBR"
|
|
$DIR/_ISO/docs/linux_utils/bootlace.com --floppy=1 $device > /dev/null 2>&1
|
|
|
|
echo "Copying $DIR to /mnt/myusb..."
|
|
cp -r -i $DIR/* /mnt/myusb > /dev/null 2>&1
|
|
|
|
#Fetch ISOs to device
|
|
echo "Copying ISOs from files.sysres to the USB..."
|
|
pushd /mnt/myusb/_ISO/MAINMENU/ > /dev/null 2>&1
|
|
wget -nd -e robots=off -r --no-parent /mnt/myusb/_ISO/MAINMENU/ http://files.sysres.liquidweb.com/iso/for-usb/ --reject index.htm* > /dev/null 2>&1
|
|
wget -nd -e robots=off -r --no-parent /mnt/myusb/_ISO/MAINMENU/ http://repo.win.liquidweb.com/tools/WinPE_Fixer.iso --reject index.htm* > /dev/null 2>&1
|
|
popd > /dev/null 2>&1
|
|
|
|
#Use E2B's defragger
|
|
echo "Defragmenting the drive and ISOs..."
|
|
chmod +x $DIR/_ISO/docs/linux_utils/defragfs > /dev/null 2>&1
|
|
|
|
$DIR/_ISO/docs/linux_utils/defragfs /mnt/myusb -f > /dev/null 2>&1
|
|
#mount WinPE iso to copy /tools dir
|
|
echo "Mounting WinPE ISO and copying tools directory..."
|
|
mkdir $DIR/isomount > /dev/null 2>&1
|
|
mount -o loop /mnt/myusb/_ISO/MAINMENU/WinPE_Fixer.iso $DIR/isomount > /dev/null 2>&1
|
|
|
|
#copy tools dir
|
|
cp -r $DIR/isomount/tools /mnt/myusb/ > /dev/null 2>&1
|
|
|
|
#unmount ISO
|
|
umount $DIR/isomount > /dev/null 2>&1
|
|
|
|
#Get files to Update Menu settings
|
|
echo "Fetching menu config files..."
|
|
wget -O /mnt/myusb/_ISO/menu_defaults.txt http://files.sysres.liquidweb.com/usbkey/smrusb-4-0/menu_defaults.txt > /dev/null 2>&1
|
|
wget -O /mnt/myusb/_ISO/MyE2B.cfg http://files.sysres.liquidweb.com/usbkey/smrusb-4-0/MyE2B.cfg > /dev/null 2>&1
|
|
|
|
#Get background
|
|
#wget -O /mnt/myusb/_ISO/mybackground.bmp http://files.sysres.liquidweb.com/usbkey/smrusb-4-0/mybackground.bmp > /dev/null 2>&1
|
|
|
|
#Remove working dir
|
|
echo "Removing working directory..."
|
|
rm -rf $DIR > /dev/null 2>&1
|
|
|
|
#unmount drive
|
|
echo "Unmounting drive..."
|
|
sleep 20
|
|
umount $dev* > /dev/null 2>&1
|
|
umount /mnt/myusb > /dev/null 2>&1
|
|
|
|
#remove mountpoint
|
|
echo "Removing mountpoint..."
|
|
rm -r /mnt/myusb > /dev/null 2>&1
|
|
|
|
#Complete
|
|
echo "Script completed, your USB has been created!"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "You said no, stopping."
|
|
exit 1
|
|
|
|
fi |