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