Info:
By James D. McDaniel, 1 Year ago, written in Bash. This post will never expire.
- #!/bin/bash
- #: Title : S.C.L.U. - SuSE Create Live USB
- #: Date Created: Mon Dec 12 20:11:40 CST 2011
- #: Last Edit : Thu Dec 22 19:59:40 CST 2011
- #: Author : James D. McDaniel
- #: Version : 1.10
- #: Description : Create LiveUSB Thumb Drive from LiveCD/DVD ISO File
- #: Options : None
- TITLE="S.C.L.U. - SuSE Create Live USB - Version 1.10"
- #
- # Written for the openSUSE forums on Thursday December 22, 2011
- #
- #
- # Copy and Paste the text of this script into a text editor and save
- # it as the file sclu in the folder ~/bin (/home/username/bin).
- # This script must be marked executable to be used. Please run
- # the following Terminal command: chmod +x ~/bin/sclu
- #
- declare -a TDD
- declare -a TDS
- declare -a TDU
- declare -a TDN
- declare -a ISO
- declare -a ISOFiles
- declare -a ISODir
- #
- # Maximum Thumb Drive size in Gigabytes or GB *********************************
- #
- MaxTDSize=34
- #
- # Where to Download ISO Images ************************************************
- #
- Downloads="$HOME/Downloads"
- #
- # ISO Download URL & Names ****************************************************
- #
- NumISOs=12
- ISODir[1]="http://download.opensuse.org/pub/opensuse/distribution/12.1/iso/"
- ISO[1]="openSUSE-12.1-KDE-LiveCD-i686.iso,1"
- ISO[2]="openSUSE-12.1-KDE-LiveCD-x86_64.iso,1"
- ISO[3]="openSUSE-12.1-GNOME-LiveCD-i686.iso,1"
- ISO[4]="openSUSE-12.1-GNOME-LiveCD-x86_64.iso,1"
- ISO[5]="openSUSE-12.1-DVD-i586.iso,1"
- ISO[6]="openSUSE-12.1-DVD-x86_64.iso,1"
- ISODir[2]="http://download.opensuse.org/pub/opensuse/distribution/11.4/iso/"
- ISO[7]="openSUSE-11.4-KDE-LiveCD-i686.iso,2"
- ISO[8]="openSUSE-11.4-KDE-LiveCD-x86_64.iso,2"
- ISO[9]="openSUSE-11.4-GNOME-LiveCD-i686.iso,2"
- ISO[10]="openSUSE-11.4-GNOME-LiveCD-x86_64.iso,2"
- ISO[11]="openSUSE-11.4-DVD-LiveCD-i686.iso,2"
- ISO[12]="openSUSE-11.4-DVD-LiveCD-x86_64.iso,2"
- #
- # Do you want to see S.C.L.U. in color? **************************************
- # The default is true, but can be set to false ********************************
- #
- use_color=true
- #
- # Color Display Request - color forground background [b/n] ********************
- #
- # 0:Black 1:Blue 2:Green 3:Cyan 4:Red 5:Magenta 6:Yellow 7:White
- function color {
- if [[ $3 == [Bb] ]] ; then
- tput bold
- fi
- if [[ $3 == [Nn] ]] ; then
- tput sgr0
- fi
- if $use_color ; then
- tput setf $(( $1 ))
- tput setb $(( $2 ))
- else
- tput setf 7
- tput setb 0
- fi
- return 0
- }
- #
- # This is the standard GPL Statement, leave at the top of the script.
- # Just use the command show_gpl after this function for it to be shown.
- #
- function show_gpl {
- echo ""
- echo "S.C.L.U. is a bash script file written to be used with openSUSE."
- echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
- echo ""
- echo "This program is free software; you can redistribute it and/or modify"
- echo "it under the terms of the GNU General Public License as published by"
- echo "the Free Software Foundation; either version 2 of the License, or"
- echo "(at your option) any later version."
- echo ""
- echo "This program is distributed in the hope that it will be useful,"
- echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
- echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
- echo "GNU General Public License for more details."
- echo ""
- echo "You should have received a copy of the GNU General Public License"
- echo "along with this program; if not, write to the Free Software"
- echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
- echo ""
- }
- #
- # Common S.C.L.U. Header display **************************************************
- #
- function sclu_header {
- dash1="------------------------------------------------------"
- clear
- color 2 0 B
- echo $dash1
- color 7 2 B
- echo " $TITLE "
- color 2 0 B
- echo $dash1
- color 7 0 B
- echo
- return 0
- }
- #
- # Create a String of spaces ***************************************************
- #
- function spad {
- spaces=""
- len=$1
- total=1
- while [ $total -le $len ] ; do
- spaces=$spaces" "
- let total=total+1
- done
- return 0
- }
- #
- # Pad string with spaces on right *********************************************
- #
- function rpad {
- rword="$1"
- len=$2
- wlen=${#rword}
- if [ ${#rword} -lt $len ] ; then
- let len2=len-wlen
- space=""
- while [ $len2 -gt 0 ] ; do
- space="$space "
- let len2=len2-1
- done
- rword="$rword$space"
- fi
- return 0
- }
- #
- # Pad string with spaces on left **********************************************
- #
- function lpad {
- lword="$1"
- len=$2
- wlen=${#lword}
- if [ ${#lword} -lt $len ] ; then
- let len2=len-wlen
- space=""
- while [ $len2 -gt 0 ] ; do
- space=" "$space
- let len2=len2-1
- done
- lword="$space$lword"
- fi
- return 0
- }
- #
- # Check for the existance of the selected Downloads Folder ********************
- #
- function check_downloads {
- if [[ ! -d "$Downloads" ]] ; then
- color 7 4 B
- echo "The ISO Download Folder: $Downloads, does not exist!"
- color 7 0 B
- echo
- echo -n "Do You wish for this folder to be created for you? (y/N): "
- read CHOICE
- if [[ $CHOICE == [Yy] ]] ; then
- mkdir -p $Downloads
- else
- echo
- echo "Please create or change this folder name in script & restart $(basename $0) again."
- echo
- exit 1
- fi
- fi
- }
- #
- # Check to see if we are root ************************************************
- #
- if [[ $UID -ne 0 ]]; then
- check_downloads
- color 7 4 B
- id -Gn | grep -q wheel || echo "Root User Permissions are required, Please Enter the ..."
- color 7 0 B
- echo
- sudo $0 $Downloads
- Exit_Code=$?
- show_gpl
- echo
- read -p "Press <enter> to Exit S.C.L.U. ..."
- exit $Exit_Code
- else
- if [ "$1" != "" ] ; then
- Downloads="$1"
- fi
- fi
- #
- # Determine if the package dd_rescue is installed ***********************************
- #
- which dd_rescue > /dev/null
- Exit_Code=$?
- if [ $(( Exit_Code )) -ge 1 ] ; then
- color 7 4 B
- echo "The dd_rescue Utility Package is not installed!"
- color 7 0 B
- echo
- echo -n "Would you like to install the dd_rescue package(y/N)? "
- read CHOICE
- if [[ $CHOICE == [Yy] ]] ; then
- sudo zypper in dd_rescue
- else
- color 7 4 B
- echo
- echo "The dd_rescue Utility Package was not installed!"
- color 7 0 B
- exit 1
- fi
- fi
- #
- # Determine if the package aria2c is installed ***********************************
- #
- which aria2c > /dev/null
- Exit_Code=$?
- if [ $(( Exit_Code )) -ge 1 ] ; then
- color 7 4 B
- echo "The aria2 Utility Package is not installed!"
- color 7 0 B
- echo
- echo -n "Would you like to install the aria2 package(y/N)? "
- read CHOICE
- if [[ $CHOICE == [Yy] ]] ; then
- sudo zypper in aria2
- else
- color 7 4 B
- echo
- echo "The aria2 Utility Package was not installed!"
- color 7 0 B
- exit 1
- fi
- fi
- #
- # Determine if the package wget is installed ***********************************
- #
- which wget > /dev/null
- Exit_Code=$?
- if [ $(( Exit_Code )) -ge 1 ] ; then
- color 7 4 B
- echo "The wget Utility Package is not installed!"
- color 7 0 B
- echo
- echo -n "Would you like to install the wget package(y/N)? "
- read CHOICE
- if [[ $CHOICE == [Yy] ]] ; then
- sudo zypper in wget
- else
- color 7 4 B
- echo
- echo "The wget Utility Package was not installed!"
- color 7 0 B
- exit 1
- fi
- fi
- #
- # Determine file size *********************************************************
- # $2 is KB (1000), K (1024), MB (1000*1000), M (1024*1024), and so on for G, T, P, E, Z, Y.
- #
- function file_size {
- if [ -e "$1" ] ; then
- filesize=$(ls -l --block-size=$2 $1 | awk -F " " '{ print $5 }')
- else
- let filesize=0
- fi
- }
- #
- # Error message if no Thumb Drive is found ************************************
- #
- function no_drive_found {
- echo
- echo
- color 7 4 B
- echo -n "No USB connected Thumb Drive was found! Press Any Key to Exit!"
- color 7 0 B
- read something
- exit 1
- }
- #
- # Determine if we have an online connection ***********************************
- #
- function are_we_online {
- wget -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
- if [ ! -s /tmp/index.google ];then
- online=false
- else
- online=true
- fi
- }
- #
- # Determine Thumb Drive designation *****************************************
- #
- sclu_header
- echo -n "Please Wait while your Drives are being Scaned .... "
- size=$(grep -Ff <(hwinfo --disk --short) <(hwinfo --usb --short) | grep -c "/dev/")
- if [ $size -ge 1 ] ; then
- inc=1
- offset=0
- tot1=0
- tot2=0
- while [ $inc -le $size ] ; do
- TDD[$inc-$offset]=$(grep -Ff <(hwinfo --disk --short) <(hwinfo --usb --short) | grep "/dev/" | awk '{print $1}'| sed -n $(( inc ))p)
- TDN[$inc-$offset]=$(grep -Ff <(hwinfo --disk --short) <(hwinfo --usb --short) | grep "/dev/" | sed -n $(( inc ))p)
- TDNL=${#TDN[$inc-$offset]}
- TDN[$inc-$offset]=${TDN[$inc-$offset]:22:$TDNL-23}
- TDS[$inc-$offset]=$(fdisk -l ${TDD[$inc-$offset]} | grep "Disk /" | awk '{print $3}')
- TDU[$inc-$offset]=$(fdisk -l ${TDD[$inc-$offset]} | grep "Disk /" | awk '{print $4}')
- TDU[$inc-$offset]=${TDU[$inc-$offset]:0:2}
- if [ "${TDS[$inc-$offset]}" == "" ] ; then
- let offset=offset+1
- else
- TDNL=${#TDN[$inc-$offset]}
- if [ $TDNL -gt $tot1 ] ; then
- let tot1=$TDNL
- fi
- TDSL=${#TDS[$inc-$offset]}
- if [ $TDSL -gt $tot2 ] ; then
- let tot2=$TDSL
- fi
- TDSIZE=${TDS[$inc-$offset]}
- if [ "${TDU[$inc-$offset]}" == "MB" ] ; then
- let TDSIZE=$(( TDSIZE / 1000 ))
- fi
- TDSIZE=$(echo "$TDSIZE" | awk '{printf("%d\n",$1 + 0.5)}')
- if [ $TDSIZE -gt $MaxTDSize ] ; then
- let offset=offset+1
- fi
- fi
- let inc=inc+1
- done
- let size=size-offset
- if [ $size -le 0 ] ; then
- no_drive_found
- fi
- inc=1
- let tot1=tot1+3
- while [ $inc -le $size ] ; do
- rpad "${TDN[$inc]}" $tot1
- TDN[$inc]="$rword"
- lpad "${TDS[$inc]}" $tot2
- TDS[$inc]="$lword"
- let inc=inc+1
- done
- else
- no_drive_found
- fi
- #
- # Drive Selection Menu ********************************************************
- #
- tmenu=true
- let tot1=tot1-6
- spad $tot1
- while $tmenu ; do
- sclu_header
- color 7 0 B
- echo -n " "
- color 7 1 B
- echo "USB Drive Listing - Select Only a Thumb Drive"
- color 7 0 B
- echo
- if [ $size -gt 1 ] ; then
- echo " Device Name $spaces Size"
- echo
- inc=1
- while [ $inc -le $size ] ; do
- color 7 0 B
- echo -n " "
- color 6 1 B
- echo "$inc) ${TDD[$inc]} ${TDN[$inc]} ${TDS[$inc]} ${TDU[$inc]}"
- let inc=inc+1
- done
- color 7 0 B
- echo
- echo -n " Enter Drive # to use [1-$size] (Q=Quit):"
- read CHOICE
- else
- CHOICE=$size
- fi
- if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
- if [[ $CHOICE -le $size ]] && [[ $CHOICE -gt 0 ]]; then
- sclu_header
- ThumbDrive=${TDD[$CHOICE]}
- TSize="${TDS[$CHOICE]} ${TDU[$CHOICE]}"
- TName=${TDN[$CHOICE]}
- echo -n " You Selected Thumb Drive: "
- color 6 1 B
- TDSize=$(echo ${TDS[$CHOICE]} | awk '{print $1}')
- echo "$ThumbDrive - $TDSize ${TDU[$CHOICE]}"
- echo
- color 7 0 B
- echo -n " Is this the correct Thumb Drive to use? (y/N)"
- read CHOICE
- if [[ $CHOICE == [Yy] ]] ; then
- tmenu=false
- fi
- if [[ $CHOICE == [Nn] ]] ; then
- if [ $size -eq 1 ] ; then
- exit 0
- fi
- fi
- fi
- fi
- if [[ $CHOICE == [Qq] ]] ; then
- tmenu=false
- exit 0
- fi
- done
- #
- # Determine if the Thumb Drive is mounted ************************************
- #
- if mount|grep $ThumbDrive > /dev/null ; then
- echo
- color 7 4 B
- echo "Your Thumb Drive $ThumbDrive is mounted and must be un-mounted!"
- color 7 0 B
- echo
- echo -n "Would you like to un-mount your Thumb Drive $ThumbDrive (y/N)?: "
- read CHOICE
- if [[ $CHOICE == [Yy] ]] ; then
- umount $ThumbDrive"1"
- else
- echo
- color 7 4 B
- echo "Your Thumb Drive $ThumbDrive can't be used while mounted!"
- color 7 0 B
- exit 1
- fi
- fi
- #
- # ISO Slection Menu Starts Here ********************************************
- #
- imenu=true
- while $imenu ; do
- sclu_header
- color 7 0 B
- echo -n " "
- color 6 1 B
- echo " openSUSE CD/DVD ISO Image Selection menu "
- color 7 0 B
- echo
- inc=1
- while [ $inc -le $NumISOs ] ; do
- echo -n " $inc) "
- echo ${ISO[$inc]} | awk -F "\"*,\"*" '{print $1}'
- let inc=inc+1
- done
- color 7 0 B
- echo
- echo -n " "
- color 7 1 B
- echo -n "Enter ISO # to use [1-$NumISOs] (L=Local & Q=Quit):"
- color 7 0 B
- read CHOICE
- if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
- if [[ $CHOICE -le $NumISOs ]] && [[ $CHOICE -gt 0 ]]; then
- ISOName=$(echo ${ISO[$CHOICE]} | awk -F "\"*,\"*" '{print $1}')
- imenu=false
- fi
- fi
- if [[ $CHOICE == [Qq] ]] ; then
- imenu=false
- exit 0
- fi
- #
- # Select ISO from File listing ************************************************
- #
- if [[ $CHOICE == [Ll] ]] ; then
- counter=0
- cd $Downloads
- sclu_header
- echo -n " Using ISO Folder: "
- color 3 0 B
- echo $Downloads
- echo
- color 7 0 B
- for i in *.iso ; do
- if [ -f $i ] ; then
- let counter=counter+1
- ISOFiles[$counter]=$i
- echo -n " $counter) "
- color 3 0 B
- echo ${ISOFiles[$counter]}
- color 7 0 B
- fi
- done
- if [[ $counter -eq 0 ]]; then
- echo
- color 7 4 B
- echo "No ISO Files were found!"
- color 7 0 B
- echo
- read -p "Press any Key to Continue" something
- CHOICE=0
- else
- echo
- color 7 1 B
- echo -n "Please Select the ISO File You wish to use (q=Quit): "
- color 7 0 B
- read CHOICE
- fi
- if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
- if [[ $CHOICE -le $counter ]] && [[ $CHOICE -gt 0 ]]; then
- ISOName=${ISOFiles[$CHOICE]}
- if [ ! -e "$Downloads/$ISOName" ] ; then
- echo
- color 7 4 B
- read -p "$ISOName was Not Found. Press Any Key to Continue" something
- color 7 0 B
- else
- imenu=false
- fi
- fi
- else
- if [[ $CHOICE == [Qq] ]] ; then
- exit 0
- fi
- fi
- fi
- done
- #
- # Download ISO File from here *************************************************
- #
- sclu_header
- if [ ! -e $Downloads/$ISOName ] ; then
- color 7 1 B
- echo "Downloading: $ISOName,"
- echo "Please Wait for the download to complete..."
- color 7 0 B
- echo
- cd $Downloads
- ISOSet=$(echo ${ISO[$CHOICE]} | awk -F "\"*,\"*" '{print $2}')
- are_we_online
- if $online ; then
- aria2c --allow-overwrite=true --summary-interval=0 -x5 "${ISODir[$ISOSet]}$ISOName" 2>/dev/null
- else
- echo
- color 7 4 B
- read -p "We Do Not Appear to have an online Connection. Press any key to exit!" something
- color 7 0 B
- exit 1
- fi
- fi
- #
- # Determine if ISO File Downloaded properly ***********************************
- #
- if [ -e $Downloads/$ISOName ] ; then
- file_size "$Downloads/$ISOName" "MB"
- color 7 1 B
- echo " Download of: $ISOName,"
- echo " was successful (or was previously completed) ... "
- color 7 0 B
- echo
- echo -n " The ISO filesize is:"
- color 3 0 B
- echo " $filesize"
- else
- color 7 4 B
- echo "Download of $ISOName was Not successful... "
- color 7 0 B
- echo
- read -p " Press Any Key to Exit S.C.L.U."
- exit 1
- fi
- color 7 0 B
- echo
- read -p " Press Any Key to Continue ..."
- #
- # Create USB Bootable Thumb Drive *******************************************
- #
- sclu_header
- color 7 4 B
- echo "Warning, you are about to write an ISO image to Your, "
- echo
- color 7 0 B
- echo -n "Thumb Drive:"
- color 3 0 B
- echo " $ThumbDrive $TSize $TName"
- echo
- color 7 4 B
- echo "All Data on your Thumb Drive will be over written!!!!!"
- echo
- color 7 1 B
- echo "You have selected the CD or DVD image which is called:"
- echo
- color 7 0 B
- echo -n "ISO File Named:"
- color 3 0 B
- echo " $ISOName "
- color 7 0 B
- echo
- echo -n "The ISO FileSize is: "
- color 3 0 B
- echo $filesize
- echo
- color 7 0 B
- read -p " Do you wish to Continue? (y/N) Q=Quit: " CHOICE
- echo
- if [[ $CHOICE == [Qq] ]] ; then
- exit 0
- fi
- if [[ $CHOICE == [Yy] ]] ; then
- dd_rescue -A "$Downloads/$ISOName" "$ThumbDrive"
- fi
- echo
- color 7 1 B
- read -p "Writing to your Thumb Drive is Complete. Press Any Key to Exit." CHOICE
- color 7 0 B
- tput clear
- exit 0
- # End Of Script
