새 목록을 생성하기 위해 출력 확장자를 추출하는 방법

새 목록을 생성하기 위해 출력 확장자를 추출하는 방법

안녕하세요, 저는 이미지를 설치하기 위해 cdemu를 사용하는 스크립트를 만들려고 합니다(gcdemu가 제게는 효과가 없었기 때문에).

지원되는 형식을 나열하려고 합니다.

$ 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)

지원되는 형식 목록을 추출하여 다음과 같은 새 배열에 넣어야 합니다.

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

하지만 cdemu 버전에 따라 형식 목록이 변경될 수 있습니다.

또 다른 것은 대문자 확장자를 소문자로 변경하고 싶습니다. 나는 시도했다

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

그런데 지금은 어떻게 사용하는지 모르겠어요

답변1

파일 확장자 목록을 얻으려면(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

이러한 확장을 배열에 넣으려면 다음을 수행하십시오.

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

올바른 배열이 있는지 확인하려면 다음을 실행하세요 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")

소문자로 변환

예제의 모든 확장자는 소문자입니다. 실제로 소문자로 변환해야 하는 경우 다음을 사용할 수 있습니다 tr.

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

tr유니코드 안전하지 않습니다. 문자열에 유니코드가 있는 경우 sed더 나은 옵션이 있습니다(GNU sed 필요).

SupportedFormats=($(cdemu enum-parsers | grep -oP '(?<=\*\.)[^,)]*' | sed -E 's/[[:upper:]]/\L&/g'))

답변2

글쎄, Xfce 4.12 및 Thunar에서 작동하는 스크립트를 만들어 보았지만 작동하지 않습니다.

 #!/usr/bin/env bash

echo '
Autor ----------------> Inukaze ( Venezuela )
Sitio ----------------> inukaze.wordpress.com
Correo-E -------------> [email protected]
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

내 생각은 간단해

  1. cdemu-daemon이 실행 중인지 확인하세요.
  2. 생성되지 않은 경우 장치가 존재하는지 확인하십시오.
  3. 장치가 존재하는 경우 이미지가 탑재되었는지 확인하고 이미지를 제거합니다.
  4. 최신 이미지 마운트

관련 정보