#!/bin/bash
##########################################
# MAPn | SOURCE CODE | HTTP://NOTAGO.COM #
# -------------------------------------- #
# Written by GONEY WON | HTTP://NGRO.ORG #
# -------------------------------------- #
# Last modified time: 2011-10-28 23:50   #
##########################################

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

## Check user permissions ##
if [ $(id -u) != "0" ]; then
	echo "Error: NO PERMISSION! Please login as root to run this script again."
	exit 1
fi

## Start ##
clear
echo ""
echo -e " \033[41;37m +-----------------------------------+ \033[0m"
echo -e " \033[41;37m | Automated process for MAPn (S)    | \033[0m"
echo -e " \033[41;37m |                                   | \033[0m"
echo -e " \033[41;37m | The original is NGRO.ORGanization | \033[0m"
echo -e " \033[41;37m |                                   | \033[0m"
echo -e " \033[41;37m | Compiled by Goney @ NOTAGO.COM    | \033[0m"
echo -e " \033[41;37m |                                   | \033[0m"
echo -e " \033[41;37m | Website: http://www.notago.com    | \033[0m"
echo -e " \033[41;37m +-----------------------------------+ \033[0m"
echo ""
echo ""

echo "Program: MAPn 3.1 Stable version (2011-10-29)"
echo ""
if [ -f /etc/redhat-release ]; then
	if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ]; then
		echo "System information: CentOS / RedHat (64bit)"
	else
		echo "System information: CentOS / RedHat (32bit)"
	fi
	echo ""
	uname -a
	cat /etc/redhat-release
	echo ""
elif [ -f /etc/debian_version ]; then
	if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ]; then
		echo "System information: Debian / Ubuntu (64bit)"
	else
		echo "System information: Debian / Ubuntu (32bit)"
	fi
	echo ""
	uname -a
	lsb_release -a
	echo ""
else
	echo -e "\033[41;37m Error: MAPn currently only supports CentOS/RedHat/Debian/Ubuntu  \033[0m"
	echo -e "\033[41;37m You can get help in http://www.notago.com or http://www.ngro.org \033[0m"
	echo ""
	echo "Exiting..."
	echo ""
	exit 1
fi

echo ""
echo " +-----+------------------------------------------+"
echo -e " | \033[41;37m 1 \033[0m | ngro-mapn-3.1.tar.gz (download version)  |"
echo " +-----+------------------------------------------+"
echo -e " | \033[41;37m 2 \033[0m | ngro-mapn-3.1-full.tar.gz (full version) |"
echo " +-----+------------------------------------------+"
echo ""

echo " Please enter 1 or 2 to get a download version or full version  <"
read -p " Choose ( 1/2 ): " choose_1_2
echo ""

if [ "$choose_1_2" = "1" ]; then
	echo -e "\033[47;30m ngro-mapn-3.1.tar.gz \033[0m downloading..."
	echo ""
	sleep 3
	wget -c http://sourceforge.net/projects/mapn/files/stable/ngro-mapn-3.1.tar.gz
	if [ ! -s ngro-mapn-3.1.tar.gz ]; then
		wget -c http://mapn.googlecode.com/files/ngro-mapn-3.1.tar.gz
	fi
	if [ ! -s ngro-mapn-3.1.tar.gz ]; then
		wget -c http://download.notago.com/mapn/ngro-mapn-3.1.tar.gz
	fi
	tar -zxvf ngro-mapn-3.1.tar.gz
	chmod -R 755 ngro-mapn-3.1/
	cd ngro-mapn-3.1/
	if [ -f /etc/redhat-release ]; then
		./centos.sh
	else
		./debian.sh
	fi
	exit 1
else
	echo -e "\033[47;30m ngro-mapn-3.1-full.tar.gz \033[0m downloading..."
	echo ""
	sleep 3
	wget -c http://sourceforge.net/projects/mapn/files/stable/ngro-mapn-3.1-full.tar.gz
	if [ ! -s ngro-mapn-3.1-full.tar.gz ]; then
		wget -c http://mapn.googlecode.com/files/ngro-mapn-3.1-full.tar.gz
	fi
	if [ ! -s ngro-mapn-3.1-full.tar.gz ]; then
		wget -c http://download.notago.com/mapn/ngro-mapn-3.1-full.tar.gz
	fi
	tar -zxvf ngro-mapn-3.1-full.tar.gz
	chmod -R 755 ngro-mapn-3.1/
	cd ngro-mapn-3.1/
	if [ -f /etc/redhat-release ]; then
		./centos.sh
	else
		./debian.sh
	fi
	exit 1
fi

## END ##