RSS

 Seguime por RSS

22 abr. 2014

ISOburner a simple bash script for burn ISO images to a CD/DVD/BR and USB memstick with data verification

A new release of ISOburner, mayor changes, all optical media are burned with woodim, and other minor changes are text fixes.
#!/bin/bash
# set -e
# ISOburner version 2.4
# Description: Shell Script for burn a ISO image to a blank DVD/BD/CD or USB and verify the checksum after the burn process
# Copyright 2013 http://hackingthesystem4fun.blogspot.com.ar
# Author: SynFlag <hackingthesystem4fun@gmail.com> | irc.freenode.net - nickname: SynFlag
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
if [ -z "$*" ]; then echo "No args. Usage: ISOburner path/to/iso/foo.iso" && exit 0; fi
clear
echo -e "\n"
echo -e "\E[1;37mISOburner is a command line tool for burn a ISO image with data verification. \nFor burn a ISO to USB execute as root or using -sudo ISOburner- or -su -c 'ISOburner'-\033[0m"
echo -e "\E[1;37mCheck if the drive has a empty media, the recommended speed is 8x for DVD and CD \n\033[0m"
echo -e "\E[1;37mImage to burn: $1 \n\033[0m"
echo -e "\E[1;37mFile information: `file "$1"`\n\033[0m"
echo -e "\E[1;37mEnter 'o' for burn a CD or DVD/BR, 'u' for Memstick/PenDrive \n\033[0m"
extents=$(( $(ls -l $1 | awk '{ print $5 }') / 2048 ))
read media
case $media in
o )
        echo -e "\E[1;37mEnter a speed for burn, 2-4-8-16-24-32-48 are recommended values. Enter the number and press Intro \n\033[0m"
        read speed
        if [[ $speed -gt 0 && $speed -lt 49 ]]; then
        clear
        echo -e "\n"
        wodim -v fs=16m speed="$speed" -overburn -dao dev=/dev/sr0 driveropts=burnfree "$1"
        echo -e "\E[1;37mFinished, the drive will be ejected, re-insert please. If not happen, eject manually and re-insert please. Later press Intro \n\033[0m"
        eject 2>/dev/null
        read -p "Wait until the system mount the CD and press Intro"
        echo -e "\n"
        echo -e "\E[1;37mData verification in progress.... \n\033[0m"
        md5dvd=$(dd if=/dev/sr0 bs=2048 count="$extents" 2>/dev/null | md5sum | cut -d ' ' -f 1)
        md5iso=$(md5sum "$1" | awk '{print $1}')
            if [ "$md5dvd" == "$md5iso" ]; then
                echo -e "\e[1;32mData verified successfully, md5sum $md5dvd is the same in ISO and CD\e[0m \n"
                eject 2>/dev/null
            else
                echo -e "\e[31mData verification failed, md5sum does not match, re-burn please\e[0m \n"
            fi
            eject 2>/dev/null
            exit 0
                else echo -e "\e[31mEnter a valid speed between 1 and 32\e[0m \n" && exit 0
            fi
            ;;

u )
        if [ "$UID" -ne 0 ]; then
            echo -e "\e[31mPlease run with root privileges for memstick/PenDrive\e[0m \n"
              exit
        fi    
        echo -e "\E[1;37mDevices in the system:\033[0m"    
        devices=$(fdisk -lu | awk '{print $1}' | egrep /dev)
        echo "$devices"
        echo -e "\E[1;37mInsert a memstick/PenDrive in a USB port and press Intro\033[0m"
        read
        echo -e "\E[1;37mSelect a device from the list, i.e.: /dev/sdX where X is b-c-d\nGenerally the new device after the memstick is inserted is the correct  \n\033[0m"    
        devices=$(fdisk -lu | awk '{print $1}' | egrep /dev)
        echo "$devices"
        if [ -z "$devices" ]; then
            echo -e "\E[1;37mNo /dev devices mounted in the system, aborting. Format the memstick/PenDrive as fat32 and re-insert it\033[0m" && exit 0
        else
            read device
            clear
            echo -e "\E[1;37mWriting and verifying data in $device, wait... all data in the memstick/PenDrive will be destroyed \n\033[0m"
            dd if="$1" of="$device" bs=4M && sync
            md5usb=$(dd if="$device" bs=2048 count="$extents" 2>/dev/null | md5sum | cut -d ' ' -f 1)
            md5iso=$(md5sum "$1" | awk '{print $1}')            
                if [ "$md5usb" == "$md5iso" ]; then
                    echo -e "\e[1;32mData verified successfully, md5sum $md5usb is the same in the ISO and memstick/PenDrive.\nRemove the memstick/PenDrive\e[0m \n"
                    eject $device 2>/dev/null
                else
                    echo -e "\e[31mData verification failed, md5sum does not match, re-burn please\e[0m \n"
                fi
                exit 0
        fi
        ;;
esac
exit 0

No hay comentarios:

Publicar un comentario en la entrada

Ingresa tu comentario