1#!/usr/bin/env bash
2#
3# MyBashBurn.sh - This is the main shell scripts.
4#		  Show the main menu and doing some check.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU Library General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19#
20# $Id: MyBashBurn.sh 36 2007-05-29 00:59:12Z k0k $
21
22export BBDECOLINE="+------------------+"
23export BBVERSION=" MyBashBurn 1.0.2 "  # Version number
24export BBCONFFILE="/usr/local/etc/mybashburnrc"        # Config global file
25export BBCONFHOMEFILE="${HOME}/.mybashburnrc"   # Config user file
26export BBROOTDIR="/usr/local/share/mybashburn" # Where MyBashBurn is installed
27
28BBPROGNAME="mybashburn"
29PID="/tmp/mybashburn.lock"
30COLS=$(tput cols) # number of columns
31ROWS=$(tput lines) # number of rows
32
33# Detect signals as 'CTRL+C', INIT, KILL, call to function force_quit,
34# Show MyBashBurn info and quit.
35trap 'force_quit' 1 2 3 15
36
37# Set shell option
38shopt -s nocasematch
39
40# Function: Check cdialog program {{{1
41#-----------------------------------------------------------------------------
42function DialogCheck()
43{
44 if [[ $(type -t "cdialog") ]]; then
45   export DIALOG=$(which cdialog)
46 else
47   echo
48   echo -n "[ERROR] Dialog program no detect, please "
49   echo "install them before of use MyBashBurn."
50   echo
51   exit 1
52 fi
53}
54
55# Function: Check rootdir {{{1
56#-----------------------------------------------------------------------------
57function RootDirCheck()
58{
59if [[ ! -d "$BBROOTDIR" ]]; then
60  echo -e "Please read the INSTALL file for instrutions."
61  exit 1
62fi
63}
64
65# Function: Check for MyBashBurn settings {{{1
66#-----------------------------------------------------------------------------
67function SetupCheck()
68{
69 StatusBar "$bb_setup_check"
70 if [[ ${BBISCONF} = 0 ]]; then
71   ${DIALOG} --backtitle " $BACKTITLE " --title " $bb_information " \
72   --msgbox "$bb_conf_check1 $bb_conf_check2" 0 0
73   # Loading setup menu
74   StatusBar "$bb_loading $bb_menu_7 ..."
75   ${BBROOTDIR}/config/configure.sh
76   # And in case we changed any options, read in vars again
77   source ${BBROOTDIR}/misc/variables.idx
78 fi
79}
80
81# Function: Check for burndir (temporary directory) {{{1
82#-----------------------------------------------------------------------------
83function BurnDirCheck()
84{
85StatusBar "$bb_checking ${BBBURNDIR} ..."
86 if [[ ! -e "${BBBURNDIR}" ]]; then
87   StatusBar "$bb_no_temp_dir"
88   if mkdir "${BBBURNDIR}"; then
89     StatusBar "'${BBBURNDIR}' ${bb_text_1}"
90     StatusBar "$bb_text_2"
91   else
92     StatusBar "${bb_text_3} '${BBBURNDIR}'"
93     StatusBar " $bb_text_4"
94     wait_for_enter
95   fi
96 fi
97}
98
99# Function: Template config file {{{1
100#-----------------------------------------------------------------------------
101ApplyDefault()
102{
103cat << EOF >"${BBCONFHOMEFILE}"
104##############################
105## CONFIGFILE OF MYBASHBURN ##
106##############################
107#
108# Top level configuration for the MyBashBurn program
109# License: GPL v2 (http://www.gnu.org/licenses/gpl.html)
110
111# Is it configured?
112BBISCONF: 0
113
114#########################################
115# General:				#
116#########################################
117
118# location of cd writer:
119BBCDWRITER: <Change me>
120
121# location of cdrom device file:
122BBCDROM: <Change me>
123
124# location of cdrom mount point:
125BBCDMNT: <Change me>
126
127# the speed of your burner:
128BBSPEED: -1
129
130# type of blanking
131BBBLANKING: fast
132
133# number of devices
134BBNUMDEV: 1
135
136# where MyBashBurn is installed
137BBROOTDIR: /usr/local/share/mybashburn
138
139# where files to be burnt are located
140BBBURNDIR: /tmp/burn
141
142# fifo dir for piped burning of audio cds
143BBFIFODIR: /tmp
144
145#########################################
146# Information of the CD:		#
147#########################################
148# the following informations are also   
149# burnt on every CD. If you want, fill	
150# them, but it's not necessary.		
151
152# you copyright:
153BBCOPYRIGHT: GPL
154
155# a short description of the content of the CD:
156BBDESCRIPTION: Burn with MyBashBurn
157
158# the author - hey, that's you, isn't it?
159BBAUTHOR: <Change me>
160
161# the publisher:
162BBPUBLISHER: <Change me>
163
164# the name of a package 
165# (a package are several CDs belonging to one package -
166#  that's important e.g. for distributions)
167BBNAMEOFPACKAGE: <Change me>
168
169# label of the cd
170BBLABEL: MyBashBurn CD
171
172#################################
173# Misc Options 			#
174#################################
175
176# use normalize or not. Default is no.
177BBNORMALIZE: no
178
179# driver options. For example burnsafe or swabaudio. 
180# leave this blank if unsure. default is nothing.
181BBOPT_ONE: 
182
183# whether to delete temp files after burn.
184# default is no
185BBDELTEMPBURN: no
186
187# whether MyBashBurn should support overburn.
188# default is no
189BBOVERBURN: no
190
191# whether MyBashBurn should indicate that audio data should be copy protected
192# default is no
193BBCOPY_PROTECT: no
194
195# Set bitrate for encoding
196# default 128
197BBBITRATE: 128
198
199# The language for MyBashBurn
200# default is English
201BBLANG: English
202
203# DAO or TAO mode
204BBDTAO: -tao
205
206EOF
207}
208
209# Function: Read global variables {{{1
210#-----------------------------------------------------------------------------
211function ReadVar()
212{
213# export BBROOTDIR="$( cat $BBCONFFILE | grep -v '^#' | grep BBROOTDIR:  | cut -d ":" -f 2- | sed -e "s/^[[:blank:]]//g")"
214 source ${BBROOTDIR}/misc/commands.idx
215 source ${BBROOTDIR}/misc/variables.idx
216 export BBTEMPMOUNTDIR="${BBBURNDIR}/mnt"
217 # Read in the language file
218 source ${BBROOTDIR}/lang/${BBLANG}/MyBashBurn.lang
219 # Read in common functions
220 source ${BBROOTDIR}/misc/commonfunctions.sh
221 # colors
222 source $BBROOTDIR/misc/colors.idx
223}
224
225# Function: PID make/check and show warnings if there is anothers instance {{{1
226#-----------------------------------------------------------------------------
227function PidMake()
228{
229 StatusBar "$bb_pid_make"
230 if ! mkdir ${PID}
231   then    # directory exist, but was created successfully
232   ${DIALOG} --backtitle "$BBVERSION" \
233   --title " $bb_information " --defaultno \
234   --yesno "$bb_pid_make_message1 ${PID}, $bb_pid_make_message2\n\n $bb_pid_make_message3" 0 0
235   if [[ $? -ne '0'  ]]; then	# if found lockdir exit
236     exit 1 # force_quit delete PID, instead to using exit.
237   fi
238 fi
239}
240
241# Function: PID remove {{{1
242#-----------------------------------------------------------------------------
243function PidRemove()
244{
245 StatusBar "$bb_pid_remove"
246 rm -fr $PID     # remove lock dir when finishes
247}
248
249# Function: Terminal size check {{{1
250#-----------------------------------------------------------------------------
251function TermCheck()
252{
253 StatusBar "$bb_term_check_message1"
254 if [ "${COLS}" -lt 80 ] || [ "${ROWS}" -lt 25 ]; then
255   StatusBar "$bb_term_check_message2 ${COLS}x${ROWS} $bb_failed"
256   exit 1
257 fi
258}
259
260# Function: Terminal reset {{{1
261#-----------------------------------------------------------------------------
262function SetTerm() # Thanks Costin Stroie
263{
264 # Move the cursor on upper-left corner and clear the entire screen
265 tput clear
266 # Make cursor normal visible
267 tput cnorm
268 # Exit special mode
269 tput rmcup
270}
271
272# Function: Load the settings {{{1
273#-----------------------------------------------------------------------------
274function LoadSettings()
275{
276 echo -n "Loading ..."
277 if [[ -r "${BBCONFFILE}" ]]; then  # search for config admin /usr/local/etc/mybashburnrc
278   ReadVar
279 elif [[ -r "${BBCONFHOMEFILE}" ]]; then  # search for config user ~/.mybashburnrc
280   BBCONFFILE="${BBCONFHOMEFILE}"
281   ReadVar
282 else
283   ApplyDefault
284   BBCONFFILE="${BBCONFHOMEFILE}"
285   ReadVar
286 fi
287}
288
289# Run: The init load function part {{{1
290#-----------------------------------------------------------------------------
291tput clear # clear term
292RootDirCheck
293LoadSettings
294DialogCheck
295TermCheck
296PidMake
297BurnDirCheck
298SetupCheck
299
300# Run: The main menu part {{{1
301#-----------------------------------------------------------------------------
302MakeTempFile
303while true; do
304StatusBar "$bb_loading $bb_main_menu ..."
305# <menu>
306 $DIALOG $OPTS --help-label "$bb_help_button" \
307   --backtitle "$BACKTITLE" \
308   --begin 2 2 --title " $bb_main_menu " \
309   --cancel-label $bb_menu_0 \
310   --menu "$bb_menu_input" 0 0 0 \
311  "1)" "$bb_menu_1" \
312  "2)" "$bb_menu_2" \
313  "3)" "$bb_menu_3" \
314  "4)" "$bb_menu_4" \
315  "5)" "$bb_menu_5" \
316  "6)" "$bb_menu_6" \
317  "7)" "$bb_menu_7" \
318  "8)" "$bb_menu_8 ${BBBURNDIR}" \
319  "9)" "$bb_menu_9" \
320  "10)" "$bb_menu_10" \
321  "11)" "$bb_menu_11" 2>${TMPFILE}
322STDOUT=$?	# Return status
323EventButtons 0
324ReadAction	# Return value $action
325# </menu>
326case $action in
327	1\))	# If you chose audio, do:
328		StatusBar "$bb_loading $bb_menu_1 ..."
329		${BBROOTDIR}/menus/audio_menu.sh
330		continue
331		;;
332	2\)) 	# If you chose data, do:
333		StatusBar "$bb_loading $bb_menu_2 ..."
334		${BBROOTDIR}/menus/data_menu.sh
335		continue
336		;;
337	3\))	#If you chose ISO, do:
338		StatusBar "$bb_loading $bb_menu_3 ..."
339		${BBROOTDIR}/menus/iso_menu.sh
340		continue
341		;;
342	4\))	#Burn an bin/cue file:
343		StatusBar "$bb_loading $bb_menu_4 ..."
344		${BBROOTDIR}/burning/bincue.sh
345		;;
346	5\))	#Multisession - Alrighty then...
347		StatusBar "$bb_loading $bb_menu_5 ..."
348		${BBROOTDIR}/burning/multi.sh
349		continue
350		;;
351	6\))	#If you chose to blank a CDRW
352		StatusBar "$bb_loading $bb_menu_6 ..."
353		check_cd_status
354
355		if [ ${BB_CDSTATUS} == "BLANK" ]; then
356		  StatusBar "$bb_cdrw_blank6"
357		  ShowWarn && wait_for_enter
358		else
359		  blank_cd
360		fi
361  		  continue
362		;;
363	7\))	# If you choose to configure MyBashBurn:
364		StatusBar "$bb_loading $bb_menu_7 ..."
365		${BBROOTDIR}/config/configure.sh
366		# And in case we changed any options, read in vars again
367		source ${BBROOTDIR}/misc/variables.idx
368		continue
369		;;
370	8\))	# Mount/unmount a cd
371		StatusBar "$bb_loading $bb_menu_8 ..."
372		${BBROOTDIR}/misc/mount.sh
373		continue
374		;;
375	9\))	# Check program's paths of burning, ripped, codecs, etc.
376		StatusBar "$bb_loading $bb_menu_9 ..."
377		${BBROOTDIR}/misc/check_path.sh
378		continue
379		;;
380	10\))	# Copy/link data to the temporary burn dir
381		StatusBar "$bb_loading $bb_menu_10 ..."
382		${BBROOTDIR}/misc/datadefine.sh
383		continue
384		;;
385	11\))	# Credits.
386		$DIALOG $OPTS --fixed-font --exit-label $bb_return \
387		--backtitle " $BACKTITLE " --title " $bb_menu_11 " \
388		--textbox "${BBROOTDIR}/CREDITS" 25 77
389		;;
390	esac
391done
392
393# vim: set ft=sh nowrap nu foldmethod=marker:
394