#!/bin/bash
# Remove broken MAN-PAGES links
for dir in man[1-8]; do
	for mp in `ls $dir/`; do
		# if it is a directory, continue
		if [ -d $dir/$mp ]; then
			continue;
		fi
		link=`head -n1 $dir/$mp | grep "^.so"`;
		# if the man-page is link to nonexisting file,
		# remove it
		if [[ "x$link" != "x" ]]; then 
			if [[ ! -f $dir/$link ]] && [[ ! -f $link ]]; then
				rm $dir/$mp
			fi
		fi
	done
done
