#!/bin/bash

LINUX=$(ls -1d $HOME/linux-* | tail -1)
[[ -n $LINUX ]] || LINUX=/usr/src/linux
if [[ ! -d $LINUX ]] ; then
    echo "E: Kernel directory not found: $LINUX"
    exit 1
fi

COURSE=$1
[[ $1 == "" ]] && COURSE=$(basename $PWD)

${0%/*}/listfiles.sh \
    | xargs grep -rI '\\kernlink{' \
    | sed 's+:.*\kernlink{+:+g; s/}.*//' \
    | sort -u \
    | while IFS=: read -r TEX FILE ; do
    FNAME=$LINUX/$FILE
    if [[ -f $FNAME ]] || [[ -d $FNAME ]] ; then
	echo "FILE EXISTS:    ${FNAME/$LINUX/}"
    else
	echo "DOES NOT EXIST: ${FNAME/$LINUX/} in ${TEX#*LFCW/}"
    fi
done
