2

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" [email protected]
else
  mail -s "No changes has occured" [email protected] /newchanges
fi

How can I accomplish this?

2 Answers 2

1

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" [email protected] < /path/to/newchanges
else
  mail -s "changes have occurred" [email protected]
fi
0

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.

You must log in to answer this question.