version 2.3-beta

This commit is contained in:
marc
2012-10-06 18:06:19 +02:00
parent 9b179d120d
commit 76c0a1a3c3

View File

@@ -1,13 +1,13 @@
#!/bin/bash #!/bin/bash
# #
# Version 2.1 2006-06-02 # Version 2.3-beta 2006-07-14
# #
# Author: Mike Constabel # Author: Mike Constabel
# VDR-Portal: vejoun # VDR-Portal.de: vejoun
# EMail: vejoun @ toppoint.de # EMail: vejoun at toppoint dot de
# WWW: http://www.constabel.net/vdr/scripts.htm # WWW: http://www.constabel.net/vdr/scripts.de.htm
# #
# ---> CONFIGURATION AT LINE 79 <--- # ---> CONFIGURATION AT LINE 83 <---
# #
# MANUAL: # MANUAL:
# ------- # -------
@@ -35,7 +35,7 @@
# You find isodetect.c in the extrecmenu plugin source package. # You find isodetect.c in the extrecmenu plugin source package.
# #
# 4. # 4.
# Tools needed: mount, awk, find, test, stat # Tools needed: mount, awk, find, test, stat, sed
# Optional tools: isodetect # Optional tools: isodetect
# #
# 5. # 5.
@@ -47,7 +47,7 @@
# If something went wrong, set DEBUG=1 and send me the file which is defined in $DEBUGLOG. # If something went wrong, set DEBUG=1 and send me the file which is defined in $DEBUGLOG.
# Use VDR-Portal or EMail. # Use VDR-Portal or EMail.
# #
# 7. # 7.
# Exitcodes: # Exitcodes:
# #
# exit 0 - no error # exit 0 - no error
@@ -59,30 +59,47 @@
# #
# HISTORY: # HISTORY:
# -------- # --------
# 2.1 - Fixed bug in testing if dvd is mounted # 2006-07-14: Version 2.3-beta
#
# - should be compatible with ash, busybox
# stays beta until someone confirm this or 2.4 comes
#
# 2006-06-13: Version 2.2
#
# - at mount, if third parameter is not given, take last part of path
#
# Version 2.1
#
# - Fixed bug in testing if dvd is mounted
# - more DEBUG=1 output # - more DEBUG=1 output
# #
# 2.0 - more logging # Version 2.0
#
# - more logging
# - check if mountpoint and device exists # - check if mountpoint and device exists
# - Debug Log in file $DEBUGLOG if $DEBUG is 1, for easier error reporting # - Debug Log in file $DEBUGLOG if $DEBUG is 1, for easier error reporting
# #
# 1.9 - use "sudo mount --bind" for mounting if filesystem is vfat # Version 1.9
#
# - use "sudo mount --bind" for mounting if filesystem is vfat
# - automatic fallback to 'sudo' and 'mount --bind' if filesystem is vfat # - automatic fallback to 'sudo' and 'mount --bind' if filesystem is vfat
# - mounting more failure tolerant # - mounting more failure tolerant
# - added MANUAL part in script # - added MANUAL part in script
# - length.vdr creation, you must not use it ;) # - length.vdr creation, you must not use it ;)
# #
# 1.8 - remove sudo, is not necessary # Version 1.8
#
# - remove sudo, is not necessary
# - on mount, if already mounted try to umount first # - on mount, if already mounted try to umount first
# - logging per syslog, see $SYSLOG # - logging per syslog, see $SYSLOG
# #
set -x
# CONFIGURATION # CONFIGURATION
# ------------- # -------------
#<Configuration> #<Configuration>
set -x
exec 2>/tmp/da.log
# Mountpoint, the same as in fstab # Mountpoint, the same as in fstab
MOUNTPOINT="/media/hdext" # no trailing '/' MOUNTPOINT="/media/hdext" # no trailing '/'
@@ -93,48 +110,83 @@ EJECTWRONG=0
EJECTUMOUNT=0 EJECTUMOUNT=0
# Log warnings/errors in syslog. 1 = yes, 0 = no. # Log warnings/errors in syslog. 1 = yes, 0 = no.
SYSLOG=0 SYSLOG=1
# Create a length.vdr after mounting the dvd for the played recording. 1 = yes, 0 = no. # Create a length.vdr after mounting the dvd for the played recording. 1 = yes, 0 = no.
# Only for non-vfat and with index.vdr only on dvd. # Only for non-vfat and with index.vdr only on dvd.
GETLENGTH=0 GETLENGTH=1
# Put debug infos in file $DEBUGLOG. Only if $DEBUG=1. # Put debug infos in file $DEBUGLOG. Only if $DEBUG=1.
DEBUG=0 DEBUG=0
DEBUGLOG="/tmp/dvdarchive.sh-debug.log" DEBUGLOG="/tmp/dvdarchive.sh-debug.log"
#</Configuration> #</Configuration>
# read config file
. /etc/vdr/dvdarchive.conf
# #
# No changes needed after this mark # No changes needed after this mark
# Remove trailing slash # Remove trailing slash
MOUNTPOINT=${MOUNTPOINT/%\/} MOUNTPOINT="$(echo "${MOUNTPOINT}" | sed -e 's/\/$//')"
if [ -L "$MOUNTPOINT" ]; then if [ -L "$MOUNTPOINT" ]; then
MOUNTPOINTT="$(find "$MOUNTPOINT" -printf "%l")" MOUNTPOINTT="$(find "$MOUNTPOINT" -printf "%l")"
else else
MOUNTPOINTT="$MOUNTPOINT" MOUNTPOINTT="$MOUNTPOINT"
fi fi
# determine dvd-device, used by eject and isodetect if exists
DEVICE="$(awk '( $1 !~ /^#/ ) && ( $2 == "'$MOUNTPOINT'" ) { printf("%s", $1); exit; }' /etc/fstab)" # Search a device mounted on $MOUNTPOINT or not mounted
DEVICE=$(mount | grep $MOUNTPOINT | awk '{print $1}')
if [ -Z $DEVICE ]; then
disks=$(cat /proc/partitions | egrep "sd[a-z][0-9]" | awk '{printf("/dev/%s\n", $4)}')
mounted=$(mount | grep /dev/sd | awk '{print $1}')
for d in $disks; do
found=0
for m in $mounted; do
if [ $d == $m ]; then
found=1
break
fi
done
if [ $found == 0 ]; then
echo "not found: $d -> mounting"
DEVICE=$d
fi
done
fi
if [ -Z $DEVICE ]; then
# determine dvd-device, used by eject and isodetect if exists
DEVICE="$(awk '( $1 !~ /^#/ ) && ( $2 == "'$MOUNTPOINT'" ) { printf("%s", $1); exit; }' /etc/fstab)"
fi
if [ -L "$DEVICE" ]; then if [ -L "$DEVICE" ]; then
DEVICET="$(find "$DEVICE" -printf "%l")" DEVICET="$(find "$DEVICE" -printf "%l")"
else else
DEVICET="$DEVICE" DEVICET="$DEVICE"
fi fi
ACTION="$1" ACTION="$1"
REC="$2" REC="$2"
NAME="$3" NAME="$3"
if [ "$ACTION" = "mount" -a -z "$NAME" ]; then
NAME="basename ${REC})"
fi
# function to print help # function to print help
call() { call() {
echo -e "\nScript $0 needs three parameters for mount and two for umount. The first must be mount or umount, the second is the full path.\n" echo -e "\nScript $0 needs three parameters for mount and two for umount. The first must be mount or umount, the second is the full path.\n"
echo -e "Only for mounting the script needs a third parameter, the last part of the recording path.\n" echo -e "Only for mounting the script needs a third parameter, the last part of the recording path.\n"
echo -e "Example: dvdarchive.sh mount '/video0/Music/%Riverdance/2004-06-06.00:10.50.99.rec' '2004-06-06.00:10.50.99.rec'\n" echo -e "Example: dvdarchive.sh mount '/video0/Music/%Riverdance/2004-06-06.00:10.50.99.rec' '2004-06-06.00:10.50.99.rec'\n"
echo -e "Example: dvdarchive.sh umount '/video0/Music/%Riverdance/2004-06-06.00:10.50.99.rec'\n" echo -e "Example: dvdarchive.sh umount '/video0/Music/%Riverdance/2004-06-06.00:10.50.99.rec'\n"
echo -e "For more information read the MANUAL part inside this script.\n" echo -e "For more information read the MANUAL part inside this script.\n"
} }
# function to log messages # function to log messages
log() { log() {
case "$1" in case "$1" in
@@ -170,11 +222,13 @@ log() {
# Some checks before doing something # Some checks before doing something
[ "$ACTION" = "mount" -o "$ACTION" = "umount" ] || { call; exit 10; } [ "$ACTION" = "mount" -o "$ACTION" = "umount" ] || { call; exit 10; }
[ -z "$REC" ] && { call; exit 10; } [ -z "$REC" -o ! -d "$REC" ] && { call; exit 10; }
[ "$ACTION" = mount -a -z "$NAME" ] && { call; exit 10; } [ "$ACTION" = "mount" -a -z "$NAME" ] && { call; exit 10; }
[ ! -d "$MOUNTPOINT" ] && { log error "Mountpoint $MOUNTPOINT doesn't exist"; exit 10; } [ ! -d "$MOUNTPOINT" ] && { log error "Mountpoint $MOUNTPOINT doesn't exist"; exit 10; }
[ ! -e "$DEVICE" ] && { log error "Device $DEVICE doesn't exist"; exit 10; } [ ! -e "$DEVICE" ] && { log error "Device >$DEVICE< doesn't exist"; exit 10; }
case "$ACTION" in case "$ACTION" in
mount) mount)
# check if dvd is in drive, only if isodetect exists # check if dvd is in drive, only if isodetect exists
@@ -190,56 +244,87 @@ mount)
if mount | egrep -q " $MOUNTPOINTT "; then if mount | egrep -q " $MOUNTPOINTT "; then
# check if dvd is in use # check if dvd is in use
if mount | egrep -q "^$DEVICET"; then if mount | egrep -q "^$DEVICET"; then
log error "dvd in use (at: check if dvd is in use)" log warning "dvd in use (at: check if dvd is in use)"
#exit 1
fi fi
# if already mountet, try to umount # if already mountet, try to umount
log warning "dvd already mounted, try to umount" log warning "dvd already mounted, try to umount"
umount "$MOUNTPOINT" || { log error "dvd umount error (at: dvd already mounted, try to umount)"; exit 1; } sudo umount "$MOUNTPOINT" || { log error "dvd umount error (at: dvd already mounted, try to umount)"; exit 1; }
# unlink broken existing links # unlink broken existing links
for LINK in "${REC}/"*.vdr; do for LINK in "${REC}/"*.vdr; do
if [ -L "$LINK" -a ! -s "$LINK" ]; then if [ -L "$LINK" -a ! -s "$LINK" ]; then
rm "$LINK" rm "$LINK"
fi fi
done done
for LINK in "${REC}/"*.ts; do
if [ -L "$LINK" -a ! -s "$LINK" ]; then
rm "$LINK"
fi
done
fi fi
# mount dvd # mount dvd
mount "$MOUNTPOINT" || { log error "dvd mount error (at: mount dvd)"; exit 1; } sudo mount $DEVICE "$MOUNTPOINT" || { log error "dvd mount error (at: mount dvd)"; exit 1; }
# is mounted, find recording on dvd # is mounted, find recording on dvd
DIR="$(find "${MOUNTPOINT}/" -name "$NAME")" DIR="$(find "${MOUNTPOINT}/links/" -maxdepth 2 -name "$NAME")"
# if not found, umount
if [ -z "$DIR" ]; then if [ -z "$DIR" ]; then
# not found in links - try root
DIR="$(find "${MOUNTPOINT}/" -maxdepth 2 -name "$NAME")"
# if not found, umount
if [ -z "$DIR" ]; then
log error "wrong dvd in drive / recording not found on dvd" log error "wrong dvd in drive / recording not found on dvd"
umount "$MOUNTPOINT" || { log error "dvd umount error (at: wrong dvd in drive / recording not found on dvd)"; exit 1; } umount "$MOUNTPOINT" || { log error "dvd umount error (at: wrong dvd in drive / recording not found on dvd)"; exit 1; }
# If wanted, eject dvd # If wanted, eject dvd
[ $EJECTWRONG -eq 1 ] && { eject "$DEVICE"; } [ $EJECTWRONG -eq 1 ] && { eject "$DEVICE"; }
exit 3 exit 3
fi fi
fi
# check if video partition is vfat # check if video partition is vfat
if [ "$(stat -f -c %T "$REC")" != "vfat" ]; then if [ "$(stat -f -c %T "$REC")" != "vfat" ]; then
# link index.vdr if not exist # link index.vdr if not exist
if [ ! -e "${REC}/index.vdr" ]; then if [ ! -e "${REC}/index.vdr" ]; then
cp -s "${DIR}/index.vdr" "${REC}/" || { log error "could not link index.vdr (at: link index.vdr from dvd to disk)"; } if [ -e "${DIR}/index.vdr" ]; then
ln -s "${DIR}/index.vdr" "${REC}/index.vdr" || { log error "could not link index.vdr (at: link index.vdr from dvd to disk)"; }
fi
fi
if [ ! -e "${REC}/index" ]; then
if [ -e "${DIR}/index" ]; then
ln -s "${DIR}/index" "${REC}/index" || { log error "could not link index (at: link index.vdr from dvd to disk)"; }
fi
fi fi
# link [0-9]*.vdr files # link [0-9]*.vdr files
cp -s "${DIR}"/[0-9]*.vdr "${REC}/" #cp -s "${DIR}"/[0-9]*.vdr "${REC}/"
#find "${DIR}"/ -name "[0-9]*.vdr" -exec ln -s "${REC}/$(basename "{}")"
for f in "${DIR}/"[0-9]*.vdr; do
if [ -e $f ]; then
ln -s "$f" "${REC}/$(basename "$f")"
fi
done
for f in "${DIR}/"[0-9]*.ts; do
if [ -e $f ]; then
ln -s "$f" "${REC}/$(basename "$f")"
fi
done
# error while linking [0-9]*.vdr files? # error while linking [0-9]*.vdr files?
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
log error "error while linking [0-9]*.vdr" log error "error while linking [0-9]*.vdr"
# umount dvd bevor unlinking # umount dvd bevor unlinking
umount "$MOUNTPOINT" || { log error "dvd umount error (at: error while linking)"; exit 1; } sudo umount "$MOUNTPOINT" || { log error "dvd umount error (at: error while linking)"; exit 1; }
# unlink broken links # unlink broken links
for LINK in "${REC}/"*.vdr; do for LINK in "${REC}/"*.vdr; do
if [ -L "$LINK" -a ! -s "$LINK" ]; then if [ -L "$LINK" -a ! -s "$LINK" ]; then
rm "$LINK" rm "$LINK"
fi fi
done done
for LINK in "${REC}/"*.ts; do
if [ -L "$LINK" -a ! -s "$LINK" ]; then
rm "$LINK"
fi
done
exit 4 exit 4
fi fi
# If wanted, create length.vdr # If wanted, create length.vdr
if [ $GETLENGTH -eq 1 -a ! -s "${REC}/length.vdr" -a -L "${REC}/index.vdr" ]; then #if [ $GETLENGTH -eq 1 -a ! -s "${REC}/length.vdr" -a -L "${REC}/index.vdr" ]; then
echo $(( $(stat -L -c %s "${REC}/index.vdr")/12000 )) > "${REC}/length.vdr" # echo $(( $(stat -L -c %s "${REC}/index.vdr")/12000 )) > "${REC}/length.vdr"
fi #fi
else else
if [ ! "$(sudo -l | egrep "\(root\) NOPASSWD: /bin/mount")" -o ! "$(sudo -l | egrep "\(root\) NOPASSWD: /bin/umount")" ]; then if [ ! "$(sudo -l | egrep "\(root\) NOPASSWD: /bin/mount")" -o ! "$(sudo -l | egrep "\(root\) NOPASSWD: /bin/umount")" ]; then
log error "you must configure sudo and allow $(whoami) to use mount/umount!" log error "you must configure sudo and allow $(whoami) to use mount/umount!"
@@ -262,18 +347,23 @@ umount)
# check if video partition is vfat # check if video partition is vfat
if [ "$(stat -f -c %T "$REC")" != "vfat" ]; then if [ "$(stat -f -c %T "$REC")" != "vfat" ]; then
# is mounted, umount dvd bevor unlinking # is mounted, umount dvd bevor unlinking
umount "$MOUNTPOINT" || { log error "dvd umount error (at: is mounted, umount dvd bevor unlinking)"; exit 1; } sudo umount "$MOUNTPOINT" || { log error "dvd umount error (at: is mounted, umount dvd bevor unlinking)"; exit 1; }
# unlink broken links # unlink broken links
for LINK in "${REC}/"*.vdr; do for LINK in "${REC}/"*.vdr; do
if [ -L "$LINK" -a ! -s "$LINK" ]; then if [ -L "$LINK" -a ! -s "$LINK" ]; then
rm "$LINK" rm "$LINK"
fi fi
done done
for LINK in "${REC}/"*.ts; do
if [ -L "$LINK" -a ! -s "$LINK" ]; then
rm "$LINK"
fi
done
else else
# umount recording # umount recording
sudo umount "$REC" || { log error "sudo umount $REC"; exit 5; } sudo umount "$REC" || { log error "sudo umount $REC"; exit 5; }
# umount dvd at umount # umount dvd at umount
umount "$MOUNTPOINT" || { log error "dvd umount error (at: umount dvd at umount)"; exit 1; } sudo umount "$MOUNTPOINT" || { log error "dvd umount error (at: umount dvd at umount)"; exit 1; }
fi fi
# If wanted, eject dvd # If wanted, eject dvd
[ $EJECTUMOUNT -eq 1 ] && { eject "$DEVICE"; } [ $EJECTUMOUNT -eq 1 ] && { eject "$DEVICE"; }