# Finding similar example ports



## carlton_draught (Apr 1, 2011)

I was originally going to make a walkthrough, and then I realized that it didn't make sense because there is so much variability. However, in the process I created a script and found a command others might find useful.

First of all, it was suggested to me that the best way to start is to find a very similar port and use that as a basis. So that's how I approached it. I thought if I find something that uses the same repository, and is a shell script like mine, I would have a good example. It ended up not working, so I just ended up using one I already knew was quite similar in that it was a shell script and a man page basically. But I put this out here in case anyone else might use it.

First check out /usr/ports/Mk/bsd.sites.mk to see if your repository is in there. If it is, use that term. e.g. I use GOOGLE, because mine is stored in code.google.com.

I'll find which one does:
`# grep -R GOOGLE /usr/ports/sysutils`
Output:

```
/usr/ports/sysutils/grok/Makefile:MASTER_SITES=	GOOGLE_CODE
/usr/ports/sysutils/slack/Makefile:MASTER_SITES=	${MASTER_SITE_GOOGLE_CODE} \
/usr/ports/sysutils/flyback/Makefile:MASTER_SITES=	${MASTER_SITE_GOOGLE_CODE}
/usr/ports/sysutils/devstat/Makefile:MASTER_SITES=	GOOGLE_CODE
/usr/ports/sysutils/pv/Makefile:MASTER_SITES=	${MASTER_SITE_GOOGLE_CODE} \
/usr/ports/sysutils/synergy/Makefile:MASTER_SITES=	GOOGLE_CODE
```
<snip>

If you need more detail, or that doesn't do enough for you, the following allows a match in both the Makefile and the pkg-descr. Enjoy.


```
#!/bin/sh
pkgdescr_search_term="script"
Makefile_search_term="GOOGLE"

usrportdirectories=$(ls -1d /usr/ports/*)

for directory in $usrportdirectories; do
  if [ -d $directory ]; then
    port_dir_list=$(ls -1d $directory/*)
    for in_port_directory in $port_dir_list; do
      if [ -e $in_port_directory/pkg-descr ]; then
        is_shell_script=$(grep -cw $pkgdescr_search_term $in_port_directory/pkg-descr)
        if [ $is_shell_script -ne 0 ]; then
          uses_google=$(grep -c $Makefile_search_term $in_port_directory/Makefile)
            if [ $uses_google -ne 0 ]; then
            echo
            echo "********************************************"
              echo "$in_port_directory"
            echo "********************************************"
            cat $in_port_directory/pkg-descr
          fi
        fi
      fi
    done
  fi
done
```


----------

