Added new eject_opts option for greater flexibility.
[rip_dvd/.git] / rip_dvd.wrap
1 #!/bin/bash
2 # The purpose of this script is to encapsulate the calls
3 # made to the rip_dvd script. This is done to help distribute
4 # the resulting ripped files to the proper folders. This
5 # script is called from the mythtv menus for example with a
6 # smaller set of options.
7
8 ##############################################
9 # Don't run if a previous rip attempt is still running
10 SCRIPT_NAME1="rip_dvd.wrap"
11 SCRIPT_NAME2="xterm -T Ripping"
12 MY_PID=$$
13 PARENT_PID=$PPID
14 GRAND_PID=$(ps -ef | grep "^[a-zA-Z]* [ ]* $PARENT_PID " | awk '{print $3}')
15 GREAT_GRAND_PID=$(ps -ef | grep "^[a-zA-Z]* [ ]* $GRAND_PID " | awk '{print $3}')
16 ps -ef | grep -e "$SCRIPT_NAME1" -e "$SCRIPT_NAME2" | grep -v grep | grep -v $MY_PID | grep -v $PARENT_PID | grep -v $GRAND_PID | grep -v $GREAT_GRAND_PID
17 if [[ $? == 0 ]]; then
18   echo -e "-E- Found an instance of this script already running. Aborting this additional attempt to rip..."
19   echo -e "    my_pid=$MY_PID parent_pid=$PARENT_PID grand_pid=$GRAND_PID great_grand_pid=$GREAT_GRAND_PID\n"
20   CALLER=$(ps -ef | grep "^[a-zA-Z]* [ ]* $PPID " | awk '{print $3}')
21   CALLER_CALLER=$(ps -ef | grep "^[a-zA-Z]* [ ]* $CALLER " | awk '{print $3}')
22   echo I was called from $CALLER who was called by $CALLER_CALLER
23   ps -ef | grep $MY_PID | grep -v grep
24   ps -ef | grep $PARENT_PID | grep -v grep
25   exit 1
26 fi
27
28 ##############################################
29 # COMMAND LINE PROCESSING
30
31 # get the dvdtype from the command line
32 dvdtype=$1
33
34 # remove the dvdtype from the args, and interpret the rest
35 # of the args to be passed directly to the rip_dvd script.
36 shift 1
37
38 ##############################################
39 if [ -z "$dvdtype" ]; then
40   echo "-E- $0 <dvdtype>' is a required option"
41   exit 1
42 fi
43
44 mydir=$(cd $(dirname $0) && pwd)
45 if [ -z "$ripcmd" ]
46 then
47   if [ -x "$mydir/rip_dvd" ]
48   then
49     ripcmd="$mydir/rip_dvd"
50   else
51     echo >&2 "Cannot find your rip_dvd command!"
52     exit 1
53   fi
54 fi
55
56 ##############################################################################
57 # Local Machine Settings:
58 # Sources both the "default" conf file tracked by GIT (rip_dvd.conf.dist)
59 # and the local conf file created by each local machine (rip_dvd.conf)
60 # Copy the rip_dvd.conf.dist file to rip_dvd.conf and edit the later.
61 # This will allow you to override all the default values to meet your needs
62 # in a way that won't get clobbered when you pull updates from my GIT repo.
63 ##############################################################################
64 config="${0%/*}/rip_dvd.conf"
65
66 # The config file will be searched for in the following location order:
67 found_config=0
68
69 # 1) /path/to/rip_dvd/script/rip_dvd.conf.dist
70 [ -e "${config}.dist" ] && found_config=1 && . "${config}.dist"
71
72 # 2) /path/to/rip_dvd/script/rip_dvd.conf
73 [ -e "${config}" ] && found_config=1 && . "${config}"
74
75 # 3) /etc/rip_dvd.conf
76 [ -e "/etc/rip_dvd.conf" ] && found_config=1 && . "/etc/rip_dvd.conf"
77
78 # 4) $PWD/rip_dvd.conf
79 [ -e "$PWD/rip_dvd.conf" ] && found_config=1 && . "$PWD/rip_dvd.conf"
80
81 # Check to make sure we found the config file
82 if [ $found_config -eq 0 ]; then
83   echo "-E- Unable to find the rip_dvd.conf file: $config"
84   exit 1
85 fi
86
87 ##############################################
88 # get the name of the DVD from the DVD disk
89 dvdname=`volname $dev | awk '{ print $1 }'`
90 dvdname=${dvdname%.} # remove trailing '.' character
91
92 ##############################################
93 # Find out what type of DVD we are ripping
94 # And set our destination directory appropriately
95 # dvdtype parameter:
96 # - netflix = DVD ripped as an entire ISO image
97 #   since these are only kept around until we watch them,
98 #   there is no need to do anything less than full iso.
99 # - collection = Only DVD main feature is ripped
100 # - children = Only DVD main feature is ripped
101 # - church = Only DVD main feature is ripped
102 rip_opts="$* -j 2"
103 if [ "$dvdtype" == "netflix" ]; then
104   echo "-> Ripping Netflix DVD"
105   dest="$moviedir/Netflix"
106   rip_opts="$rip_opts"
107 elif [ "$dvdtype" == "collection" ]; then
108   echo "-> Ripping Personal Collection DVD"
109   dest="$moviedir/Collection"
110   rip_opts="$rip_opts"
111 elif [ "$dvdtype" == "children" ]; then
112   echo "-> Ripping Children's DVD"
113   dest="$moviedir/Children"
114   rip_opts="$rip_opts"
115 elif [ "$dvdtype" == "church" ]; then
116   echo "-> Ripping Church DVD"
117   dest="$moviedir/Church"
118   rip_opts="$rip_opts"
119 else
120   echo '-E- Must specify dvdtype as "netflix" or "collection" or "children" or "church"'
121   exit 1
122 fi
123
124 ##############################################
125 # Display progress window
126
127 # Pop up an xterm window and run the script inside of it
128 echo "xterm -T \"Ripping->$dvdname\" -geometry 72x15+20+10 -bg black -fg white -e \"/bin/bash\" -c \"$ripcmd -d $dest $rip_opts\" &"
129 xterm -T "Ripping->$dvdname" -geometry 72x15+20+10 -bg black -fg white -e "/bin/bash" -c "$ripcmd -d $dest $rip_opts" &
130
131 ##############################################
132 # OR display the script output directly in the terminal it's called from
133 #$ripcmd -d $dest $rip_opts
134
135 ##############################################