I have a script here that I want to create as a port in freebsd and then make it as package so that I can install on some machines. script is below.

#!/usr/local/bin/bash
if [ ! -f "/suid.old" ]
then
find / -perm -4000 -o -perm -2000 -ls > /suid.old
else
find / -perm -4000 -o -perm -2000 -ls > /suid.new
diff suid.old suid.new > newchanges
fi
exit 0
if [ -s "/newchanges" ]
then
  mail -s "changes has occured" someone@gmail.com
else
  mail -s "No changes has occured" someone@gmail.com /newchanges
fi

How can I accomplish this?

link|improve this question
feedback

3 Answers

If you're only installing that one small script, I'd just do it manually. You could use a shar file, but that seems like overkill.

The biggest issues I see are first, that bash is going to be located in different locations on different systems, but there's nothing in your script that's Bash-specific, so you could change your shebang to:

#!/bin/sh

or

#!/usr/bin/env bash

for portability.

Second, you will need to choose a location for your script. It strikes me that /usr/local/bin would be as good as any.

Third, you will need to chown to set the ownership and chmod to set the permissions.

Fourth, you should choose better locations for your output files. If they are only for temporary use, then they should be created in /tmp rather than the root directory where you have suid.old and suid.new going, or the current directory where you have newchanges going. Otherwise, somewhere in var might be where you'd want to put more persistent data. Perhaps /var/local/suid.

Fifth, the exit prevents the second if from ever being evaluated so no mail will ever be sent.

Sixth, you might want to mv suid.new suid.old at some point so the next time you do your check it's comparing the most recent saved data.

Seventh, your last mail command should have the file piped or redirected in. It won't work as an argument. And the two mail commands should be swapped so you're not mailing a file when it's empty and are mailing it when it's not.

if [ -s "/newchanges" ]
then
  mail -s "No changes have occurred" someone@gmail.com < /path/to/newchanges
else
  mail -s "changes have occurred" someone@gmail.com
fi
link|improve this answer
feedback

A port for one shell script is beyond overkill -- As Dennis said this is something I would copy to individual machines as needed (or create a package manually, but this is a pain).

I'm also not sure this has sufficient general utility to make it into the official ports collection (in particular, there is already a "setuid binaries" check as part of the daily security audit).

All that said, details on creating a port can be found in the Porter's Handbook, and you can always roll a local port just for your site.

link|improve this answer
feedback

Oh,

I was going to use "makefile" and use this script to create a tarball.bz and then put it under the /use/ports/disfiles.

But I need help on how to create new ports in freebsd?. where to palcve files and at the end, run make makesum, and make make install. finally make package to create a package.

I was going to use this script as a to check how ports actually are running?

link|improve this answer
Please add new comments to the original question, so people can better understand the flow of the conversation in the future. Also, as other have said, please read the Porter's Handbook (freebsd.org/doc/en/books/porters-handbook). It has answers to almost every conceivable question about making a port, maintaining a port, getting it into the official ports collection, etc, etc, etc. – Chris S Mar 30 '10 at 2:59
Hi, what does Error code 71 and error code 1? means when making ports, when we run make and make install? – su55 Mar 30 '10 at 4:04
feedback

Your Answer

 
or
required, but never shown