File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpd / genconfig.sh
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:16:02 2012 UTC (12 years, 4 months ago) by misho
Branches: miniupnpd, elwix, MAIN
CVS tags: v1_5, HEAD
miniupnpd

    1: #! /bin/sh
    2: # $Id: genconfig.sh,v 1.1.1.1 2012/02/21 23:16:02 misho Exp $
    3: # miniupnp daemon
    4: # http://miniupnp.free.fr or http://miniupnp.tuxfamily.org/
    5: # (c) 2006-2010 Thomas Bernard
    6: # This software is subject to the conditions detailed in the
    7: # LICENCE file provided within the distribution
    8: 
    9: RM="rm -f"
   10: CONFIGFILE="config.h"
   11: CONFIGMACRO="__CONFIG_H__"
   12: 
   13: # version reported in XML descriptions
   14: #UPNP_VERSION=20070827
   15: UPNP_VERSION=`date +"%Y%m%d"`
   16: # Facility to syslog
   17: LOG_MINIUPNPD="LOG_DAEMON"
   18: 
   19: # detecting the OS name and version
   20: OS_NAME=`uname -s`
   21: OS_VERSION=`uname -r`
   22: 
   23: # pfSense special case
   24: if [ -f /etc/platform ]; then
   25: 	if [ `cat /etc/platform` = "pfSense" ]; then
   26: 		OS_NAME=pfSense
   27: 		OS_VERSION=`cat /etc/version`
   28: 	fi
   29: fi
   30: 
   31: ${RM} ${CONFIGFILE}
   32: 
   33: echo "/* MiniUPnP Project" >> ${CONFIGFILE}
   34: echo " * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/" >> ${CONFIGFILE}
   35: echo " * (c) 2006-2010 Thomas Bernard" >> ${CONFIGFILE}
   36: echo " * generated by $0 on `date` */" >> ${CONFIGFILE}
   37: echo "#ifndef $CONFIGMACRO" >> ${CONFIGFILE}
   38: echo "#define $CONFIGMACRO" >> ${CONFIGFILE}
   39: echo "" >> ${CONFIGFILE}
   40: echo "#include <inttypes.h>" >> ${CONFIGFILE}
   41: echo "" >> ${CONFIGFILE}
   42: echo "#define UPNP_VERSION	\"$UPNP_VERSION\"" >> ${CONFIGFILE}
   43: 
   44: # OS Specific stuff
   45: case $OS_NAME in
   46: 	OpenBSD)
   47: 		MAJORVER=`echo $OS_VERSION | cut -d. -f1`
   48: 		MINORVER=`echo $OS_VERSION | cut -d. -f2`
   49: 		#echo "OpenBSD majorversion=$MAJORVER minorversion=$MINORVER"
   50: 		# rtableid was introduced in OpenBSD 4.0
   51: 		if [ $MAJORVER -ge 4 ]; then
   52: 			echo "#define PFRULE_HAS_RTABLEID" >> ${CONFIGFILE}
   53: 		fi
   54: 		# from the 3.8 version, packets and bytes counters are double : in/out
   55: 		if [ \( $MAJORVER -ge 4 \) -o \( $MAJORVER -eq 3 -a $MINORVER -ge 8 \) ]; then
   56: 			echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
   57: 		fi
   58: 		# from the 4.7 version, new pf
   59: 		if [ \( $MAJORVER -ge 5 \) -o \( $MAJORVER -eq 4 -a $MINORVER -ge 7 \) ]; then
   60: 			echo "#define PF_NEWSTYLE" >> ${CONFIGFILE}
   61: 		fi
   62: 		echo "#define USE_PF 1" >> ${CONFIGFILE}
   63: 		FW=pf
   64: 		OS_URL=http://www.openbsd.org/
   65: 		;;
   66: 	FreeBSD)
   67: 		VER=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'`
   68: 		if [ $VER -ge 700049 ]; then
   69: 			echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
   70: 		fi
   71: 		# new way to see which one to use PF or IPF.
   72: 		# see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
   73: 		# source file with handy subroutines like checkyesno
   74: 		. /etc/rc.subr
   75: 		# source config file so we can probe vars
   76: 		. /etc/rc.conf
   77: 		if checkyesno ipfilter_enable; then
   78: 			echo "Using ipf"
   79: 			FW=ipf
   80: 			echo "#define USE_IPF 1" >> ${CONFIGFILE}
   81: 		elif checkyesno pf_enable; then
   82: 			echo "Using pf"
   83: 			FW=pf
   84: 			echo "#define USE_PF 1" >> ${CONFIGFILE}
   85: 		# TODO : Add support for IPFW
   86: 		# echo "#define USE_IPFW 1" >> ${CONFIGFILE}
   87: 		# FW=ipfw
   88: 		else
   89: 			echo "Could not detect usage of ipf or pf. Compiling for pf by default"
   90: 			FW=pf
   91: 			echo "#define USE_PF 1" >> ${CONFIGFILE}
   92: 		fi
   93: 		OS_URL=http://www.freebsd.org/
   94: 		;;
   95: 	pfSense)
   96: 		# we need to detect if PFRULE_INOUT_COUNTS macro is needed
   97: 		echo "#define USE_PF 1" >> ${CONFIGFILE}
   98: 		FW=pf
   99: 		OS_URL=http://www.pfsense.com/
  100: 		;;
  101: 	NetBSD)
  102: 		# source file with handy subroutines like checkyesno
  103: 		. /etc/rc.subr
  104: 		# source config file so we can probe vars
  105: 		. /etc/rc.conf
  106: 		if checkyesno pf; then
  107: 			echo "#define USE_PF 1" >> ${CONFIGFILE}
  108: 			FW=pf
  109: 		elif checkyesno ipfilter; then
  110: 			echo "#define USE_IPF 1" >> ${CONFIGFILE}
  111: 			FW=ipf
  112: 		else
  113: 			echo "Could not detect ipf nor pf, defaulting to pf."
  114: 			echo "#define USE_PF 1" >> ${CONFIGFILE}
  115: 			FW=pf
  116: 		fi
  117: 		OS_URL=http://www.netbsd.org/
  118: 		;;
  119: 	DragonFly)
  120: 		# source file with handy subroutines like checkyesno
  121: 		. /etc/rc.subr
  122: 		# source config file so we can probe vars
  123: 		. /etc/rc.conf
  124: 		if checkyesno pf; then
  125: 			echo "#define USE_PF 1" >> ${CONFIGFILE}
  126: 			FW=pf
  127: 		elif checkyesno ipfilter; then
  128: 			echo "#define USE_IPF 1" >> ${CONFIGFILE}
  129: 			FW=ipf
  130: 		else
  131: 			echo "Could not detect ipf nor pf, defaulting to pf."
  132: 			echo "#define USE_PF 1" >> ${CONFIGFILE}
  133: 			FW=pf
  134: 		fi
  135: 		echo "#define USE_PF 1" >> ${CONFIGFILE}
  136: 		OS_URL=http://www.dragonflybsd.org/
  137: 		;;
  138: 	SunOS)
  139: 		echo "#define USE_IPF 1" >> ${CONFIGFILE}
  140: 		FW=ipf
  141: 		echo "#define LOG_PERROR 0" >> ${CONFIGFILE}
  142: 		echo "#define SOLARIS_KSTATS 1" >> ${CONFIGFILE}
  143: 		OS_URL=http://www.sun.com/solaris/
  144: 		;;
  145: 	Linux)
  146: 		OS_URL=http://www.kernel.org/
  147: 		KERNVERA=`echo $OS_VERSION | awk -F. '{print $1}'`
  148: 		KERNVERB=`echo $OS_VERSION | awk -F. '{print $2}'`
  149: 		KERNVERC=`echo $OS_VERSION | awk -F. '{print $3}'`
  150: 		KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
  151: 		#echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
  152: 		# Debian GNU/Linux special case
  153: 		if [ -f /etc/debian_version ]; then
  154: 			OS_NAME=Debian
  155: 			OS_VERSION=`cat /etc/debian_version`
  156: 			OS_URL=http://www.debian.org/
  157: 		fi
  158: 		# use lsb_release (Linux Standard Base) when available
  159: 		LSB_RELEASE=`which lsb_release`
  160: 		if [ 0 -eq $? ]; then
  161: 			OS_NAME=`${LSB_RELEASE} -i -s`
  162: 			OS_VERSION=`${LSB_RELEASE} -r -s`
  163: 			case $OS_NAME in
  164: 				Debian)
  165: 					OS_URL=http://www.debian.org/
  166: 					OS_VERSION=`${LSB_RELEASE} -c -s`
  167: 					;;
  168: 				Ubuntu)
  169: 					OS_URL=http://www.ubuntu.com/
  170: 					OS_VERSION=`${LSB_RELEASE} -c -s`
  171: 					;;
  172: 			esac
  173: 		fi
  174: 		echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
  175: 		FW=netfilter
  176: 		;;
  177: 	Darwin)
  178: 		echo "#define USE_IPFW 1" >> ${CONFIGFILE}
  179: 		FW=ipfw
  180: 		OS_URL=http://developer.apple.com/macosx
  181: 		;;
  182: 	*)
  183: 		echo "Unknown OS : $OS_NAME"
  184: 		echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
  185: 		exit 1
  186: 		;;
  187: esac
  188: 
  189: echo "Configuring compilation for [$OS_NAME] [$OS_VERSION] with [$FW] firewall software."
  190: echo "Please edit config.h for more compilation options."
  191: 
  192: echo "#define OS_NAME		\"$OS_NAME\"" >> ${CONFIGFILE}
  193: echo "#define OS_VERSION	\"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE}
  194: echo "#define OS_URL		\"${OS_URL}\"" >> ${CONFIGFILE}
  195: echo "" >> ${CONFIGFILE}
  196: 
  197: echo "/* syslog facility to be used by miniupnpd */" >> ${CONFIGFILE}
  198: echo "#define LOG_MINIUPNPD		 ${LOG_MINIUPNPD}" >> ${CONFIGFILE}
  199: echo "" >> ${CONFIGFILE}
  200: 
  201: echo "/* Uncomment the following line to allow miniupnpd to be" >> ${CONFIGFILE}
  202: echo " * controlled by miniupnpdctl */" >> ${CONFIGFILE}
  203: echo "/*#define USE_MINIUPNPDCTL*/" >> ${CONFIGFILE}
  204: echo "" >> ${CONFIGFILE}
  205: 
  206: echo "/* Comment the following line to disable NAT-PMP operations */" >> ${CONFIGFILE}
  207: echo "#define ENABLE_NATPMP" >> ${CONFIGFILE}
  208: echo "" >> ${CONFIGFILE}
  209: 
  210: echo "/* Uncomment the following line to enable generation of" >> ${CONFIGFILE}
  211: echo " * filter rules with pf */" >> ${CONFIGFILE}
  212: echo "/*#define PF_ENABLE_FILTER_RULES*/">> ${CONFIGFILE}
  213: echo "" >> ${CONFIGFILE}
  214: 
  215: echo "/* Uncomment the following line to enable caching of results of" >> ${CONFIGFILE}
  216: echo " * the getifstats() function */" >> ${CONFIGFILE}
  217: echo "/*#define ENABLE_GETIFSTATS_CACHING*/" >> ${CONFIGFILE}
  218: echo "/* The cache duration is indicated in seconds */" >> ${CONFIGFILE}
  219: echo "#define GETIFSTATS_CACHING_DURATION 2" >> ${CONFIGFILE}
  220: echo "" >> ${CONFIGFILE}
  221: 
  222: echo "/* Uncomment the following line to enable multiple external ip support */" >> ${CONFIGFILE}
  223: echo "/* note : That is EXPERIMENTAL, do not use that unless you know perfectly what you are doing */" >> ${CONFIGFILE}
  224: echo "/* Dynamic external ip adresses are not supported when this option is enabled." >> ${CONFIGFILE}
  225: echo " * Also note that you would need to configure your .conf file accordingly. */" >> ${CONFIGFILE}
  226: echo "/*#define MULTIPLE_EXTERNAL_IP*/" >> ${CONFIGFILE}
  227: echo "" >> ${CONFIGFILE}
  228: 
  229: echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
  230: echo " * of BSD daemon() */" >> ${CONFIGFILE}
  231: echo "#define USE_DAEMON" >> ${CONFIGFILE}
  232: echo "" >> ${CONFIGFILE}
  233: 
  234: echo "/* Uncomment the following line to enable lease file support */" >> ${CONFIGFILE}
  235: echo "/*#define ENABLE_LEASEFILE*/" >> ${CONFIGFILE}
  236: echo "" >> ${CONFIGFILE}
  237: 
  238: echo "/* Define one or none of the two following macros in order to make some" >> ${CONFIGFILE}
  239: echo " * clients happy. It will change the XML Root Description of the IGD." >> ${CONFIGFILE}
  240: echo " * Enabling the Layer3Forwarding Service seems to be the more compatible" >> ${CONFIGFILE}
  241: echo " * option. */" >> ${CONFIGFILE}
  242: echo "/*#define HAS_DUMMY_SERVICE*/" >> ${CONFIGFILE}
  243: echo "#define ENABLE_L3F_SERVICE" >> ${CONFIGFILE}
  244: echo "" >> ${CONFIGFILE}
  245: 
  246: echo "/* Experimental UPnP Events support. */" >> ${CONFIGFILE}
  247: echo "/*#define ENABLE_EVENTS*/" >> ${CONFIGFILE}
  248: echo "" >> ${CONFIGFILE}
  249: 
  250: echo "/* include interface name in pf and ipf rules */" >> ${CONFIGFILE}
  251: echo "#define USE_IFNAME_IN_RULES" >> ${CONFIGFILE}
  252: echo "" >> ${CONFIGFILE}
  253: 
  254: echo "/* Experimental NFQUEUE support. */" >> ${CONFIGFILE}
  255: echo "/*#define ENABLE_NFQUEUE*/" >> ${CONFIGFILE}
  256: echo "" >> ${CONFIGFILE}
  257: 
  258: echo "#endif" >> ${CONFIGFILE}
  259: 
  260: exit 0

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>