#!/bin/bash

# Getting, And installing the dependencies here! ^-^
sudo apt-get update
sudo apt-get install build-essential swig openssl libssl-dev xsltproc tinc subversion gcc libreadline-dev bunzip2 wget bzr
sudo apt-get build-dep python2.7

# Getting, And installing Stackless Python here!
cd
wget http://www.stackless.com/binaries/stackless-272-export.tar.bz2
bunzip2 stackless-272-export.tar.bz2
tar xf stackless-272-export.tar
cd stackless-272-export
sudo mkdir -p /opt/stackless
sudo ./configure --prefix=/opt/stackless
sudo make
sudo make altinstall
cd

# Getting and installing M2Crypto!
wget https://pypi.python.org/packages/source/M/M2Crypto/M2Crypto-0.21.1.tar.gz
sudo tar xf M2Crypto-0.21.1.tar.gz
cd M2Crypto-0.21.1/
sudo /opt/stackless/bin/python2.7 setup.py build
sudo /opt/stackless/bin/python2.7 setup.py install
cd

# Getting and installing dnspython here!
wget http://www.dnspython.org/kits/1.7.1/dnspython-1.7.1.tar.gz
sudo tar xf dnspython-1.7.1.tar.gz
cd dnspython-1.7.1
sudo /opt/stackless/bin/python2.7 setup.py build
sudo /opt/stackless/bin/python2.7 setup.py install
cd

# FINALLY get Netsukuku here!
bzr branch http://bzr.savannah.gnu.org/r/netsukuku/original netsukuku-extras
sudo cp netsukuku-extras/sandbox/lukisi/branches/multipleip
sudo rename multipleip netsukuku

# Installing ANDNS here.
cd ~/netsukuku/ANDNS/andns
sudo make
sudo make install
cd ~/netsukuku/ANDNS/pyandns
sudo /opt/stackless/bin/python2.7 setup.py build
sudo /opt/stackless/bin/python2.7 setup.py install
cd

# Installing ntkresolv here!
cd ~/netsukuku/ntkresolv
echo "If you encounter problems here, Please edit the Makefile in netsukuku/ntkresolv. Replace the text gcc -Wall -landns ntkresolv.c -o ntkresolv on line 3 with gcc -Wall ntkresolv.c -landns -lcrypto -o ntkresolv"
sudo make
sudo make install
cd

# /etc/netsukukupython here!
echo "We must check if there is a netsukuku folder already!"
echo "checking..."
if [ -a /etc/netsukuku ]
	then
		echo "Yes, It exists, We'll make a new folder to preserve your settings."
fi
sudo mkdir -p /etc/netsukuku
cd netsukuku
sudo ln -s /netsukuku/pyntk/setup/etc/netsukuku/tinc /etc/netsukuku
cd
# Checks the hostname you want to register
cat /etc/hostname
sudo tee /etc/netsukuku/dnswrapper.conf <<EOF >/dev/null
andnsserver in-process
EOF

sudo tee /etc/netsukuku/andnsserver.conf <<EOF >/dev/null
inetnameserver 8.8.8.8
EOF

sudo tee /etc/netsukuku/libandns.conf <<EOF >/dev/null
andnsserver 127.0.0.1
EOF


# Information in running netsukuku python!
echo "Please try going to netsukuku/pyntk with cd, And running something like sudo /opt/stackless/bin/python2.7 ntkd -i eth0 -vvvv 

-i is the interface, It doesn't have to be ethernet, You can change it to other things. Please though! Be CERTAIN to disable ANY managers that might interfer with netsukuku, Such as NetworkManager. 

You can do this by running something like sudo stop network-manager. You should, Also, kill the dhclient, and flush the main table and ip addresses on your network interfaces.

You can do this with sudo killall dhclient

sudo ip route flush table main
sudo ip address flush dev eth0
sudo ip address flush dev wlan0

You might have different interfaces than eth0 and wlan0 though! Check ifconfig to be sure!

This WILL disconnect you from the internet though! However, It is not permenant, It will be restored upon restart. Though, You can manually connect to the internet through terminal, But that is slightly complicated. 

You would need to do that if you want to test the internet gateway feature, Though, You could do it just to continue with normal internet usage alongside netsukuku testing or what ever.

Finaly thing! Please try running this command if you want to look up names in ANDNA 

sudo tee /etc/resolv.conf <<EOF >/dev/null
nameserver 127.0.0.1
EOF

If you experience any internet connectifity issues after restarting, Please just type sudo gedit /etc/resolv.conf and delete the nameserver 127.0.0.1 line."
