File: burning.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 (421 lines) | stat: -rwxr-xr-x 9,067 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
# A function to check if overburn is enabled
check_overburn()
{
    if [[ "${BBOVERBURN}" = yes ]]
    then	# Is overburn enabled?
	BBOBURN=-overburn		# yes it was
    else
	echo $bb_no_ob			# No it wasn't
	BBOBURN=
    fi
}

# A function to see if files in temp dir should be deleted after burning is done
check_tempdel()
{
    typeset str="$bb_burning_tmp_1 ${BBBURNDIR}"

    if [[ "${BBDELTEMPBURN}" = yes ]]
    then
	rm -rf "${BBBURNDIR}"/*
	str="$str $bb_burning_tmp_1b"
    else
	str="$str $bb_burning_tmp_2"
    fi
    echo "$str"
}

set_session_type()
{
    typeset session_answer
    # Return 0 for yes
    # Return 1 for no
    # Return 2 for else
    cat <<EOF
$bb_burning_dvd_1
$bb_burning_dvd_2
$bb_burning_dvd_3
$bb_burning_dvd_4

EOF
    read -e -p "$bb_burning_dvd_5" session_answer
    case "$session_answer" in
    yes)
	return 0
	;;
    no)
	return 1
	;;
    *)
	return 2
	;;
    esac
}

################################ AUDIO #################################

_burning()
{
    typeset audio
    # HACK option processing. FIXME:
    if [[ "$1" == -a ]]
    then 
	audio=-audio
	shift
    fi

    # HACK to get driveroptions to work. FIXME
    # FIXME: Also, if you modify the variable then it will only work once.
    # The second time through, you'll change the value to
    # driveropts=driveropts=$BBDRIVEROPT
    BBDRIVEROPT=${BBDRIVEROPT:+driveropts="$BBDRIVEROPT"}

    # Check if CD is already written to
    if check_cd_status
    then
	ask_for_blanking && doit=1
    else
	doit=1
    fi
    if (( doit ))
    then
	if ${BB_CDBURNCMD} dev=${BBCDWRITER} speed=${BBSPEED} \
		${BBDTAO} ${BBDRIVEROPT} \
		$audio ${BBPADDING} -eject -v ${BBOBURN} "$@"
	then		#Burn audio cd
	    echo -e "\n$bb_burning_finish_1"
	    check_tempdel
	else
	    echo "$bb_burning_finish_2"
	    return 1
	fi
    fi
    return 0
}

# a function to burn audio cds.
# it looks for wav-files in the BBBURNDIR (/tmp/burn/)..
audio_burning()
{
    if ! check_for_wavs
    then
	echo -e "\n$bb_burning_audio_2 ${BBBURNDIR}"
    else
	shopt -s nocaseglob
        echo -e "*.wav being used..."
	if [[ "${BBNORMALIZE}" = yes ]]
	then
	    cd "${BBBURNDIR}"
	    ${BB_NORMCMD} -m *.wav
	else
	    echo $bb_burning_audio_3
	fi
	check_overburn		# Overburn enabled?
	_burning *.wav
	shopt -u nocaseglob
    fi
    wait_for_enter
}

################################# ISO ###################################

# to burn a .iso-file in the BURNDIR.
iso_burning()
{
    typeset imagetype
    if ! is_dir_empty ${BBBURNDIR}
    then
	check_overburn
	# Check for type of image, iso or img supported
	if [[ -n $(find ${BBBURNDIR} -iname '*.iso') ]]
	then
	    imagetype=iso
	elif [[ -n $(find ${BBBURNDIR} -iname '*.img') ]]
	then
	    imagetype=img
	else
	    message \
	"$bb_burning_error ${BBBURNDIR} *.iso or *.img file[s] not found?"
	    datadefine
	    return 0
	fi
	# Check if CD is already written to
	if ! _burning ${BBBURNDIR}/*.$imagetype
	then
	    echo "$bb_burning_finish_3 ${BBBURNDIR} ?"
	fi
    else
	echo "$bb_burning_error $BBBURNDIR"
    fi
}

################# DVD Image #########################################

# DVD support. Not as well tested as CD-burning, but should work just fine.

dvd_image_burn()
{
    typeset imagetype
    if ! is_dir_empty ${BBBURNDIR}
    then
	check_overburn
	# Check for type of image, iso or img supported
	if [[ -n $(find ${BBBURNDIR} -iname '*iso') ]]
	then
	    imagetype=iso
	elif [[ -n $(find ${BBBURNDIR} -iname '*img') ]]
	then
	    imagetype=img
	else
	    message \
	"$bb_burning_error ${BBBURNDIR}  *.iso or *.img file[s] not found?"
	    datadefine
	    return 0
	fi
	# check_cd_status	# FIXME: Why check? if CD is already written to
	
	# FIXME: This is wrong.
	if ${BB_DVDBURNCMD} -dvd-compat \
	    -Z ${BBCDWRITER}=${BBBURNDIR}/$(ls ${BBBURNDIR} | grep -i $imagetype)
	then
	    echo -e "\n$bb_burning_finish_1"
	    check_tempdel
	else
	    echo $bb_burning_finish_2
	    echo "$bb_burning_finish_3 ${BBBURNDIR} ?"
	fi
    else
	echo "$bb_burning_error $BBBURNDIR"
    fi
    wait_for_enter
}

################################### DATA ##################################

# This is a function to burn all files in /tmp/burn/ as a data-CD.
# It checks whether folder is empty, and if not creates an ISO from its
# contents and burns it. It does NOT check if the folder contains an ISO
# anymore. If it does, it creates an ISO containing an ISO and burns it.
# This is due to lots of people wanting this functionality. 

data_burning()
{
    if ! is_dir_empty ${BBBURNDIR}
    then
	BBLABELBACKUP=${BBLABEL}
	#### i want a question regarding the BBLABEL ####
	[[ "$BBLABEL" == '<ask-me>' ]] && read -e -p "$bb_burning_data_label" \
						BBLABEL
	if ${BB_ISOCMD} -r -f -v -J -joliet-long \
		-A "$BBDESCRIPTION" -p "$BBAUTHOR" -V "$BBLABEL" \
		-o ${BBBURNDIR}/BashBurn.iso ${BBBURNDIR}
	then
	    iso_burning			# call function - declared above
	    BBLABEL=${BBLABELBACKUP}	
	else
	    echo $bb_burning_data_2
	    echo $bb_burning_data_3
	    BBLABEL=${BBLABELBACKUP}
	fi
    else
	echo "$bb_burning_error $BBBURNDIR"
    fi
    wait_for_enter
}

################################### DVD Data #############################

# Preliminary DVD support. Not very well tested, use at your own risk.
# (However I do believe it should work as planned.)
# Better support will come in time.

dvd_data_burning()
{
    typeset -i status
    typeset bb_dvdsession

    if ! is_dir_empty ${BBBURNDIR}
    then
	BBLABELBACKUP=${BBLABEL}
   	[[ "$BBLABEL" == '<ask-me>' ]] && read -e -p "$bb_burning_data_label" \
						BBLABEL
	set_session_type
	status=$?
	case $status in
	0)
	    bb_dvdsession=-Z
	    ;;
	1)
	    bb_dvdsession=-M
	    ;;
	*)
	    return
	    ;;
	esac
	# FIXME: This is commented out because it doesn't do anything.
	# check_cd_status		# Check if CD is already written to
	if ${BB_DVDBURNCMD} $bb_dvdsession ${BBCDWRITER} ${BB_DVDBURNCMDOPTS} \
		-A "$BBDESCRIPTION" -p "$BBAUTHOR" \
		-V "$BBLABEL" ${BBBURNDIR}
	then
	    echo $bb_burning_finish_1
	    BBLABEL=${BBLABELBACKUP}
	else
	    echo $bb_burning_finish_2
	    BBLABEL=${BBLABELBACKUP}
	fi
    else
	echo "$bb_burning_error $BBBURNDIR"
    fi
    wait_for_enter
}

################################## DVD blank ##############################

set_blanking_dvd()
{
    typeset blanking_answer
    cat <<EOF
$bb_dvd_blank1
$bb_dvd_blank2
$bb_dvd_blank3
$bb_dvd_blank4
$bb_dvd_blank5

EOF
    read -e -p '(yes/no):' blanking_answer
    case "$blanking_answer" in
    yes)
	return 0
	;;
    no)
	return 1
	;;
    *)
	return 2
	;;
    esac
}

dvd_blanking()
{
    typeset -i status
    typeset blank
    set_blanking_dvd
    status=$?
    case $status in
    0)
	blank=-blank
	;;
    1)
	blank=-blank=full
	;;
    2)
	return
	;;
    esac
    if ${BB_DVDBLANK} $blank} ${BBCDWRITER}
    then
	echo $bb_cdrw_blank2
    else
	echo $bb_cdrw_blank5
    fi
    wait_for_enter
}
	    
################################## PIPELINE ##############################

# A function to do direct audio burning without creating wavs. This is
# butt ugly and might be removed or rewritten at one point. 

pipeline_burning()
{
    typeset -i counter=0
    typeset -i doit=0
    typeset fifolst=
    typeset commandlst=
    typeset fifo
    typeset file
    typeset pfile
    shopt -s nocaseglob

    if ! check_for_mp3s
    then
   	message "\n$bb_burning_audio_2 ${BBBURNDIR}"
    else
 	#fifo counter set to 0
	while read file
	do
	    if [[ ${file} =~ .MP3 ]]
	    then
		counter=counter+1
		fifo="${BBFIFODIR}/FIFO$$-${counter}"
		fifolst="${fifolst} ${fifo}"
		commandlst="${commandlst} -audio ${fifo}"
		mknod ${fifo} p; #equivalent to mkfifo $fifo
		${BB_MP3DEC} -qs "${file}" > ${fifo} &
		pfile=${file##*/}
		echo "${counter-MP3} ${pfile:0:35} flushed into ${fifo} (pipe)."
	    elif [[ ${file} =~ .WAV ]]
	    then
		counter=counter+1
		fifo="${BBFIFODIR}/FILE$$-${counter}.wav"
		fifolst="${fifolst} ${fifo}"
		ln -s "${file}" ${fifo}
		commandlst="${commandlst} -audio ${fifo}"
		pfile=${file##*/}
		echo "${counter-WAV} ${pfile:0:35}."
	    fi
	done < <(find ${BBBURNDIR} -iname \*.mp3 -o -iname \*.wav)
	
	(( counter == 0 )) && message "$bb_burning_fifo_1 ${BBBURNDIR}"
	echo "$bb_burning_fifo_2 ${counter} $bb_burning_fifo_2b"
	# Check if CD is already written to
	if check_cd_status
	then
	    ask_for_blanking && doit=1
	else
	    doit=1
	fi
	if (( doit ))
	then
	    ${BB_CDBURNCMD} dev=${BBCDWRITER} speed=${BBSPEED} \
		    ${BBDTAO} ${BBOPT_DRIVER:+"driver=$BBOPT_DRIVER"} \
		    fs=16m -swab -audio ${BBPADDING} -eject -v ${BBOBURN} \
		    ${commandlst}
	    echo $bb_burning_fifo_3
	    [[ -z "$fifolst" ]] || rm ${fifolst}
	    check_tempdel
	fi
    fi
    shopt -u nocaseglob
}
    
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
burning ()
{
    case "$1" in
    "--audio")
	audio_burning
	;;
    "--data")
	data_burning
	;;
    "--dvddata")
	dvd_data_burning
	;;
    "--dvdblank")
	dvd_blanking
	;;
    "--dvdimage")
	dvd_image_burn
	;;
    "--iso")
	iso_burning
	;;
    "--pipeline")
        pipeline_burning
	;;
    esac
}