0

Hi there i am trying to make a script for use cdemu to mount image (because gcdemu never works for me).

i am trying to make a list of supported formats

$ cdemu enum-parsers
Supported parsers:
  PARSER-MDX: MDX Image Parser
    application/x-mdx: DaemonTools images (*.mdx, *.mds)
  PARSER-HD: Hard-disk Image Parser
    application/x-apple-diskimage: Apple Disk image (*.cdr)
    application/x-apple-diskimage: Apple Disk image (*.smi)
    application/x-apple-diskimage: Apple Disk image (*.img)
  PARSER-READCD: READCD Image Parser
    application/x-cd-image: readcd images (*.toc)
  PARSER-ISO: ISO Image Parser
    application/x-cd-image: ISO images (*.iso, *.bin, *.img)
    audio/x-wav: WAV audio files (*.wav)
  PARSER-XCDROAST: X-CD-Roast Image Parser
    application/x-xcdroast: X-CD-Roast images (*.toc)
  PARSER-CCD: CCD Image Parser
    application/x-ccd: CloneCD images (*.ccd)
  PARSER-C2D: C2D Image Parser
    application/x-c2d: WinOnCD images (*.c2d)
  PARSER-CDI: CDI Image Parser
    application/x-cdi: DiscJuggler images (*.cdi)
  PARSER-B6T: B6T Image Parser
    application/x-b6t: BlindWrite 5/6 images (*.b5t, *.b6t)
  PARSER-NRG: NRG Image Parser
    application/x-nrg: Nero Burning Rom images (*.nrg)
  PARSER-CUE: CUE Image Parser
    application/x-cue: CUE images (*.cue)
  PARSER-TOC: TOC Image Parser
    application/x-cdrdao-toc: cdrdao images (*.toc)
  PARSER-MDS: MDS Image Parser
    application/x-mds: Alchohol 120% images (*.mds)
    application/x-xmd: GameJack images (*.xmd)
  PARSER-CIF: CIF Image Parser
    application/x-cif: Adaptec Easy CD/DVD Creator images (*.cif)

i need extract the format list supported and put inside of a new array like

SuportedFormats=(
mdx
mds
cdr
smi
img
toc
ccd
c2d
cdi
b5t
b6t
nrg
cue
xmd
cif)

but the format list can change depend of version of cdemu.

Another thing i want to change the uppercase extension to lowercase. i try with

tr '[:upper:]' '[:lower:]' "${1##*.}"

But i don't now how to use it

1

To get a list of file extensions (requires GNU grep):

$ cdemu enum-parsers | grep -oP '(?<=\*\.)[^,)]*'
mdx
mds
cdr
smi
img
toc
iso
bin
img
wav
toc
ccd
c2d
cdi
b5t
b6t
nrg
cue
toc
mds
xmd
cif

To put those extensions into an array:

$ SupportedFormats=($(cdemu enum-parsers | grep -oP '(?<=\*\.)[^,)]*'))

To verify that we have the correct array, run declare -p:

$ declare -p SupportedFormats
declare -a SupportedFormats=([0]="mdx" [1]="mds" [2]="cdr" [3]="smi" [4]="img" [5]="toc" [6]="iso" [7]="bin" [8]="img" [9]="wav" [10]="toc" [11]="ccd" [12]="c2d" [13]="cdi" [14]="b5t" [15]="b6t" [16]="nrg" [17]="cue" [18]="toc" [19]="mds" [20]="xmd" [21]="cif")

Converting to lower case

All of the extensions in your example were lower case. If you really do need to convert to lower case, you can use tr:

SupportedFormats=($(cdemu enum-parsers | grep -oP '(?<=\*\.)[^,)]*' | tr '[:upper:]' '[:lower:]'))

tr is not unicode-safe. If your strings have unicode, then sed is a better choice (GNU sed required):

SupportedFormats=($(cdemu enum-parsers | grep -oP '(?<=\*\.)[^,)]*' | sed -E 's/[[:upper:]]/\L&/g'))
  • Thank you very much for you quickly and complete answer :=) – Inukaze Nov 23 '17 at 8:11
0

Well i try to make my script, works with Xfce 4.12 and Thunar, but don't work

 #!/usr/bin/env bash

echo '
Autor ----------------> Inukaze ( Venezuela )
Sitio ----------------> inukaze.wordpress.com
Correo-E -------------> inukaze.otaku@gmail.com
Licencia -------------> GPL 2

******* Inicio : Acerca de este Script ********

 Este Mini-Script es para poder Montar
 Imagen(es) de Disco(s) Compacto(s)
 de forma sencilla. sin necesidad
 del fallido "gcdemu" (Solo me da errores)

******** Fin : Acerca de este Script **********'

# NOTAS
#
# 1 - Verificar el Demonio
# 2 - Verificar que existe por lo menos una unidad virtual, en caso de que no, crear una
# 3 - En caso de que si exista, pero ya este montada una imagen, desmontar la imagen para montar la más nueva
#
# Patron de "Imagen" y "Otros Archivos" para Thunar : 
# *.mdx;*.mds;*.cdr;*.smi;*.img;*.toc;*.ccd;*.c2d;*.cdi;*.b5t;*.b6t;*.nrg;*.cue;*.xmd;*.cif;*.iso

# Asegurarse de que el demonio esta en ejecucion
DEMONIO=$(ps -A | grep cdemu-daemon | awk '{print $1}')
if [ "$DEMONIO" == "$(pgrep cdemu-daemon)" ] ; then
       DEMONIO=$(echo "Demonio cargado y funcionando") ; echo "$DEMONIO"
    else zenity --error --text 'El Demonio "cdemu" no esta cargado, Abortando.'; exit 1
fi

FormatoSoportado=($(cdemu enum-parsers | grep -oP '(?<=\*\.)[^,)]*'))
declare -p FormatoSoportado 2&>/dev/null
#Minusculas=$(sed -E 's/[[:upper:]]/\L&/g')

# Comprobar que existe por lo menos un dispositivo virtual, si no existe crear uno
DISPOSITIVO=$(cdemu --bus session status | grep "0" | tail -n1 | awk '{print $1}')
if [ ! $DISPOSITIVO ]; then
    cdemu add-device
fi

DISPOSITIVO=$(cdemu --bus session status | grep -E 'LOADED|True' | awk '$2=="True"' | awk '{print $2}')
if [ "$DISPOSITIVO" == "True" ]; then
    #ARCHIVO=$(cdemu --bus session status | awk '{ print $3 $6 }' | tail -n1)
    cdemu unload 0
    #zenity --error --text "No puedes cargar más imagenes. Dispositivo Ocupado.\n$ARCHIVO"; exit 1
fi

DISPOSITIVO=$(cdemu --bus session status | grep -E 'LOADED|False' | awk '$2=="False"' | awk '{print $2}')
if [ "$DIPOSITIVO" == "False" ]; then
     NOMBRE="$(basename "$@")"
     NOMBRE=$(echo "$NOMBRE" | sed 's/[*.*].*//')
     RUTA=$(echo $(cd $(dirname "$1") && pwd -P)/$(basename "$1"))
     cdemu load 0 "$NOMBRE.${#FormatoSoportado[@]}"
fi

The idea for my is simple

  1. Check cdemu-daemon is running
  2. Check exist one device if not create one
  3. If a device exists, check if yes have a image mounted, unmounted the image
  4. Mount the image most recent

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.