
#!/bin/bash

# Make sure that a block device was specified
[ -b "$1" ] || { printf "Usage: ${0##*/} <cd_device>\n"; exit 1; }

# Read the entire header - actually sector 16 of the disc (2K sectors)
# All character codes in the "control" region (0-31 decimal) are folded
# into the character '.' - these control codes seem to upset bash's
# variable sub-string functions (${var:start:length}) quite badly )-:
data=`dd if=$1 bs=1 skip=32768 count=2048 2>/dev/null | tr '[\\000-\\037]'
'.*'`

# Define some useful functions for prettifying the output
tidy_print()
{
   # Really cheap way of folding whitespace
   echo $*
}

date_print()
{
   if [ "${1}" == "00000000000000" ]
   then
     echo "-"
   else
     # try to parse the date,  but fail gracefully if too hard
     date=`date --date="${1:6:2}/${1:4:2}/${1:0:4}
${1:8:2}:${1:10:2}:${1:12:2}" --utc 2> /dev/null`
     if [ $? -eq 0 ]
     then
       echo ${date}
     else
       echo "-"
     fi
   fi
}

echo "Volume:      `tidy_print ${data:40:32}`"
echo "Publisher:   `tidy_print ${data:318:128}`"
echo "Preparer:    `tidy_print ${data:446:128}`"
echo "Application: `tidy_print ${data:574:128}`"
echo "System:      `tidy_print ${data:8:32}`"
echo "Created:     `date_print ${data:813:14}`"
echo "Modified:    `date_print ${data:830:14}`"
echo "Expires:     `date_print ${data:847:14}`"
echo "Effective:   `date_print ${data:864:14}`"

