Skip to content

Instantly share code, notes, and snippets.

@lietu
Created May 31, 2014 09:42
Show Gist options
  • Save lietu/c42e39e819ff63a983ff to your computer and use it in GitHub Desktop.
Save lietu/c42e39e819ff63a983ff to your computer and use it in GitHub Desktop.
Script to automatically install DJBDNS and dependencies on CentOS 6, should be easy to adapt to other OSes easily
#!/usr/bin/env bash
# Temporary directory to work in
TMPDIR="$HOME/tmp/djbdns"
# Where to install daemontools
PACKAGE="/package"
# Version numbers for packages
UCSPI_VERSION="0.88"
DAEMONTOOLS_VERSION="0.76"
DJBDNS_VERSION="1.05"
# IP to listen in, leave empty for auto-detect
IP=""
# ----- SCRIPT LOGIC ----- #
# Set up dependencies
echo "Installing dependencies (curl, gcc, make, rsync)"
yum -y install curl gcc make rsync
# Figure out my IP
if [[ -z "$IP" ]]; then
echo "Querying ifconfig.me for your IP"
IP=$(curl ifconfig.me)
echo "Detected it as $IP"
fi
# Create our folders
echo "Initializing environment"
mkdir -p "$TMPDIR"
mkdir -p "$PACKAGE"
# Set up some permissions
chmod 1755 "$PACKAGE"
cd "$TMPDIR"
echo "Downloading packages"
curl -O "http://cr.yp.to/ucspi-tcp/ucspi-tcp-$UCSPI_VERSION.tar.gz"
curl -O "http://cr.yp.to/daemontools/daemontools-$DAEMONTOOLS_VERSION.tar.gz"
curl -O "http://cr.yp.to/djbdns/djbdns-$DJBDNS_VERSION.tar.gz"
echo "Extracting packages"
tar -zxf "ucspi-tcp-$USCPI_VERSION.tar.gz"
tar -zxf "djbdns-$DJBDNS_VERSION.tar.gz"
cd "$PACKAGE"
tar -zxf "$TMPDIR/daemontools-$DAEMONTOOLS_VERSION.tar.gz"
# At least CentOS needs a slightly patched compilation, so we can patch that here
#if [[ -f "/etc/centos-release" ]]; then
echo "Patching CC configuration"
ccpatch="gcc -O2 -include /usr/include/errno.h"
echo "$ccpatch" > "$PACKAGE/admin/daemontools-$DAEMONTOOLS_VERSION/src/conf-cc"
echo "$ccpatch" > "$TMPDIR/ucspi-tcp-$UCSPI_VERSION/conf-cc"
echo "$ccpatch" > "$TMPDIR/djbdns-$DJBDNS_VERSION/conf-cc"
#fi
# Build and install daemontools
echo "Building and installing daemontools"
cd "$PACKAGE/admin/daemontools-$DAEMONTOOLS_VERSION"
package/install
# Build and install ucspi-tcp
echo "Building and installing ucspi-tcp"
cd "$TMPDIR/ucspi-tcp-$UCSPI_VERSION"
make setup check
# Build and install djbdns
echo "Building and installing djbdns"
cd "$TMPDIR/djbdns-$DJBDNS_VERSION"
make setup check
# Set up user
echo "Creating tinydns user"
adduser tinydns
# Configure tinydns
echo "Configuring tinydns"
tinydns-conf tinydns tinydns /usr/local/tinydns-nsN "$IP"
echo "Enabling service"
ln -s /usr/local/tinydns-nsN /service/tinydns
echo "Starting svscanboot"
svscanboot &
echo "Starting service"
svc -u /service/tinydns
echo "Checking for listening"
sleep 0.1
netstat -lpn | grep tinydns
echo "If you can see TinyDNS listening above, then we're all done."
echo "If not, there's probably an error somewhere above."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment