3
TEMP_DIR='/tmp/optical-test'
4
ISO_NAME='optical-test.iso'
5
SAMPLE_FILE_PATH='/usr/share/example-content/'
6
SAMPLE_FILE='Ubuntu_Free_Culture_Showcase'
7
MD5SUM_FILE='optical_test.md5'
10
create_working_dirs(){
11
# First, create the temp dir and cd there
12
echo "Creating Temp directory and moving there ..."
13
mkdir -p $TEMP_DIR || return 1
15
echo "Now working in $PWD ..."
19
# Get our sample files
20
echo "Getting sample files from $SAMPLE_FILE_PATH ..."
21
cp -a $SAMPLE_FILE_PATH/$SAMPLE_FILE $TEMP_DIR
27
echo "Generating md5sums of sample files ..."
30
md5sum * > $TEMP_DIR/$MD5SUM_FILE
31
# Check the sums for paranoia sake
32
check_md5 $TEMP_DIR/$MD5SUM_FILE
39
echo "Checking md5sums ..."
46
echo "Creating ISO Image ..."
47
genisoimage -r -J -o $ISO_NAME $SAMPLE_FILE
52
#Burn the ISO with wodim
53
echo "Sleeping 10 seconds in case drive is not yet ready ..."
55
echo "Beginning image burn ..."
56
wodim -eject dev=$OPTICAL_DRIVE $ISO_NAME
66
# Give the tester up to 5 minutes to reload the newly created CD/DVD
67
echo "Waiting up to 5 minutes for drive to be mounted ..."
70
SLEEP_COUNT=`expr $SLEEP_COUNT + $INTERVAL`
72
mount $OPTICAL_DRIVE 2>&1 |egrep -q "already mounted"
74
if [ $rt -eq 0 ]; then
75
echo "Drive appears to be mounted now"
79
# If they exceed the timeout limit, make a best effort to load the tray
81
if [ $SLEEP_COUNT -ge $TIMEOUT ]; then
82
echo "WARNING: TIMEOUT Exceeded and no mount detected!"
88
echo "Deleting original data files ..."
90
if [ ! -z "$(mount | grep $OPTICAL_DRIVE)" ]; then
91
MOUNT_PT=$(mount | grep $OPTICAL_DRIVE | awk '{print $3}')
92
echo "Disk is mounted to $MOUNT_PT"
94
echo "Attempting best effort to mount $OPTICAL_DRIVE on my own"
95
MOUNT_PT=$TEMP_DIR/mnt
96
echo "Creating temp mount point: $MOUNT_PT ..."
98
echo "Mounting disk to mount point ..."
99
mount $OPTICAL_DRIVE $MOUNT_PT
101
if [ $rt -ne 0 ]; then
102
echo "ERROR: Unable to re-mount $OPTICAL_DRIVE!" >&2
106
echo "Copying files from ISO ..."
107
cp $MOUNT_PT/* $TEMP_DIR
108
check_md5 $MD5SUM_FILE
113
echo "Moving back to original location"
115
echo "Now residing in $PWD"
116
echo "Cleaning up ..."
119
echo "Ejecting spent media ..."
125
echo "Attempting to clean up ..."
131
OPTICAL_DRIVE=$(readlink -f $1)
133
OPTICAL_DRIVE='/dev/sr0'
136
create_working_dirs || failed "Failed to create working directories"
137
get_sample_data || failed "Failed to copy sample data"
138
generate_md5 || failed "Failed to generate initial md5"
139
generate_iso || failed "Failed to create ISO image"
140
burn_iso || failed "Failed to burn ISO image"
141
check_disk || failed "Failed to verify files on optical disk"
142
cleanup || failed "Failed to clean up"