• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

kleines Bash Script zum Brennen

Hi

hab mal ein kleines Bash Script geschrieben, mit dem man in der Konsole mal eben schnell brennen kann
Vielleicht braucht es ja mal jemand :wink:

Benutzung auf eigene Gefahr

Code:
#!/bin/bash
# GNU GENERAL PUBLIC LICENSE
# Version 2, June 1991

# Copyright (C) 2004-11-25 }-Tux-{ <suse-tux@gmx.de>

#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

# Script: burn@konsole
# Version: 0.5
# Function: create and burn Images
# SPECIAL THX to oc2pus for help :)
###########################################

# Variablen
###########

# $AUSWAHL (beinhaltet die Auswhal vom Programmstart)
# $PFAD (speichert den Pfad(Ordner) von dem ein Image erstellt werden soll)
# $ZIEL (speichert den Pfad, wo das Image image.img gespeichert werden soll)
# $IMAGE (Pfad des Images für die function brennen() (wird nocht geändert)
# $DEVICE (Brenner Laufwerk)
# $SPEED (Brenngeschwindigkeit)
# $ANTWORT (in der function multi(), beinhaltet entweder start um eine neue MultiSession zu starten oder um eine fortzusetzen
# $HOME (Umgebungsvariable, Homepfad des Users, der das Script aufruft)



function AUSGABE() {
   echo -e $1
}

# Programmstart
AUSGABE "Konsolen Brennprogramm\n"
AUSGABE "======================\n\n\n"
AUSGABE "Was möchten Sie tun?\n"
AUSGABE "(I)mage Datei (*.img) erstellen"
AUSGABE "Image Datei (*.img) (B)rennen"
AUSGABE "(M)ultisession Disk brennen\n"
AUSGABE "Bitte wählen Sie (): "

read -n 1 AUSWAHL
AUSGABE "\n\n\n"


# Für die farbigen Statusmeldungen

################################################################################
# offset from right margin of the screen to start status labels at.
################################################################################
RES_OFFSET=8

################################################################################
# Enumerate colors
################################################################################
let BLACK=0 RED=1 GREEN=2 YELLOW=3 BLUE=4 MAGENTA=5 CYAN=6 WHITE=7

################################################################################
# terminal sequence to move to that position.
################################################################################
MOVE_TO_COL(){
    # `tput cols` reports 80 on dumb terms, the real width when appropriate;
    # `tput hpa N` moves to col N; on dumb terms does nothing.
    tput hpa $(( $(tput cols) - RES_OFFSET )) # Horizontal Position Absolute
}

################################################################################
################################################################################
SWITCHCOLOR(){
   tput bold;
   tput setaf $1;
}

################################################################################
# set 'success' color (currently: green)
################################################################################
SETCOLOR_SUCCESS(){
   SWITCHCOLOR $GREEN;
}

################################################################################
# set 'failure' color (currently: red)
################################################################################
SETCOLOR_FAILURE(){
   SWITCHCOLOR $RED;
}

################################################################################
# terminal sequence to reset to the default color.
################################################################################
SETCOLOR_NORMAL(){
    tput op    # set Original color Pair
    tput sgr0    # turn off all special graphics mode (bold in our case)
}

echo_success() {
   MOVE_TO_COL
   echo -n '[  '
   SETCOLOR_SUCCESS
   echo -n 'OK'
   SETCOLOR_NORMAL
   echo '  ]'
   return 0
}

################################################################################
################################################################################
echo_failure() {
   MOVE_TO_COL
   echo -n '['
   SETCOLOR_FAILURE
   echo -n 'FAILED'
   SETCOLOR_NORMAL
   echo ']'
   return 0
}

##################################################################################
# Aufruf: checkProgramm2 $VARPATH $VARPROG
##################################################################################
function checkProgramm2() {
   if [ -x "$1/$2" ]; then
      echo -e "Checking for $1/$2" && echo_success
      IMG=0
   else
      echo -e "Checking for $1/$2" && echo_failure
      PROGNAME=$2
      IMG=1
      let IMG=$IMG+1
   fi
   
   if [ "$IMG" -gt "0" ]; then
      echo -e "Bitte installieren $PROGNAME"
      exit 1
   fi
}

###################################################################################
# Function "checkProgramm2" überprüft ob die benötigten Programme installiert sind#
###################################################################################
PROGPATH="/usr/bin"
PROG1="mkisofs"
PROG2="cdrecord"

checkProgramm2 $PROGPATH $PROG1
checkProgramm2 $PROGPATH $PROG2


function errorcontrol() {
if [ "`cat $HOME/burnatkonsole.log | grep "error"`" == "" ]; then {
   AUSGABE "Brennvorgang erfolgreich abgeschlossen ! :) " && echo_success
   eject $DEVICE
   rm $HOME/burnatkonsole.log
   AUSGABE "\n\n"
}
else
   AUSGABE "Beim Brennen traten fehler auf bitte schauen Sie in $HOME/burnatkonsole.log" && echo_failure
   exit 1
   fi
}

function rohling() {
   AUSGABE "Bitte legen Sie einen Rohling ein"
   eject $DEVICE
   AUSGABE "Drücken Sie enter um den Brennvorgang zu starten: "
   read x
   eject -t $DEVICE
}

function multi_brennen(){
   rohling
   echo $SPEED
   cdrecord -v -multi -eject -driveropts=burnfree -tao dev=$DEVICE speed=$SPEED $IMAGE | tee $HOME/burnatkonsole.log
   errorcontrol
}

function ausgabe_speed() {
   AUSGABE "Die meisten Brenner unterstützen nur eine Geschwindigkeit <= 52x \n" && echo_failure && exit 1
}

function ausgabe_brenner() {
   AUSGABE "Ihr Device $DEVICE existiert nicht\n" && echo_failure
   exit 1
}

function ausgabe_speicherort() {
   AUSGABE "Ihr angegebener Speicherort zum Image: $IMAGE existiert nicht\n" && echo_failure
   exit 1
}

function speed_check() {
   if [ -z $SPEED ]; then {
      SPEED=24
   }
   elif [ "$SPEED" -le "52" ]; then {
      SPEED=$SPEED
   }
   else
      ausgabe_speed
   fi
}

function image_ziel() {
   AUSGABE "Image wird erstellt...\n"
    mkisofs -v -r -J -o $ZIEL $PFAD
   AUSGABE "Image wurde erfolgreich in $ZIEL gespeichert" && echo_success
}

function image_brennen() {
   cdrecord -v -eject -driveropts=burnfree -dao dev=$DEVICE speed=$SPEED $IMAGE | tee $HOME/burnatkonsole.log
}

##############################################
# Funktion "image" um ein Image zu erstellen##
##############################################

function image() {
   AUSGABE "Bitte machen Sie folgende Angaben:\n\n"
   AUSGABE "Quelldatei: \n"
   read PFAD
   if [ -r "$PFAD" ]; then
      clear
   else {
      AUSGABE "Ihr Speicherort: $PFAD existiert nicht" && echo_failure
      exit 1
   }
   fi
   AUSGABE "Speicherort des Images: (default: $HOME)\n"
   read ZIEL
   if [ -z $ZIEL ]; then
      ZIEL="$HOME/image.img"
      image_ziel
   elif [ -r $ZIEL ]; then {
      ZIEL="$ZIEL/image.img"
      image_ziel
   }
   else
      AUSGABE "Ihr Speicherort: $ZIEL existiert nicht" && echo_failure
      exit 1
   fi
}
# Function "image" ende

####################################################
# Function "brennen" um ein Image auf CD zu brennen#
####################################################

function brennen() {
      AUSGABE "Bitte machen Sie folgende angaben:\n\n\n"
      AUSGABE "Geben Sie den Pfad zum Image an: !!ACHTUNG!! es darf sich nur EINE *.img Datei dort befinden\n"
      read IMAGE
      HILFS_VAR=`ls $IMAGE | grep img`
      IMAGE="$IMAGE/$HILFS_VAR"
      if [ -r $IMAGE ]; then {
         AUSGABE "Ihr Brenner Device: \n"
         read -n 9 DEVICE
         if [ -r $DEVICE ]; then {
            AUSGABE "Brenngeschwindigkeit: (default 24x)\n"
            read -n 2 SPEED
            if [ "$SPEED" == "" ]; then {
               SPEED=24
               rohling
               image_brennen
               errorcontrol
            }
            elif [ "$SPEED" -le "52" ]; then
               rohling
               image_brennen
               errorcontrol
            else
               ausgabe_speed
            fi
         }
         else
            ausgabe_brenner
         fi
      }
      else
         ausgabe_speicherort
      fi
}

# Function "brennen" ende


################################################################
# Function "multi" um eine MultiSession zu starten/fortzusetzen#
################################################################

function multi() {
   AUSGABE "Möchten Sie eine Multisession starten oder fortsetzen (start/fort)"
   read ANTWORT
   while [ "$ANTWORT" != "start" ] && [ "$ANTWORT" != "fort" ]; do
   read ANTWORT
   done

   if [ "$ANTWORT" = "start" ]; then {   
      AUSGABE "Bitte machen Sie folgende angaben:\n\n\n"
      AUSGABE "Geben Sie den Pfad zum Image an: !!ACHTUNG!! es darf sich nur EINE *.img Datei dort befinden\n"
      read IMAGE
      HILFS_VAR=`ls $IMAGE | grep img`
      IMAGE="$IMAGE/$HILFS_VAR"
      AUSGABE $IMAGE
      if [ -r $IMAGE ]; then {
         AUSGABE "Ihr Brenner Device: \n"
         read -n 9 DEVICE
         if [ -r $DEVICE ]; then {
            AUSGABE "Brenngeschwindigkeit: (default 24x)\n"
            read -n 2 SPEED
            speed_check
            multi_brennen
         }
         else
            ausgabe_brenner
         fi
      }
      else
         ausgabe_speicherort
      fi   
   }
# Eine MultiSession wird fortgesetzt
   else {
      if [ "$ANTWORT" == "fort" ] && [ -x "$BURNPROG" ]; then  {
      AUSGABE $ANTWORT
         AUSGABE "Bitte machen Sie folgende angaben:\n\n\n"
         AUSGABE "Quelldatei: "
         read PFAD
         AUSGABE "Zieldatei: "
         read ZIEL
         if [ -r $PFAD ] && [ -r $ZIEL ]; then {
            ZIEL="$ZIEL/image.img"
            AUSGABE $ZIEL
            AUSGABE "Ihr Brenner Device: \n"
            read -n 9 DEVICE
            if [ -r $DEVICE ]; then {
               AUSGABE "Bitte legen Sie die MultiSession CD in ihr Brenner Device"
               eject $DEVICE
               AUSGABE "Drücken Sie RETURN um fortzufahren"
               read x
               eject -t $DEVICE
               read x
               mount $DEVICE
               ANFWERT=`cdrecord -msinfo dev=$DEVICE` # ließt den Anfang der Session
               AUSGABE $ANFWERT
               mkisofs -v -r -C $ANFWERT -M $DEVICE -J -o $ZIEL $PFAD && echo_success
               AUSGABE "Brenngeschwindigkeit: (default 24x)\n"
               read -n 2 SPEED
               speed_check
               multi_brennen
            }
            else
               ausgabe_brenner
            fi
         }
         else
            ausgabe_speicherort
         fi
      }
      fi
   }
   fi
}

# Function "multi" ende

case $AUSWAHL in
   I|i) image;;
   B|b) brennen;;
   M|m) multi;;
   *) AUSGABE "Die Auswahl $AUSWAHL ist ungültig\n\n";;
esac


mfg }-Tux-{
 
Oben