Skip to content

Instantly share code, notes, and snippets.

@anuaimi
Created January 9, 2014 12:03
Show Gist options
  • Save anuaimi/8333087 to your computer and use it in GitHub Desktop.
Save anuaimi/8333087 to your computer and use it in GitHub Desktop.
will build geodns and create a debian package
#!/bin/bash
# From github issue 47
# https://github.com/abh/geodns/issues/47
USER=vagrant
BASE_DIR=/home/vagrant
install_build_tools() {
echo "installing go language"
# add repo with latest go (1.1)
sudo apt-get install -y python-software-properties
sudo add-apt-repository -y ppa:duh/golang
sudo apt-get update
# install go
echo "golang-go golang-go/dashboard boolean false" | debconf-set-selections
sudo apt-get install -y golang
#
echo "adding go to path"
export PATH=$PATH:/usr/local/go/bin
# bzr & git
echo "installing source control tools"
sudo apt-get install -y mercurial
sudo apt-get install -y bzr
sudo apt-get install -y git
# libgeoip
echo "installing geoip library"
sudo apt-get install -y libgeoip-dev
return 0
}
install_package_tools() {
# ruby
echo "installing fpm (& ruby)"
sudo add-apt-repository -y ppa:brightbox/ruby-ng-experimental
sudo apt-get update
#sudo apt-get install -y ruby2.0 ruby2.0-dev ruby2.0-doc
sudo apt-get install -y ruby2.0
sudo update-alternatives --set ruby /usr/bin/ruby2.0
# fpm
sudo gem install fpm --no-rdoc --no-ri
return 0
}
setup_build_environment() {
install_build_tools
install_package_tools
echo "== setup complete =="
return 0
}
build_geodns() {
# set where go code is
export GOPATH=${BASE_DIR}/workspace/go/
# set build directory
mkdir -p ${BASE_DIR}/workspace/go
cd ${BASE_DIR}/workspace/go/
echo "get geodns source code"
go get launchpad.net/gocheck
go get github.com/abh/geodns
echo "build geodns binary"
cd ${BASE_DIR}/workspace/go/src/github.com/abh/geodns
go test
go build
echo "== build complete =="
return ${VERSION}
}
package_geodns() {
echo "creating debian package"
rm -f geodns_*.deb
VERSION=`git describe --abbrev=0`
fpm -s dir -t deb -n geodns -v ${VERSION} --prefix /usr/local/bin/ geodns
return 0
}
install_geodns() {
# get geo database
echo "downloading GeoLite database"
wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
sudo cp GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat
# installs to /use/local/bin
echo "installing geodns"
sudo dpkg -i geodns_2.4.4_amd64.deb
mkdir -p /vagrant/install
cp geodns_2.4.4_amd64.deb /vagrant/install
return 0
}
test_install() {
# try it out
cd ${BASE_DIR}
cd /vagrant
geodns -port=5353 -log=false -config="dns/surfeasy.conf"
# dig @127.0.0.1 -p 5353 www.surfeasy.mobi
return 0
}
#
# main
#
setup_build_environment
build_geodns
package_geodns
install_geodns
test_install
# done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment