-
Notifications
You must be signed in to change notification settings - Fork 2
/
burn.sh
236 lines (222 loc) · 6.91 KB
/
burn.sh
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
#!/bin/bash
: <<COMMENT
Copyright (C) 2012 Tri Le <trile7 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 as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
COMMENT
#dependencies: cdrtools, dvd+rw-tools
#optional dependencies: mpg123 or lame or normalize to convert mp3 to wav for audio cd
version="burn v0.2"
burndir="/tmp/burndir"
tmpfile="/tmp/burn.txt"
menutitle=$version
blue='\e[0;34m'; green='\e[0;32m'; red='\e[0;31m'; yellow='\e[0;33m'; bold='\e[1m';none='\e[0m'
function menu {
n=0
choices=("$@")
echo -e "$blue$bold$menutitle"
for i in "${choices[@]}"; do
echo -e "$none$((n++))) $yellow$i"
done
echo -en "${none}c|q) ${yellow}Cancel"
echo -e $green
read -p "Enter a choice from above menu: " i
echo -e $none
[[ $i =~ c|q ]] && exit 1
if test $i -lt $n 2>/dev/null; then
choice=${choices[i]}; return $i
else
echo -e "$red$i is an invalid entry...please try again!"
menu "${choices[@]}"
fi
}
function burnmenu {
checksize
clear
echo "Drive: $DEV"
echo "Media: $DISCTYPE"
echo "Status: $DISCSTAT"
echo "Est. extra space: $EXTRASPACE MB"
echo "Data content: $burndir"
echo "Mode: $MODE"
echo
#Burn audio CD from mp3
if [[ $MODE = audio && $DISCTYPE = CD* && $cue ]]; then
cmd="cdrecord -v dev=$DEV driveropts=burnfree cuefile=$cue -text -raw -pad"
burndir=`dirname $burndir`
#Burn audio CD from WAV
elif [[ $MODE = audio && $DISCTYPE = CD* ]]; then
cmd="cdrecord -v dev=$DEV driveropts=burnfree -pad -audio *.wav"
#Burn video DVD
elif [[ $MODE = video && $DISCTYPE = DVD* ]]; then
vollabel
cmd="growisofs -dvd-video -udf -f -l -V ${VOLID:0:8} -Z $DEV $burndir"
#Burn data
elif [[ $MODE = data && $DISCTYPE = DVD* ]]; then
vollabel
cmd="growisofs -r -f -J -l -V ${VOLID:0:8} -Z $DEV $burndir"
elif [[ $MODE = data && $DISCTYPE = DVD* ]]; then
vollabel
cmd="growisofs -r -f -J -l -V ${VOLID:0:8} -M $DEV $burndir"
elif [[ $MODE = data && $DISCTYPE = CD* ]]; then
cmd="cdrecord -v -overburn -eject -multi dev=$DEV $burndir"
#Burn iso file
elif [[ $MODE = burniso && $DISCTYPE = DVD* ]]; then
cmd="growisofs -Z $DEV=$ISO"
elif [[ $MODE = burniso && $DISCTYPE = DVD* ]]; then
cmd="growisofs -M $DEV=$ISO"
elif [[ $MODE = burniso && $DISCTYPE = CD* ]]; then
cmd="cdrecord -v -eject -multi dev=$DEV $ISO"
#Make iso from burndir or DEV
elif [[ $MODE = makeiso ]]; then
read -p "ISO filename: " i
FNAME=${i:-$HOME/image.iso}
while [[ -e $FNAME ]]; do FNAME=${FNAME%.*}_1.iso; done
VOLID=`basename "$FNAME" .iso`
menu "Data content" "Video DVD content"
if [[ $? -eq 1 ]]; then
cmd="mkisofs -r -f -J -l -V ${VOLID:0:8} -o $FNAME $burndir"
else
cmd="mkisofs -dvd-video -udf -f -l -V ${VOLID:0:8} -o $FNAME $burndir"
fi
fi
echo "Burning command:"
echo "$cmd"
echo
menu "Burn" "Change device" "Drive and media info" "Erase RW media" "Refresh" "Mode menu"
case $? in
0) $cmd ;;
1) read -p "device path: " i
[[ -e $i ]] || echo "Device $i doesn't exist!"
DEV=${i:=$DEV}
burnmenu
;;
2) clear
cat $tmpfile
burnmenu
;;
3) if [[ $DISCTYPE = DVD-RW* ]]; then
dvd+rw-format $DEV
elif [[ $DISCTYPE = CD-RW* ]]; then
cdrecord dev=$DEV -v -eject blank=fast
else
echo "Media is not rewritable"
fi
burnmenu
;;
4) burnmenu ;;
5) modemenu ;;
esac
}
function modemenu {
burndir="/tmp/burndir"
if ISO=`ls | grep -m1 -i .iso`; then
MODE=burniso
burndir=$ISO
else
menu "Burn audio CD" "Burn video DVD" "Burn data" "Make ISO from $burndir content" "Make ISO from $DEV content"
case $? in
0) MODE=audio ;;
1) MODE=video ;;
2) MODE=data ;;
3) MODE=makeiso ;;
4) MODE=makeiso; burndir=$DEV ;;
*) exit 1 ;;
esac
fi
if [ $MODE = "audio" ]; then
read -p "Convert mp3s to wavs? (Y/n) " i
[[ $i = "n" ]] || mp3-wav
fi
burnmenu
}
function checksize {
echo "checking media and capcity..."
cdrecord dev=$DEV -minfo > $tmpfile
DISCTYPE=`grep "media type" $tmpfile|awk '{print $4}'`
DISCSIZE=`grep "writable size" $tmpfile|awk '{print $4}'`
DISCSTAT=`grep "disk status" $tmpfile|awk '{print $3}'`
DIRSIZE=`du -sLb $burndir|awk '{print $1}'`; DIRSIZE=$(( DIRSIZE / 2048 ))
EXTRASPACE=$(( (DISCSIZE-DIRSIZE)/512 ))
}
function vollabel {
read -p "Volume label: " i
VOLID=${i:=CDDVD}
}
function mp3-wav {
burndir=$burndir/WAV
mkdir -p $burndir
for i in *.mp3; do
[[ -f $i ]] || break
mpg123 -w "WAV/${i%.*}.wav" "$i" || lame --decode "$i" "WAV/${i%.*}.wav"
done
normalize -b $burndir/*.wav
cuesheet
}
function cuesheet {
cue=$burndir/cuesheet.cue
header=yes
for i in *.mp3; do
[[ -f $i ]] || continue
oIFS=$IFS; IFS=$'\n'
tags=(`id3info "$i" | egrep "TIT2|TPE1|TALB|TYER|TRCK" | awk -F ': ' '{print $2}'`)
IFS=$oIFS
title="${tags[0]}"
performer="${tags[1]}"
album="${tags[2]}"
year="${tags[3]}"
track="${tags[4]}"
if [[ $header = "yes" ]]; then
echo "REM COMMENT \"Enter genre, album title, album artist, and year in quote. This line can be removed.\"" > $cue
echo "REM GENRE \"\"" >> $cue
echo "REM YEAR \"$year\"" >> $cue
echo "TITLE \"$title\"" >> $cue
echo "PERFORMER \"Various Artist\""
header=no
fi
echo "FILE \"$burndir/${i%.*}.wav\" WAVE" >> $cue
echo " TRACK $track AUDIO" >> $cue
echo " PERFORMER \"$performer\"" >> $cue
echo " INDEX 01 00:00:00" >> $cue
done
$EDITOR $cue
}
function addfile {
[[ -e $1 ]] && ln -sf "$1" $burndir
}
mkdir -p $burndir
cd $burndir
case $1 in
--addfiles)
shift
for i; do addfile "$i"; done
exit 0 ;;
--help|-h)
tty -s || exit 1
echo "$0 --addfiles #add files to burn folder, then exit"
echo "$0 --help #print this, then exit"
echo "$0 filepath1 filepath2 .... #add files for burn folder, then start burn menu"
echo "$0 #start burn menu"
echo "To burn ISO file, copy/link it to burn folder. Only the first ISO file will be burned."
echo "Burn folder is located at $burndir"
exit 0 ;;
*)
for i; do addfile "$i"; done ;;
esac
tty -s || exit 1
DEV=(`ls /dev/sr*`)
if [[ ${#DEV[@]} -gt 2 ]]; then
menu ${DEV[@]}
DEV=${DEV[$?]}
fi
modemenu
read -p "Clear $burndir content? (Y/n) " i
[[ $i = "n" ]] || rm -Rf $burndir/*