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