linkslash.sh

 

#/usr/bin/ksh
### linkslash.sh
###
### Usage:
###
###    linkslash.sh linkdir file.html phrase
###
### Create link to file.html in all html files under linkdir that have phrase 
### Run this from the directory where file.html is located
###
### This program should be used to link directory phrases such as...
###
###    /etc/sysconfig/filename
###
### To copy all ascii files from a directory, run something like the following:
###
###   mkdir $DOCUMENTROOT/etc
###   cd $DOCUMENTROOT/etc
###   cp `file /etc/* | egrep text | egrep -v long | egrep -v lock | cut -d: -f1 | sort | uniq` .
###   for i in `ls`
###   do
###       convertp.sh $i
###   done
###
###
 
 
 
 if [ "$3" = "" ]
 then
    echo "Usage: $0 linkdir filename phrase"
    exit 1
 fi
 
 
 linkdir=$1
 file=$2
 key1=$3
 key2=$4
 key3=$5
 key4=$6
 key5=$7
 key6=$8
 key7=$9
 
 
 path=`pwd | sed "s,/var/www,," | sed "s,/,/,g"`
 
 
 phrase=$key1
 
 if [ "$key2" != "" ]
 then
    phrase="${key1} ${key2}" 
 fi
 
 if [ "$key3" != "" ]
 then
    phrase="${key1} ${key2} ${key3}"
 fi
 
 if [ "$key4" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4}"
 fi
 
 if [ "$key5" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4} ${key5}"
 fi
 
 if [ "$key6" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4} ${key5} ${key6}"
 fi
 
 if [ "$key7" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4} ${key5} ${key6} ${key7} "
 fi
 
 if [ "$key8" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4} ${key5} ${key6} ${key7} ${key8}  "
 fi
 
echo "Looking for $grep"
 
for i in `find $linkdir -name \*.htm\* -print | egrep -v "/$file" `
 do


     ### If i is file that we are linking to
     ### don't create a hyperlink.
     #ib=`basename $i`
     #if [ "$ib" = "$file" ]
     #then
     #    echo "$ib = $file, skipping"
     #    continue
     #fi 
 
     if `egrep -w "$grep" $i >/dev/null 2>/dev/null`
     then
 

         atag=`/usr/local/bin/atag.sh $i $grep`
         if `echo $atag | egrep 1 >/dev/null 2>/dev/null`
         then
             echo "disqualified atag"
             continue
         fi

         Atag=`/usr/local/bin/Atag.sh $i $grep`
         if `echo $Atag | egrep 1 >/dev/null 2>/dev/null`
         then
             echo "disqualified Atag"
             continue
         fi
 
         titletag=`/usr/local/bin/titletag.sh $i $grep`
         if `echo $titletag | egrep 1 >/dev/null 2>/dev/null`
         then
             echo "disqualified titletag"
             continue
         fi
 
         h1tag=`/usr/local/bin/h1tag.sh $i $grep`
         if `echo $h1tag | egrep 1 >/dev/null 2>/dev/null`
         then
             echo "disqualified h1tag"
             continue
         fi
 
 
         h2tag=`/usr/local/bin/h2tag.sh $i $grep`
         if `echo $h2tag | egrep 1 >/dev/null 2>/dev/null`
         then
             echo "disqualified h2tag"
             continue
         fi
 
         h3tag=`/usr/local/bin/h3tag.sh $i $grep`
         if `echo $h3tag | egrep 1 >/dev/null 2>/dev/null`
         then
             echo "disqualified h3tag"
             continue
         fi
 
         h4tag=`/usr/local/bin/h4tag.sh $i $grep`
         if `echo $h4tag | egrep 1 >/dev/null 2>/dev/null`
         then
             echo "disqualified h4tag"
             continue
         fi
 


 


         xfile=`echo $file | sed "s/\////g"`
     
         p="http://www.setgetweb.com${path}/${xfile}"
 
         echo " "
         echo "Creating link in:"
         echo "    $i"
         echo " "
         echo "using the phrase: "
         echo "    $grep"

         echo " "
 
         sed "s+/$grep +/<a href=\"$p\">$phrase</a> +"  $i | \
         sed "s+/$grep$+/<a href=\"$p\">$phrase</a>+"  | \
         sed "s+/+/+g"  > tmp.$$
         mv tmp.$$ $i

     fi


 
 done