my lame attempt at a shell script...

Eric F Crist ecrist at secure-computing.net
Mon Jan 3 13:52:50 PST 2005


On Jan 3, 2005, at 3:34 PM, Erik Norgaard wrote:

> Eric F Crist wrote:
>
>> elif [ "$grog_firewall_enable" <> "YES" or "NO" ]
>> then
>>         echo "Syntax error in /etc/rc.conf file. grog_firewall_enable 
>> must be YES or NO"
>> fi
>
> I don't know if you're on 5.x, nor whether you use ipfw, ipfilter or 
> pf - I wrote a replacement for ipfilter as I got dizzy trying to 
> maintain a  too long ruleset so I wanted to split it into multiple 
> files.
>
> On 5.x things get a lot simpler. In /etc/rc.d there are plenty of 
> scripts to look at - don't look at rc.firewall.
>
> The scripts in /etc/rc.d are executed as ordered by rcorder(8).
>
> Create your script and load rc.subr:
>
> . /etc/rc.subr
>
> which gives you a lot of predefined handy functions. Set the "name" 
> variable in the script, eg:
>
> name="grog" # Name of my firewall script
>
> it is customary to call the script the same. Follow by
>
> load_rc_config=$name
>
> most scripts then just includes the line
>
> run_rc_command "$1"
>
> - everything is defined by the functions in rc.subr. Now, you can set 
> the commands to be run and define them in your script, see eg. 
> ipfilter.
>
> rc.subr also contains a "checkyesno" function answering your question 
> above - however, it is normal to check "[Yy][Ee][Ss]" and treat 
> everything else as a no. After all, what are you gonna do if you only 
> accept "yes" or "no" but some one typed "yeah right"? You must have a 
> default action.
>
> Since your script isn't default, maybe don't add default settings to 
> /etc/defaults/rc.conf. Instead variables can have defaults eg:
> ${ipfilter_program:-/sbin/ipf} will use /sbin/ipf unless the 
> ipfilter_program variable is set.
>
> Finally, don't use bash, use /bin/sh and nothing else, you don't know 
> if bash is available when your script run.
>
> Regarding your script, which I got deleted from this mail (sorry), I 
> think there is an error:
>
> > if [ "$grog_firewall_enable" = "YES" ]
>
> this "=" is assignment and will always evaulate to true. You want
>
> if [ "$grog_firewall_enable" -eq "YES" ]
>
> I'm not sure if "==" works, but always be careful you're not using 
> asignment in if-statements.
>
> Cheers, Erik

Thanks for the reply.  I'm actually using ipfw, and this script is 
going to require this.  Also, this script isn't really for public use, 
anyone's welcome to it, if they want, and only internal use.  In 
regards to placing variables in /etc/rc.conf, these aren't really true 
variables (no pun intended), but rather system-specific device 
information.

My overall setup is such that each server could have a different 
brand/chipset network card, and different purposes on the network.  My 
goal is that I can set an internal interface, and external interface, 
hostname, ipaddresses, and protocols independently of the actual 
script.  Then, the script will plug those variables into the correct 
places.  I could put this information in another place, like a 
/etc/firewall.setup file, but it'll make my life easier if I just put 
it into rc.conf.

In regards to the = or -eq, I can't discern a difference in output when 
I use them.  Can you explain further their differences?

What would NOT EQUAL be?

Thanks.
_______________________________________________________
Eric F Crist                  "I am so smart, S.M.R.T!"
Secure Computing Networks              -Homer J Simpson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20050103/695b3efb/PGP.bin


More information about the freebsd-questions mailing list