Gravação de CDs/DVDs em dialog

Publicado por Perfil removido (última atualização em 24/09/2012)

[ Hits: 4.422 ]

Download 5540.burncd.sh




Shell script para fazer cópias de cds/dvds, criar imagens ISO, gravar dados em cds e dvds e queimar imagens ISO em cds/dvds. Antes de começar a fazer qualquer tarefa, o script verifica se seu sistema tem os pré-requisitos para finalizar com sucesso qualquer tarefa a ser executada, caso não tenha, solicita que instale no sistema tais pacotes para continuar.

O script é longo, mas fiquem a vontade para alterar seu conteúdo conforme sua necessidade. Rodei sem problemas no Debian, Linux Mint, CentOS, Fedora e Ubuntu.

  



Esconder código-fonte

#!/bin/bash

#*******************************************************************************#
#                              #
# Nome do script: burncd.sh                     #
# criado por Edson de Abreu Oliveira                  #
# -----------------------------------------------------------------------------   #
# Objetivo do shell script é queimar (burn) cds e dvds, gravando nas mídias    #
# imagens iso, dados diversos (disco de dados), assim como também criar      #
# imagens iso, ou copiar cds e ou dvds.                  #
# -----------------------------------------------------------------------------   #
# O script tem várias funções. as principais são: begin, parar.         #
# Além de outras funções que executam tarefas especificas que pode ser      #
# selecionadas no inicio do script.                  #      
#*******************************************************************************#

begin()
 {
         
            #############################################################
            ############# Verifica Requisitos do sistema ################
            #############################################################

                if [ -e $(which dd) -a -e $(which eject) -a -e $(which wodim) -a -e $(which dialog) -a -e $(which growisofs) -a -e $(which genisoimage) ]; then
                    dialog --infobox ' checando sistema... ' 3 30
                    sleep 2
            else
                    echo "checando sistema..."
          echo -e "# Pacotes necessários para script:{FONTE}33[31;1mgenisoimage wodim dvd+rw-tools coreutils eject dialog{FONTE}33[m,instale os pacotes para rodar sem problemas"
          exit 1
      fi

            ###################################################
            ########### Tela de apresentação do script  #######
            ###################################################

          NU=$( dialog --stdout --title 'OPÇÕES' --menu 'Escolha a opção que será executada:' 0 0 0 \
         image-iso '- CRIAR UMA IMAGEM ISO' \
         data-midi '- CRIAR UMA MÍDIA DE DADOS' \
         copy-midi '- COPIAR UM CD OU DVD' \
         burn     '- QUEIMAR IMAGEM ISO NA MÍDIA' \
         sair      '- Sair do script' ) 

          [ -n "$NU" ] && OP="$NU" || OP=$(($NU + 1))

         case $OP in
          image-iso)image-iso;;
          data-midi)data-midi;;
          copy-midi)copy-midi;;
          burn)burn;;
          sair)dialog --title "Opção escolhida" --infobox 'saindo do script' 3 20;exit 1;;
          1)dialog --title "CANCELAMENTO" --infobox 'O Botão CANCELAR foi apertado ou ESC foi presionado. saindo do script' 3 60;exit 1;;
          *) echo "Opção Inválida!!!";iniciar;;
 
         esac
}
 image-iso()
 {
 
          #############################################################
          #############################################################
          #############      CRIAR IMAGEM ISO   #############
          #############################################################
          #############################################################

          dialog --title "Opção" --infobox ' Você escolheu a opção criar uma imagem iso ' 3 50
          sleep 2

          #################################################################################################
          # Pedi informações ao usuário, como pro exemplo: nome da imagem iso, local de destino da imagem #
          #################################################################################################

         texto="Insira o nome que a imagem ISO receberá e o caminho absoluto dos dados que deseja incluir na imagem ISO (diretório ou arquivo)"
         ent=$(dialog --stdout \
         --ok-label "OK" \
         --title "Dados de entrada" \
         --form "$texto" 9 70 4 \
         "Nome" 1 1 "" 1 20 50 0 \
         "Dados de Origem" 2 1 "" 2 20 50 0 )
               nome=$(echo "$ent" |head -1)
               cam=$(echo "$ent" |head -2 |tail -1)

         ###############################
         # Verificação das informações #
         ###############################

         if [ -e "$cam" -a -n "$ent" -a -n "$nome" ];then
             sleep 1 
         else
             dialog --title "Erro" --infobox "informação insuficiente, saindo do script..." 3 50 && exit 1
         fi

         cam1=$(dialog --stdout --ok-label "OK" --title "Escolha o local onde será armazenada a imagem ISO" --dselect "$HOME" 10 70)

         if [ -e "$cam1" -a -n "$cam1" ];then
            sleep 1
                   else
                           dialog --title "Erro" --infobox "informação insuficiente, saindo do script..." 3 50 
            exit 1
         fi 

          #################################
          # Gerando imagem iso no destino #
          #################################
         clear
         genisoimage -o $cam1/$nome -JrlL -pad $cam
         if [ -e "$cam1/$nome" ];then
            dialog --title "Fim" --infobox " imagem criada com sucesso " 3 30
            dialog --title "Tamanho da Imagem ISO" --infobox "Tamanho total da Imagem é:$(du -h "$cam1"/"$nome")" 3 40
         else
            dialog --title "Erro" --infobox " imagem não foi criada ocorreu algum erro " 3 45 && exit 1
         fi

}

 data-midi()
 {
 
          ###########################################################################
          ###########################################################################
          ################   CRIAR MIDIA DE DADOS     ##########################
          ###########################################################################
          ###########################################################################

         dialog --title "Opção" --infobox ' Você escolheu a opção criar mídia de Dados ' 3 55
          sleep 2

         ################################################################################
         #   CÓDIGO QUE INDICA A LOCALIZAÇÃO DOS DADOS E QUE SERÃO GRAVADOS NA MÍDIA    #
         #   E A GRAVADORA QUE CONTÉM A MÍDIA                      #
         ################################################################################

          loc=$(dialog --stdout --ok-label "OK" --title "Dados a serem copiados" --dselect / 10 70)

          if [ -n "$loc" ];then
            dialog --infobox " Dados existem... " 3 25
            sleep 2
            midi=$(dialog --stdout --ok-label "OK" --inputbox " Deseja gravar os dados em um CD ou DVD ? " 0 0)
         #########################################################
         #      Gravar dados no DVD         #
         #########################################################
               texto1="Escolha o drive que será usado para gravar os dados na mídia"
                   if [ "$midi" = dvd -o "$midi" = DVD -o "$midi" = Dvd ];then
                  midia=$(dialog --stdout --title "$texto1" --ok-label "OK" --fselect /dev/ 10 80)
                  if [ -b "$midia" ];then
                     eject "$midia"
                     dialog --ok-label "OK" --title "Mídia a ser cópiada"  --infobox ' Coloque a mídia na bandeja e tecle ENTER ' 3 55
                     read ppp
                     eject -t "$midia"
                     sleep 20
                     clear
                     growisofs -dvd-compat -speed=4 -Z "$midia" -R -J "$loc"
                     sleep 5 && eject "$midia"
                     rm -fr /tmp/burncd/
                  elif [-z "$midia" ];then
                      dialog --title "Erro" --infobox 'você cancelou a operação' 3 35
                     exit 1
                  else
                     dialog --title "Erro" --infobox 'Informação insuficiente...' 3 35
                     exit 1
                  fi

         #########################################################
         #      Gravar dados no CD         #
         #########################################################
               elif [ "$midi" = cd -o "$midi" = CD -o "$midi" = Cd ];then
                  mkdir /tmp/burncd
                  genisoimage -o /tmp/burncd/dados.iso -JrlL -pad "$loc"
                [ -e "/tmp/burncd/dados.iso" ]&& sleep 2 || dialog --infobox "Erro, finalizando script" 3 35 && exit 1
               midia=$(dialog --stdout --title "$texto1" --ok-label "OK" --fselect /dev/ 10 80)
         ######################################################################
         ################  Gravando imagem iso no cd ##########################
         ######################################################################
                  if [ -b "$midia" ];then
                                                        eject "$midia"
                                                        dialog --ok-label "OK" --title "Mídia a ser cópiada"  --infobox ' Coloque a mídia na bandeja e tecle ENTER ' 3 55
                                                        read ppp
                                                        eject -t "$midia"
                                                        sleep 20
                     clear
                                                     wodim -v -dev "$midia" -speed=24 -eject -multi -data /tmp/burncd/dados.iso
                                                        sleep 5 && eject "$midia"
                     rm -fr /tmp/burncd/
                                                elif [-z "$midia" ];then
                                                        dialog --title "Erro" --infobox 'você cancelou a operação' 3 35
                                                        exit 1
                                                else
                                                        dialog --title "Erro" --infobox 'Informação insuficiente...' 3 35
                                                        exit 1
                                                fi
               else
                  dialog --infobox " Opção invalida, saindo do script... " 3 45
                  exit 1
                 fi
         elif [ -z "$loc" ];then
             dialog --infobox " Operação cancelada, informação insuficiente... " 3 60 
             exit 1
         fi

 }

 copy-midi()
 {

          #####################################################################
          #####################################################################
          ################   COPIAR MIDIAS       #####################
          #####################################################################
          #####################################################################

         dialog --title "Opção" --infobox ' Você escolheu a opção copiar mídia ' 3 50
          sleep 2

         #################################################################
         #         Escolhendo mídia         #
         #################################################################

         midia=$(dialog --stdout --ok-label "OK" --title "Escolha o drive que será usado para cópiar a mídia" --fselect /dev/ 10 70)
         if [ -b "$midia" ];then
            dialog --infobox ' ejetando bandeja do drive... ' 3 35
            eject "$midia"
            sleep 2
               dialog --infobox ' Coloque a mídia na bandeja e tecle ENTER ' 3 45
               read ppp
               eject -t "$midia"
               sleep 20
         elif [-z "$midia" ];then
             dialog --infobox 'você cancelou a operação' 3 35
            exit 1
         else
            dialog --infobox 'Informação insuficiente...' 3 35
            exit 1
         fi

         #########################################################################
         #         Fazendo copia da mídia            #                           
         #########################################################################

         mkdir /tmp/burncd
         dialog --ok-label "OK" --title "Cópia"   --infobox ' Fazendo cópia da mídia ... ' 3 35
          dd if="$midia" of=/tmp/burncd/dados.iso
         sleep 2

         if [ -e /tmp/burncd/dados.iso ];then
            sleep 1
         else
            dialog --title "Erro" --infobox ' Falha ao realizar a cópia ' 3 35 && exit 1
         fi
         
         #################################################################################
         #         Gravando cópia feita na mídia            #
         #################################################################################

         midi=$(dialog --stdout --ok-label "OK" --inputbox " Deseja gravar em um CD ou DVD " 0 0)

         if [ "$midi" = "DVD" -o "$midi" = "dvd" -o "$midi" = "Dvd" ];then
            eject "$midia"
            dialog --infobox ' coloque a midia vazia na bandeja do drive  e tecle ENTER para gravar na mídia ' 3 90
            read ppd
            eject -t "$midia"
            sleep 20
            clear         
            growisofs -dvd-compat -speed=4 -Z "$midia"=/tmp/burncd/dados.iso
            sleep 2
            eject "$midia"
         elif [ "$midi" = "CD" -o "$midi" = "cd" -o "$midi" = "Cd" ];then
            eject "$midia"
            dialog --infobox ' coloque a midia vazia na bandeja do drive  e tecle ENTER para gravar na mídia ' 3 90
            read ppd
            eject -t "$midia"
            sleep 20
            clear
            wodim -v -dev "$midia" -speed=24 -eject -multi -data /tmp/burncd/dados.iso
         else
            dialog --ok-label "OK" --title "Fim" --infobox ' Operação Cancelada, informação insuficiente... ' 3 50 && exit 1
         fi
          rm -fr /tmp/burncd/
      
 }

 burn()
 {

          ####################################################
          ####################################################
          ############   QUEIMAR MIDIA   ####################
          ####################################################
          ####################################################

         dialog --title "Opção" --infobox ' Você escolheu a opção queimar imagem ISO na mídia ' 3 60
          sleep 2
         
         image=$(dialog --stdout --title "Imagem" --ok-label "OK" --fselect / 10 70)
          if [ -e "$image" ];then
             dialog --infobox " imagem existe OK " 3 25
            sleep 2
          else
             dialog --infobox " imagem não existe, saindo do script ..." 3 45 && exit 1
          fi
         medi=$(dialog --stdout --ok-label "OK" --inputbox " Deseja gravar os dados em um CD ou DVD ? " 0 0)
          if [ "$medi" = "dvd" -o "$medi" = "DVD" -o "$medi" = "Dvd" ];then
         ######################################################################
         ################  Gravando imagem iso no  dvd ########################
         ######################################################################
            midia=$(dialog --stdout --title "$texto1" --ok-label "OK" --fselect /dev/ 10 80)   
            if [ -b "$midia" ];then
               eject "$midia"
               dialog --ok-label "OK" --title "Mídia a ser cópiada"  --infobox ' Coloque a mídia na bandeja e tecle ENTER ' 3 55
               read ppp
               eject -t "$midia"
               sleep 20
               clear
               growisofs -dvd-compat -speed=4 -Z "$midia"="$image"
               sleep 5 && eject "$midia"
            elif [-z "$midia" ];then
                dialog --title "Erro" --infobox 'você cancelou a operação' 3 35
               exit 1
            else
               dialog --title "Erro" --infobox 'Informação insuficiente...' 3 35
               exit 1
            fi      
          elif [ "$medi" = "cd" -o "$medi" =CD -o "$medi" = Cd ];then
            midia=$(dialog --stdout --title "$texto1" --ok-label "OK" --fselect /dev/ 10 80)
         ######################################################################
         ################  Gravando imagem iso no cd ##########################
         ######################################################################
                  if [ -b "$midia" ];then
                                                        eject "$midia"
                                                        dialog --ok-label "OK" --title "Mídia a ser cópiada"  --infobox ' Coloque a mídia na bandeja e tecle ENTER ' 3 55
                                                        read ppp
                                                        eject -t "$midia"
                                                        sleep 20
                     clear
                                                     wodim -v -dev "$midia" -speed=24 -eject -multi -data "$image"
                                                        sleep 5 && eject "$midia"
                                                elif [-z "$midia" ];then
                                                        dialog --title "Erro" --infobox 'você cancelou a operação' 3 35
                                                        exit 1
                                                else
                                                        dialog --title "Erro" --infobox 'Informação insuficiente...' 3 35
                                                        exit 1
                                                fi
         else
            dialog --infobox " Opção invalida, saindo do script... " 3 35
            exit 1
           fi
 }

 sair()
 {

 dialog --infobox " saindo do script " 3 25
 exit 0

 }

parar(){

 dialog --yesno " Deseja realmente parar o script ? isto pode fazer com que alguma tarefa em execução não seja concluida e ocasionar perda de dados. " 7 60 
     if [ "$?" = "0" ];then
      pkill -term wodim 2> /dev/null
        pkill -term dd 2> /dev/null
          pkill -term burncd.sh 2> /dev/null
      pkill -term growisofs 2> /dev/null
      pkill -term 
    else
        dialog --infobox " script continua em execução..." 3 35
    fi

}

case $1 in
start)begin;;
stop)parar;;
*) echo " Digite uma parametro valido * start,stop ou restart *";;
 
 esac

Scripts recomendados

Enviar gráficos 3D pela janela de chat no Kopete

Configurar usuarios samba na boa sem dor de cabeça em modo texto

Ping para servidores tendo um arquivo TXT com a lista dos IPs/Hostnames

Descom.sh - Descompactador de arquivos

Consulta operadora


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts