blob: dfdee0a8adabca222ae1021e598338ce26841028 (
plain)
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
|
#!/bin/bash
#
# Version 1.1 2006-03-27
#
# Exitcodes:
#
# exit 0 - no error
# exit 1 - mount/umount error
# exit 2 - no dvd in drive
# exit 3 - wrong dvd in drive / recording not found
# exit 4 - error while linking [0-9]*.vdr
#
# Errorhandling/Symlinking: vejoun@vdr-portal
#
# For dvd-in-drive detection download isodetect.c, compile it and put it into the PATH,
# usually /usr/local/bin/
#
#<Configuration>
MOUNTCMD="/usr/bin/sudo /bin/mount"
UMOUNTCMD="/usr/bin/sudo /bin/umount"
MOUNTPOINT="/media/cdrom" # no trailing '/'!
#</Configuration>
DEVICE="$(grep "$MOUNTPOINT" /etc/fstab | head -n1 | awk '{ print $1; }')" # dvd-device, used by isodetect if exists
REC="$2"
NAME="$3"
case "$1" in
mount)
# check if dvd is in drive, only if isodetect exists
if [ -n "$(which isodetect)" -a -n "$DEVICE" ]; then
isodetect -d "$DEVICE" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "no dvd in drive"
exit 2
fi
fi
# check if not mounted
$MOUNTCMD | grep "$MOUNTPOINT" >/dev/null && { echo "dvd already mounted"; exit 1; }
# mount dvd
$MOUNTCMD "$MOUNTPOINT" || { echo "dvd mount error"; exit 1; }
# is mounted?
# find recording on dvd
DIR="$(find "${MOUNTPOINT}/" -name "$NAME")"
# if not found, umount
if [ -z "$DIR" ]; then
$UMOUNTCMD "$MOUNTPOINT" || { echo "dvd umount error"; exit 1; }
echo "wrong dvd in drive / recording not found on dvd"
exit 3
fi
# link index.vdr if not exist
if [ ! -e "${REC}/index.vdr" ]; then
cp -s "${DIR}/index.vdr" "${REC}/"
fi
# link [0-9]*.vdr files
cp -s "${DIR}/"[0-9]*.vdr "${REC}/"
# error while linking [0-9]*.vdr files?
if [ $? -ne 0 ]; then
# umount dvd bevor unlinking
$UMOUNTCMD "$MOUNTPOINT" || { echo "dvd umount error"; exit 1; }
# unlink broken links
for LINK in "${REC}/"*.vdr; do
if [ -L "$LINK" -a ! -s "$LINK" ]; then
rm "$LINK"
fi
done
echo "error while linking [0-9]*.vdr"
exit 4
fi
;;
umount)
# check if dvd is mounted
$MOUNTCMD | grep "$MOUNTPOINT" >/dev/null || { echo "dvd not mounted"; exit 1; }
# is mounted?
# umount dvd bevor unlinking
$UMOUNTCMD "$MOUNTPOINT" || { echo "dvd umount error"; exit 1; }
# unlink broken links
for LINK in "${REC}/"*.vdr; do
if [ -L "$LINK" -a ! -s "$LINK" ]; then
rm "$LINK"
fi
done
;;
esac
exit 0
|