-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.func
390 lines (358 loc) · 11.6 KB
/
common.func
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
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# burnCDDA is a shell script for burning Audio-CDs with
# cdrdao and cdrecord.
#
# (C) 2001 by Thorsten Muehlfelder <~thenktor~at~gmail~dot~com~>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License (version 2)
# as published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#------------------------------------------------------------------------------
# create IMGDIR
function createimgdir()
{
if [ ! -e "$IMGDIR" ]; then
echo "Creating '$IMGDIR'"
mkdir -p "$IMGDIR"
echo -e "${BLUE}Press any key${NOCOLOR}"
read -n1
fi
}
# check for required tools
function checkreqtools()
{
DIALOG=`which $DIALOG`
if [ "$DIALOG" = "" ]; then
echo -e "${RED}ERROR:${NOCOLOR} Required tool 'dialog' not found!"
echo "This is a standard tool and should be installed on every system."
echo "Check your '$PATH' or set the right path in '/etc/burncdda.conf'!"
exit1 # common.func
fi
SED=`which $SED`
if [ "$SED" = "" ]; then
echo -e "${RED}ERROR:${NOCOLOR} Required tool 'sed' not found!"
echo "This is a standard tool and should be installed on every system."
echo "Check your '$PATH' or set the right path in '/etc/burncdda.conf'!"
exit1 # common.func
fi
GAWK=`which $GAWK`
if [ "$GAWK" = "" ]; then
echo -e "${RED}ERROR:${NOCOLOR} Required tool 'gawk' not found!"
echo "This is a standard tool and should be installed on every system."
echo "Check your '$PATH' or set the right path in '/etc/burncdda.conf'!"
exit1 # common.func
fi
FIND=`which $FIND`
if [ "$FIND" = "" ]; then
echo -e "${RED}ERROR:${NOCOLOR} Required tool 'find' not found!"
echo "This is a standard tool and should be installed on every system."
echo "Check your '$PATH' or set the right path in '/etc/burncdda.conf'!"
exit1 # common.func
fi
}
# tests if the source file exists and loads it
function testsource()
{
if [ -r "$1" ]; then
source "$1"
else
echo "Fatal error!"
echo "File not found: $1"
exit1
fi
}
# forced kill
function forcedkill()
{
test -e "$TEMPFILE" && rm -f "$TEMPFILE"
test -e "$TEXTFILE" && rm -f "$TEXTFILE"
test -e "$DIRFILE" && rm -f "$DIRFILE"
echo -e "Caught an exit signal...\n${RED}Terminating${NOCOLOR}"
exit 0
}
# normal exit, status 0
function exit0()
{
test -e "$TEMPFILE" && rm -f "$TEMPFILE"
test -e "$TEXTFILE" && rm -f "$TEXTFILE"
test -e "$DIRFILE" && rm -f "$DIRFILE"
echo -e "${GREEN}Bye...${NOCOLOR}"
exit 0
}
# normal exit, status 1
function exit1()
{
test -e "$TEMPFILE" && rm -f "$TEMPFILE"
test -e "$TEXTFILE" && rm -f "$TEXTFILE"
test -e "$DIRFILE" && rm -f "$DIRFILE"
echo -e "Something went wrong...\n${YELLOW}Aborting${NOCOLOR}"
exit 1
}
# counts files in playlist (MAXN), counts lines in playlist (MAXLN)
function filecount()
{
MAXLN=`$GAWK 'END {print NR}' "$PLAYLIST"`
MAXN=$MAXLN-`$GAWK 'BEGIN {FS = "#"} {if (NF > 1 && $1 == "") print $2}' "$PLAYLIST" | $WC -l`
}
# create image info file
function imageinfofile()
{
echo "TOCFILE: $CDNAME.toc" > IMAGEINFO
echo "DATAFILE: $CDNAME.bin" >> IMAGEINFO
FILESIZE=`ls -l "$CDNAME.bin" | $GAWK '{print $5}'`
FILETIME=($FILESIZE/176400)
MINUTES=($FILETIME/60)
SECONDS=`expr $FILETIME % 60`
FILESIZE=($FILESIZE/1048576)
echo "SIZE: $FILESIZE MiB" >> IMAGEINFO
if [ $SECONDS -le 9 ]; then
echo "DISCLENGTH: $MINUTES:0$SECONDS" >> IMAGEINFO
else
echo "DISCLENGTH: $MINUTES:$SECONDS" >> IMAGEINFO
fi
}
# burn with cdrecord function
function burncdrecord()
{
if [ "$CDEXTRA" = "0" ]; then
$CDRECORD "dev=$DEVICE" "speed=$WRITESPEED" $DRIVEROPTS $OTHERREC $WMODE -audio "$IMGDIR/$WAVNAME/$WAVNAME".*.wav
if [ ! $? = "0" ]; then
echo -e "\n${RED}WARNING:${NOCOLOR} Something went wrong!\n"
fi
else
$CDRECORD "dev=$DEVICE" "speed=$WRITESPEED" $DRIVEROPTS $OTHERREC $WMODEEXTRA1 -audio -multi "$IMGDIR/$WAVNAME/$WAVNAME".*.wav
if [ ! $? = "0" ]; then
echo -e "\n${RED}WARNING:${NOCOLOR} Something went wrong!"
echo -e "${BLUE}Press any key to cancel${NOCOLOR} (type d to write data session)"
read -n1 KEY
if [ "$KEY" = "d" -o "$KEY" = "D" ]; then
echo -e "\nTrying to write data session...\n"
else
LNSELECTED=$LNSELECTED+1
continue
fi
else
echo -e "${GREEN}First session written.${NOCOLOR}\n"
fi
sleep 1
echo -n "Getting size of first session: "
CDEXTRAOFFSET=$($CDRECORD "dev=$DEVICE" -msinfo 2>&1)
if [ ! $? = "0" ]; then
echo -e "-\n\n${RED}ERROR:${NOCOLOR} Couldn't get size of first session!"
echo -e "${BLUE}Press any key to cancel${NOCOLOR}"
read -n1
LNSELECTED=$LNSELECTED+1
continue
else
echo -e "$CDEXTRAOFFSET sectors.\n"
fi
sleep 1
# on the fly
$MKISOFS -r -J -joliet-long -l -quiet -C $CDEXTRAOFFSET -V "CD-EXTRA" "$IMGDIR/$WAVNAME/CD-EXTRA/" 2> /dev/null \
| $CDRECORD "dev=$DEVICE" "speed=$WRITESPEED" $DRIVEROPTS $OTHERREC $WMODEEXTRA2 -tsize=${CDEXTRATSIZE}s -data -
if [ ! $? = "0" ]; then
echo -e "\n${RED}WARNING:${NOCOLOR} Something went wrong!\n"
fi
# step by step
#$MKISOFS -r -J -joliet-long -l -quiet -C $CDEXTRAOFFSET -V "CD-EXTRA" -o "$IMGDIR/$WAVNAME/CD-EXTRA.iso" "$IMGDIR/$WAVNAME/CD-EXTRA/"
#$CDRECORD "dev=$DEVICE" "speed=$WRITESPEED" $DRIVEROPTS $OTHERREC $WMODE -tsize=${CDEXTRATSIZE}s -data "$IMGDIR/$WAVNAME/CD-EXTRA.iso"
fi
}
# command line options
function commandlineopts()
{
case $1 in
-c)
PLAYLIST="$2"
if [ "$PLAYLIST" = "" ]; then
echo -e "\n${RED}ERROR:${NOCOLOR} you have to specify a playlist"
exit1 # common.func
fi
M3U=`echo "$PLAYLIST" | $TAIL -c4 | $TR [:upper:] [:lower:]`
if [ ! -r "$PLAYLIST" ]; then
echo -e "\n${RED}ERROR:${NOCOLOR} $PLAYLIST does not exist or is not readable"
exit1 # common.func
fi
if [ "$M3U" != "m3u" ]; then
echo -e "\n${RED}ERROR:${NOCOLOR} $PLAYLIST is not a M3U file"
exit1 # common.func
fi
clear
filecount # common.func
checkm3u # checkm3u.func
echo ""
exit0 # common.func
;;
-cd)
# search files, sort them, remove ./ from the beginning, remove m3u... from list
$FIND . -maxdepth 1 -type f | $SORT | $SED 's#^\./##' | $GREP -E -i -v "(\.m3u$|\.txt$|\.jpg$|\.png$|\.gif$|\.bmp$|\.zip$|\.rar$|\.url$|\.log$|\.cue$|\.csv$)" > $DIRFILE
PLAYLIST="$DIRFILE"
clear
filecount # common.func
checkm3u # checkm3u.func
echo ""
exit0 # common.func
;;
-b)
# check the size of the terminal
if [ ${COLS} -lt 80 -o ${ROWS} -lt 24 ]; then
echo -e "${RED}ERROR:${NOCOLOR} Your terminal is too small!"
echo "Minimum size is 80x24 but you have only ${COLS}x${ROWS} :-("
exit1 # common.func
fi
PLAYLIST="$2"
if [ "$PLAYLIST" = "" ]; then
echo -e "\n${RED}ERROR:${NOCOLOR} you have to specify a playlist"
exit1 # common.func
fi
M3U=`echo "$PLAYLIST" | $TAIL -c4 | $TR [:upper:] [:lower:]`
if [ ! -r "$PLAYLIST" ]; then
echo -e "\n${RED}ERROR:${NOCOLOR} $PLAYLIST does not exist or is not readable"
exit1 # common.func
fi
if [ "$M3U" != "m3u" ]; then
echo -e "\n${RED}ERROR:${NOCOLOR} $PLAYLIST is not a M3U file"
exit1 # common.func
fi
# WAVNAME = PLAYLIST without .m3u and without path
WAVNAME=`basename "$PLAYLIST" | $SED s/'\.'[Mm]3[Uu]$//`
if [ -e "$IMGDIR/$WAVNAME" ]; then
echo -e "\n${RED}ERROR:${NOCOLOR} $WAVNAME already exists. Please delete the existing WAVs!"
exit1 # common.func
fi
# go to m3u directory
cd $(dirname "$PLAYLIST")
# burning options
CHECKLISTOPTS=`echo -e "Normalize CD tracks?\0255option\0255off\0255Create CD-Extra?\0255option\0255off"`
IFS="$(echo -e "\0255")"
# select options and writes the selectet options to $TEXTFILE
$DIALOG --backtitle "$BACKTITLE" --title "Burn playlist/directory to Audio-CD" --separate-output \
--checklist "${WAVNAME}: Change options with spacebar" 12 60 2 $CHECKLISTOPTS 2> $TEXTFILE
if [ $? = "1" ]; then
IFS="$IFSBAK"
clear
exit0
fi
IFS="$IFSBAK"
# quick and dirty method to set options according to $TEXTFILE
NORMSET="0"
$GREP "Normalize CD tracks" $TEXTFILE > /dev/null && NORMSET="1"
CDEXTRA="0"
$GREP "Create CD-Extra" $TEXTFILE > /dev/null && CDEXTRA="1"
# count files
filecount # common.func
# checks playlist for more than 99 tracks
if [ $MAXN -gt 99 ]; then
$DIALOG --backtitle "$BACKTITLE" --title "$ERROR" \
--msgbox "There are $MAXN files in '$PLAYLIST' but you cannot burn more than 99 tracks." 6 60
MENULEVEL=0
clear
continue
fi
# decode and normalize
clear
decodenorm
echo -e "${BLUE}Insert CD-R and press Enter${NOCOLOR} (type c to cancel)"
read -n1 KEY
if [ "$KEY" = "c" -o "$KEY" = "C" ]; then
echo ""
exit0 # common.func
fi
# burn
# we need the while loop as workaround to use the same burncdrecord function like in main program
LNSELECTED=1
MAXLNSELECTED=1
while [ $LNSELECTED -le $MAXLNSELECTED ]; do
burncdrecord # common.func
LNSELECTED=$LNSELECTED+1
done
echo ""
exit0 # common.func
;;
-bd)
# check the size of the terminal
if [ ${COLS} -lt 80 -o ${ROWS} -lt 24 ]; then
echo -e "${RED}ERROR:${NOCOLOR} Your terminal is too small!"
echo "Minimum size is 80x24 but you have only ${COLS}x${ROWS} :-("
exit1 # common.func
fi
# search files, sort them, remove ./ from the beginning, remove m3u... from list
$FIND . -maxdepth 1 -type f | $SORT | $SED 's#^\./##' | $GREP -E -i -v "(\.m3u$|\.txt$|\.jpg$|\.png$|\.gif$|\.bmp$|\.zip$|\.rar$|\.url$|\.log$|\.cue$)" > $DIRFILE
PLAYLIST="$DIRFILE"
WAVNAME=`basename "$STARTDIR"`
if [ -e "$IMGDIR/$WAVNAME" ]; then
echo -e "\n${RED}ERROR:${NOCOLOR} $WAVNAME already exists. Please delete the existing WAVs!"
exit1 # common.func
fi
# burning options
CHECKLISTOPTS=`echo -e "Normalize CD tracks?\0255option\0255off\0255Create CD-Extra?\0255option\0255off"`
IFS="$(echo -e "\0255")"
# select options and writes the selectet options to $TEXTFILE
$DIALOG --backtitle "$BACKTITLE" --title "Burn playlist/directory to Audio-CD" --separate-output \
--checklist "${WAVNAME}: Change options with spacebar" 12 60 2 $CHECKLISTOPTS 2> $TEXTFILE
if [ $? = "1" ]; then
IFS="$IFSBAK"
clear
exit0
fi
IFS="$IFSBAK"
# quick and dirty method to set options according to $TEXTFILE
NORMSET="0"
$GREP "Normalize CD tracks" $TEXTFILE > /dev/null && NORMSET="1"
CDEXTRA="0"
$GREP "Create CD-Extra" $TEXTFILE > /dev/null && CDEXTRA="1"
# count files
filecount # common.func
# checks playlist for more than 99 tracks
if [ $MAXN -gt 99 ]; then
$DIALOG --backtitle "$BACKTITLE" --title "$ERROR" \
--msgbox "There are $MAXN files in '$PLAYLIST' but you cannot burn more than 99 tracks." 6 60
MENULEVEL=0
clear
continue
fi
# decode and normalize
clear
decodenorm
echo -e "${BLUE}Insert CD-R and press Enter${NOCOLOR} (type c to cancel)"
read -n1 KEY
if [ "$KEY" = "c" -o "$KEY" = "C" ]; then
echo ""
exit0 # common.func
fi
# burn
# we need the while loop as workaround to use the same burncdrecord function like in main program
LNSELECTED=1
MAXLNSELECTED=1
while [ $LNSELECTED -le $MAXLNSELECTED ]; do
burncdrecord # common.func
LNSELECTED=$LNSELECTED+1
done
echo ""
exit0 # common.func
;;
"")
;;
*)
echo "Usage: burncdda [option] file"
echo " -b Burn M3U playlist"
echo " -bd Burn files in current directory"
echo " -c Check files in M3U playlist"
echo " -cd Check files in current directory"
echo ""
echo "Without command line options the dialog interface will be started"
echo "Try 'man burncdda' for more information!"
exit0 # common.func
;;
esac
}