You should definitely use a not_if or only_if metaparameter to the script resource, otherwise Chef will execute the script every time it runs on the node. Depending on the software you're compiling, that can be as simple as existence of the file, or that it is a non-zero size, or as complex as verifying that the command copied in /usr/local/bin outputs some particular string.
For example, if you want to see if the file merely exists and assume the best:
script "install_foo" do
# .. other stuff you wrote!
not_if "test -x /usr/local/bin/foo"
end
You should probably make sure that the file is executable, since you're putting it in /usr/local/bin.
file "/usr/local/bin/foo" do
mode 0755
end
If you want to check that the command has some particular output, you could do something like:
script "install_foo" do
# .. other stuff you wrote!
not_if "test -x /usr/local/bin/foo && /usr/local/bin/foo | grep -x 'foo is awesome'"
end
(assuming that running foo would have that output, of course.)
The not_if (and only_if) metaparameters can take a string or a Ruby block. If it is a string, then that will be shell commands executed on the system. If it is a Ruby block (do .. end or { }), then it will be executed as Ruby.
Meta-parameters are documented on the Chef wiki under the "resources" page.