#! /bin/csh -f # Last edited on 2003-10-12 12:34:15 by stolfi set cmd = "$0"; set cmd = "${cmd:t}" set usage = "${cmd} TAG DIR" # Finds all symbolic links under the directory DIR; output is "~/.symlinks-TAG-all" (with "->"). # Recurses through NFS mounts but not through symbolic links. # Separates out the "bad" links, whose referent matches a given RE pattern; output is "~/.symlinks-TAG-bad", "~/.symlinks-TAG-ok" # Creates from that files "~/.symlinks-TAG-remove" and "~.symlinks-TAG-recreate" that can be sourced to perform if ( $#argv != 2 ) then echo "usage: ${usage}"; exit 1 endif set tag = "$1"; shift; set dir = "$1"; shift; set out = ${STOLFIHOME}/.symlinks-${tag} /bin/rm -v ${out}-* if ( ! ( -d ${dir} ) ) then echo "${dir}: not a directory" ; exit 1 endif cd ${dir} find ./. -type l -ls \ | gawk \ ' /./ { \ L = $11; A = $12; R = $13; \ gsub(/^[.][\/][.][\/]/, "", L); \ printf "%s %s %s\n", L, A, R; \ } \ ' \ | sort | uniq \ > ${out}-all cat ${out}-all \ | gawk '($2 \!= "->"){printf "BAD: %s\n", $0;}' \ > ${out}-badfmt if ( -z ${out}-badfmt ) then /bin/rm -f ${out}-badfmt else echo 'bad "find" output format - see '"${out}-badfmt"; exit 1 endif cat ${out}-all \ | gawk '( ($3 ~ /[\/]n[.\/]ftp[.\/]pub[.\/]/) || ($3 ~ /[\/]home[.\/]lac[.\/]/) ){ print; }' \ > ${out}-bad bool 1-2 ${out}-all ${out}-bad > ${out}-ok