#!/bin/sh :<<'########################################################################' Usage: make_pdnsd.sh This script downloads and constructs the pdnsd extension. See ------------------------------------------------------------------------ Change-log: 2011-10-09 First version. ------------------------------------------------------------------------ This script was written in 2011 by vitex from forum.tinycorelinux.net. To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. See http://creativecommons.org/publicdomain/zero/1.0/ for a copy of the CC0 Public Domain Dedication under which this work is distributed. ######################################################################## # Specify the name of the extension. EXTENSION=pdnsd # Specify the base portion of the extension. EXTENSION0=pdnsd #----------------------------------------------------------------------- # Install the extensions needed to build this extension. tce-load -wi compiletc.tcz groff.tcz #----------------------------------------------------------------------- # Specify the temporary directory that will contain the build components. TMP=/tmp/tcz # Specify the directory in which the squashfs files will be assembled. SQUASHFS=$TMP/squashfs # Specify the directory in which the submission package will be assembled. PACKAGE=$TMP/package #----------------------------------------------------------------------- # Specify the location containing the software distribution. VERSION=1.2.8 DOWNLOAD=http://www.phys.uu.nl/~rombouts/pdnsd/releases/pdnsd-$VERSION-par.tar.gz #----------------------------------------------------------------------- # Download if necessary. tar tzf $TMP/$(basename $DOWNLOAD) 1>/dev/null 2>&1 || wget -O- $DOWNLOAD >$TMP/$(basename $DOWNLOAD) #----------------------------------------------------------------------- # Save the download for GPL compliance. cp $TMP/$(basename $DOWNLOAD) $PACKAGE #----------------------------------------------------------------------- # Compute the name of the directory into which the software will be unpacked. DIRECTORY=$TMP/$EXTENSION0-$VERSION #----------------------------------------------------------------------- # Unpack the software. rm -fR $DIRECTORY tar xzf $TMP/$(basename $DOWNLOAD) -C $TMP #----------------------------------------------------------------------- export CFLAGS="-march=i486 -mtune=i686 -Os -pipe" export CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" export LDFLAGS="-Wl,-O1" #----------------------------------------------------------------------- # Build the software. { cd $DIRECTORY ; ./configure ; make ; touch $TMP/TIMESTAMP ; sudo make install ; } #----------------------------------------------------------------------- # Copy the installed files (those newer than $TMP/TIMESTAMP) from # /usr/local to $SQUASHFS/usr/local. ( cd / find usr/local -not -type d -newer $TMP/TIMESTAMP | grep -v /man/ | cpio -pvd $SQUASHFS ) #----------------------------------------------------------------------- # Make a default configuration file. mkdir -p $SQUASHFS/usr/local/etc/ cat >$SQUASHFS/usr/local/etc/$EXTENSION.conf.default <$SQUASHFS/usr/local/etc/init.d/$EXTENSION <<'EOF' #!/bin/sh # This is a script to start and stop the pdnsd daemon. # This script must be executed as root. [ "$(id -u)" != '0' ] && echo $0 must be executed as root. && exit 1 # The udhcpc default script must be modified so we can control # /etc/resolv.conf. DEFAULT_SCRIPT=/usr/share/udhcpc/default.script DEFAULT_NAMESERVERS="$(dirname $DEFAULT_SCRIPT)/default.nameservers" # Change the udhcpc script $DEFAULT_SCRIPT so it checks for the file # $DEFAULT_NAMESERVERS containing a list of name server IP addresses. if ! grep -q $DEFAULT_NAMESERVERS $DEFAULT_SCRIPT ; then sed -i '/RESOLV_CONF=/ i\ # Replace dns, the DHCP-supplied list of name servers, with the content \ # of the file '$DEFAULT_NAMESERVERS' if that file exists. \ [ -r '$DEFAULT_NAMESERVERS' ] && \ dns="$(cat '$DEFAULT_NAMESERVERS')" \ \ ' $DEFAULT_SCRIPT fi # If $DEFAULT_NAMESERVERS exits and is not "127.0.0.1", # save it in $DEFAULT_NAMESERVERS.saved. save_nameservers () { [ -r $DEFAULT_NAMESERVERS ] && [ "$(cat $DEFAULT_NAMESERVERS)" != '127.0.0.1' ] && mv -f $DEFAULT_NAMESERVERS $DEFAULT_NAMESERVERS.saved } # If $DEFAULT_NAMESERVERS.saved exists, use is to restore # $DEFAULT_NAMESERVERS; otherwise, delete $DEFAULT_NAMESERVERS. restore_nameservers () { if [ -r $DEFAULT_NAMESERVERS.saved ] ; then mv -f $DEFAULT_NAMESERVERS.saved $DEFAULT_NAMESERVERS else rm -f $DEFAULT_NAMESERVERS fi } # Create /var/cache/pdnsd, switch the name server to 127.0.0.1, signal # udhcpc to rebuild /etc/resolv.conf, and start pdnsd using either # "-d" or the options specified on the command line. start () { if [ ! -d /var/cache/pdnsd ] ; then mkdir -p /var/cache/pdnsd chown nobody:nogroup /var/cache/pdnsd fi save_nameservers echo 127.0.0.1 >$DEFAULT_NAMESERVERS killall -q -USR1 udhcpc pkill -f '^/usr/local/sbin/pdnsd ' shift /usr/local/sbin/pdnsd ${@:-'-d'} return 0 } # Restore the name servers, signal udhcpc to rebuild /etc/resolv.conf, # and terminate pdnsd. stop () { restore_nameservers killall -q -USR1 udhcpc pkill -f '^/usr/local/sbin/pdnsd ' return 0 } case "$1" in start) start "$@" ;; stop) stop ;; restart) stop && start "$@" ;; *) echo Usage: $0 '{ start [options] | stop | restart [options] }' ;; esac EOF chmod +x $SQUASHFS/usr/local/etc/init.d/$EXTENSION #----------------------------------------------------------------------- # Create an initialization script that creates /var/cache/pdnsd and # the file /usr/local/etc/$EXTENSION.conf if the user has not supplied # a version of that file. mkdir -p $SQUASHFS/usr/local/tce.installed cat >$SQUASHFS/usr/local/tce.installed/$EXTENSION <$PACKAGE/$EXTENSION.tcz.info <