Home | History | Annotate | Download | only in test_scripts
      1 #!/bin/bash
      2 
      3 # Validate the CD/DVD devices in the system by progressively mounting them,
      4 # copying the CDs to the hard disk, and then diffing the results.
      5 # Note that this test also examines SCSI CD drives, making the "ide" part a
      6 # misnomer that's maintained solely because it's familiar to the users.
      7 
      8 # Copyright (C) 2003-2006 IBM
      9 #
     10 # This program is free software; you can redistribute it and/or
     11 # modify it under the terms of the GNU General Public License as
     12 # published by the Free Software Foundation; either version 2 of the
     13 # License, or (at your option) any later version.
     14 #
     15 # This program is distributed in the hope that it will be useful, but
     16 # WITHOUT ANY WARRANTY; without even the implied warranty of
     17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     18 # General Public License for more details.
     19 #
     20 # You should have received a copy of the GNU General Public License
     21 # along with this program; if not, write to the Free Software
     22 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
     23 # 02111-1307, USA.
     24 
     25 . "$POUNDER_SRCDIR/libidecd.sh"
     26 
     27 DEFAULT_MOUNT="$POUNDER_TMPDIR/cdmount"
     28 DESTINATION="$POUNDER_TMPDIR/cddata"
     29 
     30 # Ensure that our default mountpoint and destination dirs exist.
     31 mkdir -p "$DEFAULT_MOUNT"
     32 
     33 # Scoop up the old error count.
     34 LOGFILE=/proc/$$/fd/1
     35 OLD_ERRORS=`egrep -ic "(err|fail|invalid|cannot|denied)" $LOGFILE`
     36 OLD_DIFFS=`egrep -ic "^---" $LOGFILE`
     37 
     38 # Trap a SIGABRT which signifies an aborted test...
     39 trap 'exit 255' SIGABRT
     40 
     41 # Now, mount each disc and do the test.
     42 find_discs_with_media | while read DEV USE_FSTAB; do
     43 
     44 	# Are there no CDs at all?
     45 	if [ "$DEV" == "NONE" ]; then
     46 		echo "No CD/DVD drives found.  Aborting."
     47 		kill -SIGABRT $$
     48 	fi
     49 
     50 	# Mount the disc.
     51 	echo "Mounting $DEV."
     52 	if [ $USE_FSTAB -gt 0 ]; then
     53 		MOUNTPOINT=`grep "^$DEV[ 	]" /etc/fstab | awk -F " " '{print $2}'`
     54 		mount "$DEV"
     55 	else
     56 		MOUNTPOINT="$DEFAULT_MOUNT"
     57 		mount "$DEV" "$MOUNTPOINT" -t auto
     58 	fi
     59 
     60 	# Create destination and set up auto-removal
     61 	trap 'echo Cleaning up...; rm -rf $DESTINATION; umount $MOUNTPOINT; echo Clean.; exit 0' 1 2 15
     62 	mkdir -p "$DESTINATION"
     63 
     64 	# Copy the CD
     65 	echo "Copying $DEV."
     66 	cp -pRdu "$MOUNTPOINT" "$DESTINATION"
     67 
     68 	# Diff the copy
     69 	echo "Comparing $DEV to $DESTINATION."
     70 	diff -rq "$MOUNTPOINT" "$DESTINATION/`basename $MOUNTPOINT`"
     71 
     72 	# Unmount
     73 	echo "Done with $DEV."
     74 	umount "$DEV"
     75 
     76 	# Remove the copy
     77 	rm -rf "$DESTINATION"
     78 done
     79 
     80 
     81 # Look for new errors.
     82 NEW_ERRORS=`egrep -ic "(err|fail|invalid|cannot|denied)" $LOGFILE`
     83 NEW_DIFFS=`egrep -ic "^---" $LOGFILE`
     84 
     85 ERRORS=$(( NEW_ERRORS - OLD_ERRORS ))
     86 DIFFS=$(( NEW_DIFFS - OLD_DIFFS ))
     87 WRONG=$(( ERRORS + DIFFS ))
     88 if [ $WRONG -eq 255 ]; then
     89 	WRONG=254
     90 fi
     91 exit $WRONG
     92