File: BashBurn.sh

package info (click to toggle)
bashburn 3.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 1,140 kB
  • sloc: sh: 2,584; sed: 64; makefile: 19
file content (449 lines) | stat: -rwxr-xr-x 13,220 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#!/bin/bash

errmsg()
{
    echo -e "$@" 1>&2
}

die()
{
    errmsg "$@"
    exit 1
}

# Creates a default config file if one is missing
create_config()
{
    {
	create_reg_config
	create_advanced_config
    } > $BBCONFFILE
}


create_reg_config()
{
    typeset line

    echo -e "
VERSION: 3.x.x
BBISCONF: 0
BBCDWRITER: <Change me>
BBCDROM: <Change me>
BBCDMNT: <Change me>
BBSPEED: -1
BBBLANKING: fast
BBNUMDEV: 1
BBBURNDIR: /tmp/burn
BBFIFODIR: /tmp
BBDESCRIPTION: Burnt with BashBurn
BBAUTHOR: <Change me>
BBLABEL: BashBurn CD/DVD
BBNORMALIZE: no
BBDRIVEROPT: 
BBDELTEMPBURN: no
BBOVERBURN: no
BBBITRATE: 192
BBLANG: English
BBDTAO: -tao
BBPADDING: -pad
"
}

create_advanced_config ()
{
    echo -e "
BB_CDBURNCMD: wodim
BB_DVDBURNCMD: growisofs
BB_DVDBURNCMDOPTS: -r -f -v -J -joliet-long
BB_ISOCMD: genisoimage
BB_DVDBLANK: dvd+rw-format
BB_CDIMAGECMD: cdrdao
BB_CDAUDIORIP: cdparanoia
BB_READCD: genisoimage
BB_READ_OPTS: -r -R -J -l --allow-leading-dots
BB_MP3ENC: 
BB_MP3DEC: mpg123
BB_OGGENC: oggenc
BB_OGGDEC: oggdec
BB_FLACCMD: flac
BB_EJECT: eject
BB_NORMCMD: normalize-audio
"
}

exit_handler()
{
    echo -e "

${BBMAINCOLOR}$bb_quit1${BBHEADCOLOR}${BBVERSION}
${BBMAINCOLOR}$bb_quit2${BBSUBCOLOR}$bb_quit3${BBMAINCOLOR}$bb_quit4${BBCOLOROFF}"
    # Reset terminal
    tput sgr0
    stty $TERMINAL_CHARACTERISTICS
    history -w
}

force_quit()
{
    exit 0
}

typeset -ra BB_REG_KEYWORDS=( \
	VERSION \
	BBCDWRITER \
	BBCDROM \
	BBCDMNT \
	BBSPEED \
	BBBLANKING \
	BBNUMDEV \
	BBBURNDIR \
	BBLABEL \
	BBDESCRIPTION \
	BBAUTHOR \
	BBNORMALIZE \
	BBDRIVEROPT \
	BBFIFODIR \
	BBDELTEMPBURN \
	BBOVERBURN \
	BBBITRATE \
	BBLANG \
	BBISCONF \
	BBDTAO \
	BBPADDING \
	BBCONFFILE \
	)

typeset -ra BB_ADV_KEYWORDS=( \
	BB_CDBURNCMD \
	BB_DVDBURNCMD \
        BB_DVDBURNCMDOPTS \
	BB_ISOCMD \
	BB_DVDBLANK \
	BB_CDIMAGECMD \
	BB_CDAUDIORIP \
	BB_READ_OPTS \
	BB_READCD \
	BB_MP3ENC \
	BB_MP3DEC \
	BB_OGGENC \
	BB_OGGDEC \
	BB_FLACCMD \
	BB_EJECT \
	BB_NORMCMD \
	)
typeset -ra BB_KEYWORDS=( "${BB_REG_KEYWORDS[@]}" "${BB_ADV_KEYWORDS[@]}" )

typeset -a mainmenu
typeset -a advancedmenu
typeset -a audiomenu
typeset -a configmenu
typeset -a datamenu
typeset -a isomenu
typeset -a multimenu
typeset -a mountmenu
typeset -a datadefinemenu
typeset -a conf_menuitems
typeset CFG_CHANGES


typeset -r grepcdfstab="grep -E 'cdrom|dvd|writer|cdrw' /etc/fstab"
typeset -r lslang='ls -I ${BBLANG} -1 ${BBROOTDIR}/lang'
typeset -r checkdrive='$BB_CDBURNCMD dev=$BBCDWRITER driveropts=help \
		       -checkdrive 2>&1 > /dev/null | grep -A 20 "Driver options"'

define_global_menus()
{
    # Define the menu array entries. Colon is the seperator.
    # Field 1 is always the the prompt.
    # Field 2 is always the action if there's a match.
    # If field three exists then it is the current value to be displayed.
    # The above description only applies to menus. It does NOT apply to
    # configuration menus. Regular menus are fed to bbmenu. Configuration 
    # menus are fed to bbmenuconf.
    # Format for bbmenuconf is
    # Fld1 is field description.
    # Fld2 is the name of the config param.
    # Fld3 is the prompt if you want to change the value of fld2.
    # Fld4 (optional) is the code to execute to provide more data at runtime
    # for fld3.
    mainmenu[0]="$bb_menu_1@audio_menu"
    mainmenu[1]="$bb_menu_2@data_menu"
    mainmenu[2]="$bb_menu_3@iso_menu"
    mainmenu[3]="$bb_menu_4@bincue"
    mainmenu[4]="$bb_menu_5@multi"
    mainmenu[5]="$bb_menu_6@configure && return"	# Very tricky.
    mainmenu[6]="$bb_conf_menu_adv@advanced"
    mainmenu[7]="$bb_menu_7@mount_func"
    mainmenu[8]="$bb_menu_8@check_path"
    mainmenu[9]="$bb_menu_9@datadefine"
    mainmenu[10]="$bb_menu_0@bbexit"

    advancedmenu[0]='bb_adv_cdburncmd@BB_CDBURNCMD@bb_adv_cdburncmd_help'
    advancedmenu[1]='bb_adv_dvdburncmd@BB_DVDBURNCMD@bb_adv_dvdburncmd_help'
    advancedmenu[2]='bb_adv_dvdburncmdopts@BB_DVDBURNCMDOPTS@bb_adv_dvdburncmdopts_help'
    advancedmenu[3]='bb_adv_isocmd@BB_ISOCMD@bb_adv_isocmd_help'
    advancedmenu[4]='bb_adv_dvdblankcmd@BB_DVDBLANK@bb_adv_dvdblankcmd_help'
    advancedmenu[5]='bb_adv_imgburncmd@BB_CDIMAGECMD@bb_adv_imgburncmd_help'
    advancedmenu[6]='bb_adv_audioripcmd@BB_CDAUDIORIP@bb_adv_audioripcmd_help'
    advancedmenu[7]='bb_adv_cdcopycmd@BB_READCD@bb_adv_cdcopycmd_help'
    advancedmenu[8]='bb_adv_cdcopyopts@BB_READ_OPTS@bb_adv_cdcopyopts_help'
    advancedmenu[9]='bb_adv_mp3enc@BB_MP3ENC@bb_adv_mp3enc_help'
    advancedmenu[10]='bb_adv_mp3dec@BB_MP3DEC@bb_adv_mp3dec_help'
    advancedmenu[11]='bb_adv_oggenc@BB_OGGENC@bb_adv_oggenc_help'
    advancedmenu[12]='bb_adv_oggdec@BB_OGGDEC@bb_adv_oggdec_help'
    advancedmenu[13]='bb_adv_flac@BB_FLACCMD@bb_adv_flac_help'
    advancedmenu[14]='bb_adv_eject@BB_EJECT@bb_adv_eject_help'
    advancedmenu[15]='bb_adv_norm@BB_NORMCMD@bb_adv_norm_help'

    audiomenu[0]="$bb_am_menu_1@convert_and_burn_from_files"
    audiomenu[1]="$bb_am_menu_2@burning --pipeline"
    audiomenu[2]="$bb_am_menu_3@copy_audio_cd"
    audiomenu[3]="$bb_am_menu_4@copy_cd_to_hd"
    audiomenu[4]="$bb_am_menu_5@burn_m3u_playlist"
    audiomenu[5]="$bb_am_menu_6@create_mp3s_from_wavs"
    audiomenu[6]="$bb_am_menu_7@create_oggs_from_wavs"
    audiomenu[7]="$bb_am_menu_8@create_flacs_from_wavs"
    audiomenu[8]="$bb_am_menu_9@create_mp3s_from_cd"
    audiomenu[9]="$bb_am_menu_10@create_oggs_from_cd"
    audiomenu[10]="$bb_am_menu_11@create_flacs_from_cd"
    audiomenu[11]="$bb_am_menu_0@return"

    conf_menuitems[0]='bb_conf_menu_writer@BBCDWRITER@bb_conf_ch_writer@grepcdfstab'
    conf_menuitems[1]='bb_conf_menu_cddev@BBCDROM@bb_conf_ch_cddev@grepcdfstab'
    conf_menuitems[2]='bb_conf_menu_cdmnt@BBCDMNT@bb_conf_ch_cdmnt@grepcdfstab'
    conf_menuitems[3]='bb_conf_menu_speed@BBSPEED@bb_conf_ch_speed'
    conf_menuitems[4]='bb_conf_menu_blank@BBBLANKING@bb_conf_ch_blanking'
    conf_menuitems[5]='bb_conf_menu_numdev@BBNUMDEV@bb_conf_ch_numdev'
    conf_menuitems[6]='bb_conf_menu_burn@BBBURNDIR@bb_conf_ch_burndir'
    conf_menuitems[7]='bb_conf_menu_label@BBLABEL@bb_conf_ch_label'
    conf_menuitems[8]='bb_conf_menu_auth@BBAUTHOR@bb_conf_ch_author'
    conf_menuitems[9]='bb_conf_menu_desc@BBDESCRIPTION@bb_conf_ch_desc'
    conf_menuitems[10]='bb_conf_menu_norm@BBNORMALIZE@bb_conf_ch_norm'
    conf_menuitems[11]='bb_conf_menu_dropt@BBDRIVEROPT@bb_conf_ch_dropts@checkdrive'
    conf_menuitems[12]='bb_conf_menu_fifo@BBFIFODIR@bb_conf_ch_fifo'
    conf_menuitems[13]='bb_conf_menu_deltmp@BBDELTEMPBURN@bb_conf_ch_tempdel'
    conf_menuitems[14]='bb_conf_menu_ob@BBOVERBURN@bb_conf_ch_ob'
    conf_menuitems[15]='bb_conf_menu_bitrate@BBBITRATE@bb_conf_ch_bitrate'
    conf_menuitems[16]='bb_conf_menu_lang@BBLANG@bb_conf_ch_lang@lslang' 
    conf_menuitems[17]='bb_conf_menu_dtao@BBDTAO@bb_conf_ch_dtao'
    conf_menuitems[18]='bb_conf_menu_gap@BBPADDING@bb_conf_ch_pad'

    datamenu[0]="$bb_dm_menu_1@burning --data"
    datamenu[1]="$bb_dm_menu_2@copy_data_cd"
    datamenu[2]="$bb_dm_menu_3@burning --dvddata"
    datamenu[3]="$bb_dm_menu_4@blank_CDROM"
    datamenu[4]="$bb_dm_menu_5@burning --dvdblank"
    datamenu[5]="$bb_dm_menu_0@return"

    isomenu[0]="$bb_im_menu_1@burning --iso"
    isomenu[1]="$bb_im_menu_2${BBBURNDIR}@create_iso_from_dir"
    isomenu[2]="$bb_im_menu_3@create_iso_from_cd"
    isomenu[3]="$bb_im_menu_4@burning --dvdimage"
    isomenu[4]="$bb_im_menu_5@mount_in_loopback"
    isomenu[5]="$bb_im_menu_0@return"

    multimenu[0]="$bb_multi_menu_1@burn_multi -m 0"
    multimenu[1]="$bb_multi_menu_2@burn_multi -m 1"
    multimenu[2]="$bb_multi_menu_3@burn_multi 1"
    multimenu[3]="$bb_multi_menu_0@return"

    mountmenu[0]="$bb_mnt_menu_1@mount_device"
    mountmenu[1]="$bb_mnt_menu_2@umount_device"
    mountmenu[2]="$bb_mnt_menu_3@eject_device"
    mountmenu[3]="$bb_mnt_menu_0@return"

    datadefinemenu[0]="$bb_dc_menu_1${BBBURNDIR}@copy_link_data"
    datadefinemenu[1]="$bb_dc_menu_2${BBBURNDIR}@{ view_contents; wait_for_enter; }"
    datadefinemenu[2]="$bb_dc_menu_3${BBBURNDIR}@{ delete_data; wait_for_enter; }"
    datadefinemenu[3]="$bb_dc_menu_0@return"
}

source_language_modules()
{
    # This to GO when all configure.lang are fixed
    # This just adds help descriptions in English
    # for languages that have not yet got the new $VAR
    # else they get NO help descriptions at all.
    . ${BBROOTDIR}/misc/configure_temp_help.lang 

    typeset -r langdir=${BBROOTDIR}/lang/${BBLANG}
    # Language files
    . $langdir/BashBurn.lang
    . $langdir/advanced.lang
    . $langdir/audio_menu.lang
    . $langdir/bincue.lang
    . $langdir/burning.lang
    . $langdir/check_path.lang
    . $langdir/commonfunctions.lang
    . $langdir/configure.lang
    . $langdir/convert_flacs.lang
    . $langdir/convert_mp3s.lang
    . $langdir/convert_oggs.lang
    . $langdir/data_menu.lang
    . $langdir/datadefine.lang
    . $langdir/iso_menu.lang
    . $langdir/loopback.lang
    . $langdir/mount.lang
    . $langdir/multi.lang
}

bbexit()
{
    typeset -r bberrlog=/dev/null
    echo -e "--\n" >> $bberrlog
    exit 0
}

getconfigparam()
{
    typeset param=$1
    typeset oldIFS="$IFS"
    typeset IFS=:
    typeset line
    while read line
    do
	set -- $line
	if [[ $1 == $param ]]
	then
	    IFS="$oldIFS"
	    read trimval <<< $2
	    eval $param=$trimval
	    return 0	# found
	fi
    done < $BBCONFFILE
    return 1
}

# Decoline must be two characters longer than version or it will look funny.
typeset -r BBDECOLINE='+----------------+'
# Version number (should not contain whitespaces at beginning or
# end [petsound]).
typeset -r BBVERSION='BashBurn 3.0.1'
# Bashburn configuration file:
typeset -r HOMEDIR=$HOME # User identification
# Default config file, used if no config file in user dir 
typeset BBCONFFILE=$HOMEDIR/.bashburnrc
typeset BBROOTDIR='/usr/share/bashburn/lib'

typeset TERMINAL_CHARACTERISTICS
typeset HISTFILE=$HOMEDIR/.bashburn_history

# Error log
typeset bberrorlog=/tmp/bb-error.log
typeset -r OLD_IFS="$IFS"
typeset -r BBLANGdef=English

echo -e "$(date)\n" >> $bberrorlog

# Current terminal characteristics.
TERMINAL_CHARACTERISTICS=$(stty -g)

# Detect signals as 'CTRL+C', INIT, KILL, call to function force_quit, 
# show BashBurn info and quit.
trap exit_handler EXIT
trap force_quit SIGHUP SIGINT SIGQUIT SIGTERM

# Pull in minimal files
. ${BBROOTDIR}/misc/colors.idx
colordef
. ${BBROOTDIR}/config/apply_options.sh
. ${BBROOTDIR}/misc/commonfunctions.sh

BBLANG=$BBLANGdef
source_language_modules

# Create $HOMEDIR/.bashburnrc if it is not available
# Check if an old version is being used
if [[ -r $BBCONFFILE ]]
then
	if (! grep -q "VERSION: 3.x.x"  $BBCONFFILE)
	then
	message \
	"\n	You have an different version of $BBCONFFILE that
	will not work with version ${BBVERSION}.
	Please remove ${BBCONFFILE}, restart BashBurn, and
	immediately reconfigure ([option 5] in the main menu).\n"
	die
	 fi

fi
if [[ ! -r $BBCONFFILE ]]
then
    # We have no rc file and we have to say *something* so for now we will 
    # default to English.
    message \
"There is no '${BBCONFFILE}'.
This is the file where BashBurn stores and reads its configuration.
BashBurn  will now attempt to create a default template file.
PLEASE remember to set up your configuration first [option 5] in the main menu."
    create_config
    if [[ -r $BBCONFFILE ]]
    then
	message "${BBCONFFILE} file created successfully..."
    else
	die 'Failed to create config file. This should not happen.
Please report this bug to the BashBurn developers.'
    fi
fi
# If we get to here then the rc file exists.    
. ${BBROOTDIR}/misc/commands.idx
bb_parse_config

if [[ ! -d ${BBROOTDIR}/lang/${BBLANG} ]]
then
    message \
"Text files for configured language does not exist.
Defaulting to English."
    # Since the set language did not exist,
    # set it to English and save the option
    # so that in the future this message is not
    # shown again.
    BBLANG=English
fi

# Read in all files here
# This needs to go after all BBLANG help texts are completed/updated.
source_language_modules

# Function files
. ${BBROOTDIR}/burning/bincue.sh
. ${BBROOTDIR}/burning/burning.sh
. ${BBROOTDIR}/burning/multi.sh	
. ${BBROOTDIR}/convert/convert_audio.sh
. ${BBROOTDIR}/func/advancedfunc.sh
. ${BBROOTDIR}/func/audiofunc.sh
. ${BBROOTDIR}/func/bincuefunc.sh
. ${BBROOTDIR}/func/configfunc.sh
. ${BBROOTDIR}/func/datafunc.sh
. ${BBROOTDIR}/func/definefunc.sh
. ${BBROOTDIR}/func/isofunc.sh
. ${BBROOTDIR}/func/mountfunc.sh
. ${BBROOTDIR}/func/multifunc.sh
. ${BBROOTDIR}/menus/advanced.sh
. ${BBROOTDIR}/menus/audio_menu.sh
. ${BBROOTDIR}/menus/bbmenu.sh
. ${BBROOTDIR}/menus/configure.sh
. ${BBROOTDIR}/menus/datadefine.sh
. ${BBROOTDIR}/menus/data_menu.sh
. ${BBROOTDIR}/menus/iso_menu.sh 
. ${BBROOTDIR}/menus/mount.sh
. ${BBROOTDIR}/misc/check_path.sh
. ${BBROOTDIR}/misc/loopback.sh
. ${BBROOTDIR}/misc/m3u_read.sh

apply_options

# Create temporary directory if it does not exist
mkdir -p $BBBURNDIR

define_global_menus
####PROGRAM START####
# bbmenu is called in a loop because
# the configure menu will cause an exit. This will give the mainmenu
# the opportunity to re-evaluate the array.
while true
do
    bbmenu bb_main_menu mainmenu
done
exit 0