<commit_before>#!/bin/bash



# Checking Linux Distro Is Ubuntu
if [ ! -f /etc/lsb-release ]
then
	echo -e "\033[31mEasyEngine (ee) Is Made For Ubuntu Only As Of Now\e[0m"
	echo -e "\033[31mYou Are Free To Fork EasyEngine (ee): https://github.com/rtCamp/easyengine/fork\e[0m"
	exit 100
fi



# Checking Permissions
Permission=$(id -u)
if [ $Permission -ne 0 ] 
then
	echo -e "\033[31mSudo Privilege Required...\e[0m"
	echo -e "\033[31mUses:\e[0m\033[34m curl -sL rt.cx/ee | sudo bash\e[0m"
	exit 100 
fi


# Make Variables Available For Later Use
LOGDIR=/var/log/easyengine
INSTALLLOG=/var/log/easyengine/install.log


# Capture Errors
OwnError()
{
	echo -e "[ `date` ] \033[31m$@\e[0m" | tee -ai $INSTALLLOG
	exit 101
}


# Pre Checks To Avoid Later Screw Ups
# Checking Logs Directory

if [ ! -d $LOGDIR ]
then
	echo -e "\033[34mCreating EasyEngine (ee) Log Directory, Please Wait...\e[0m"
	mkdir -p $LOGDIR || OwnError "Unable To Create Log Directory $LOGDIR"
fi

# Checking Tee
if [ ! -x  /usr/bin/tee ]
then
	echo -e "\033[31mTee Command Not Found\e[0m"
	echo -e "\033[34mInstalling Tee, Please Wait...\e[0m"
	sudo apt-get -y install coreutils &>> $INSTALLLOG || OwnError "Unable to install tee"
fi

echo &>> $INSTALLLOG
echo &>> $INSTALLLOG
echo -e "\033[34mEasyEngine (ee) Installation Started [$(date)]\e[0m" | tee -ai $INSTALLLOG


# Checking Ed
if [ ! -x  /bin/ed ]
then
	echo -e "\033[31mEd Command Not Found\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[34mInstalling Ed, Please Wait...\e[0m" | tee -ai $INSTALLLOG
	sudo apt-get -y install ed &>> $INSTALLLOG || OwnError "Unable to install ed"
fi

# Checking Wget
if [ ! -x  /usr/bin/wget ]
then
	echo -e "\033[31mWget Command Not Found\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[34mInstalling Wget, Please Wait...\e[0m" | tee -ai $INSTALLLOG
	sudo apt-get -y install wget &>> $INSTALLLOG || OwnError "Unable To Install Wget"
fi

# Checking Curl
if [ ! -x  /usr/bin/curl ]
then
	echo -e "\033[31mCurl Command Not Found\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[34mInstalling Curl, Please Wait...\e[0m" | tee -ai $INSTALLLOG
	sudo apt-get -y install curl &>> $INSTALLLOG || OwnError "Unable To Install Curl"
fi

# Checking Tar
if [ ! -x  /bin/tar ]
then
	echo -e "\033[31mTar Command Not Found\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[34mInstalling Tar, Please Wait...\e[0m" | tee -ai $INSTALLLOG
	sudo apt-get -y install tar &>> $INSTALLLOG || OwnError "Unable To Install Tar"
fi

# Checking Git
if [ ! -x  /usr/bin/git ]
then
	echo -e "\033[31mGit Command Not Found\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[34mInstalling Git, Please Wait...\e[0m" | tee -ai $INSTALLLOG
	sudo apt-get -y install git-core &>> $INSTALLLOG || OwnError "Unable To Install Git"
fi

# Checking Name Servers
if [[ -z $(cat /etc/resolv.conf 2> /dev/null | awk '/^nameserver/ { print $2 }') ]]
then
	echo -e "\033[31mNo Name Servers Detected\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[31mPlease Configure /etc/resolv.conf\e[0m" | tee -ai $INSTALLLOG
	exit 102
fi

# Pre Checks End


# Check The EasyEngine (ee) Is Available
EXIST=$(basename `pwd`)
if [ "$EXIST" != "easyengine" ]
then
	echo -e "\033[34mCloning EasyEngine (ee), Please Wait...\e[0m" | tee -ai $INSTALLLOG
	
	# Remove Older EasyEngine (ee) If Found
	rm -rf /tmp/easyengine &>> /dev/null

	# Clone EasyEngine (ee) Stable Repository
	git clone -b stable git://github.com/rtCamp/easyengine.git /tmp/easyengine &>> $INSTALLLOG || OwnError "Unable To Clone Easy Engine"
fi

# Create Directory /etc/easyengine
if [ ! -d /etc/easyengine ]
then
	# Create A Directory For EE Configurations
	mkdir -p /etc/easyengine || OwnError "Unable To Create Dir /etc/easyengine"
fi

# Create Directory /usr/share/easyengine
if [ ! -d /usr/share/easyengine/nginx ]
then
	# Create A Directory For EE Nginx Configurations
	mkdir -p /usr/share/easyengine/nginx || OwnError "Unable To Create Dir /usr/share/easyengine/nginx"
fi

# Install EasyEngine (ee)
echo -e "\033[34mInstalling EasyEngine (ee), Please Wait...\e[0m" | tee -ai $INSTALLLOG

# EasyEngine (ee) /etc Files
cp -a /tmp/easyengine/etc/bash_completion.d/ee /etc/bash_completion.d/ &>> $INSTALLLOG || OwnError "Unable To Copy EE Auto Complete File"
cp -a /tmp/easyengine/etc/easyengine/ee.conf /etc/easyengine/ &>> $INSTALLLOG || OwnError "Unable To Copy ee.conf File"

# EE /usr/share/easyengine Files
cp -a /tmp/easyengine/etc/nginx/* /usr/share/easyengine/nginx/ &>> $INSTALLLOG || OwnError "Unable To Copy Configuration Files "
cp -a /tmp/easyengine/usr/share/easyengine/* /usr/share/easyengine/ &>> $INSTALLLOG || OwnError "Unable To Copy Configuration Files "

# EE Command
cp -a /tmp/easyengine/usr/local/sbin/easyengine /usr/local/sbin/ &>> $INSTALLLOG || OwnError "Unable To Copy EasyEngine Command"

# EE Man Pages<commit_msg>Remove Unwated Install Codes<commit_after>#!/bin/bash



# Checking Linux Distro Is Ubuntu
if [ ! -f /etc/lsb-release ]
then
	echo -e "\033[31mEasyEngine (ee) Is Made For Ubuntu Only As Of Now\e[0m"
	echo -e "\033[31mYou Are Free To Fork EasyEngine (ee): https://github.com/rtCamp/easyengine/fork\e[0m"
	exit 100
fi



# Checking Permissions
Permission=$(id -u)
if [ $Permission -ne 0 ] 
then
	echo -e "\033[31mSudo Privilege Required...\e[0m"
	echo -e "\033[31mUses:\e[0m\033[34m curl -sL rt.cx/ee | sudo bash\e[0m"
	exit 100 
fi


# Make Variables Available For Later Use
LOGDIR=/var/log/easyengine
INSTALLLOG=/var/log/easyengine/install.log


# Capture Errors
OwnError()
{
	echo -e "[ `date` ] \033[31m$@\e[0m" | tee -ai $INSTALLLOG
	exit 101
}


# Pre Checks To Avoid Later Screw Ups
# Checking Logs Directory

if [ ! -d $LOGDIR ]
then
	echo -e "\033[34mCreating EasyEngine (ee) Log Directory, Please Wait...\e[0m"
	mkdir -p $LOGDIR || OwnError "Unable To Create Log Directory $LOGDIR"
fi

# Checking Tee
if [ ! -x  /usr/bin/tee ]
then
	echo -e "\033[31mTee Command Not Found\e[0m"
	echo -e "\033[34mInstalling Tee, Please Wait...\e[0m"
	sudo apt-get -y install coreutils &>> $INSTALLLOG || OwnError "Unable to install tee"
fi

echo &>> $INSTALLLOG
echo &>> $INSTALLLOG
echo -e "\033[34mEasyEngine (ee) Installation Started [$(date)]\e[0m" | tee -ai $INSTALLLOG


# Checking Ed
if [ ! -x  /bin/ed ]
then
	echo -e "\033[31mEd Command Not Found\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[34mInstalling Ed, Please Wait...\e[0m" | tee -ai $INSTALLLOG
	sudo apt-get -y install ed &>> $INSTALLLOG || OwnError "Unable to install ed"
fi

# Checking Wget
if [ ! -x  /usr/bin/wget ]
then
	echo -e "\033[31mWget Command Not Found\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[34mInstalling Wget, Please Wait...\e[0m" | tee -ai $INSTALLLOG
	sudo apt-get -y install wget &>> $INSTALLLOG || OwnError "Unable To Install Wget"
fi

# Checking Curl
if [ ! -x  /usr/bin/curl ]
then
	echo -e "\033[31mCurl Command Not Found\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[34mInstalling Curl, Please Wait...\e[0m" | tee -ai $INSTALLLOG
	sudo apt-get -y install curl &>> $INSTALLLOG || OwnError "Unable To Install Curl"
fi

# Checking Tar
if [ ! -x  /bin/tar ]
then
	echo -e "\033[31mTar Command Not Found\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[34mInstalling Tar, Please Wait...\e[0m" | tee -ai $INSTALLLOG
	sudo apt-get -y install tar &>> $INSTALLLOG || OwnError "Unable To Install Tar"
fi

# Checking Git
if [ ! -x  /usr/bin/git ]
then
	echo -e "\033[31mGit Command Not Found\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[34mInstalling Git, Please Wait...\e[0m" | tee -ai $INSTALLLOG
	sudo apt-get -y install git-core &>> $INSTALLLOG || OwnError "Unable To Install Git"
fi

# Checking Name Servers
if [[ -z $(cat /etc/resolv.conf 2> /dev/null | awk '/^nameserver/ { print $2 }') ]]
then
	echo -e "\033[31mNo Name Servers Detected\e[0m" | tee -ai $INSTALLLOG
	echo -e "\033[31mPlease Configure /etc/resolv.conf\e[0m" | tee -ai $INSTALLLOG
	exit 102
fi

# Pre Checks End

# Clone EasyEngine (ee)
echo -e "\033[34mCloning EasyEngine (ee), Please Wait...\e[0m" | tee -ai $INSTALLLOG
	
# Remove Older EasyEngine (ee) If Found
rm -rf /tmp/easyengine &>> /dev/null

# Clone EasyEngine (ee) Stable Repository
git clone -b stable git://github.com/rtCamp/easyengine.git /tmp/easyengine &>> $INSTALLLOG || OwnError "Unable To Clone Easy Engine"


# Create Directory /etc/easyengine
if [ ! -d /etc/easyengine ]
then
	# Create A Directory For EE Configurations
	mkdir -p /etc/easyengine || OwnError "Unable To Create Dir /etc/easyengine"
fi

# Create Directory /usr/share/easyengine
if [ ! -d /usr/share/easyengine/nginx ]
then
	# Create A Directory For EE Nginx Configurations
	mkdir -p /usr/share/easyengine/nginx || OwnError "Unable To Create Dir /usr/share/easyengine/nginx"
fi

# Install EasyEngine (ee)
echo -e "\033[34mInstalling EasyEngine (ee), Please Wait...\e[0m" | tee -ai $INSTALLLOG

# EasyEngine (ee) /etc Files
cp -a /tmp/easyengine/etc/bash_completion.d/ee /etc/bash_completion.d/ &>> $INSTALLLOG || OwnError "Unable To Copy EE Auto Complete File"
cp -a /tmp/easyengine/etc/easyengine/ee.conf /etc/easyengine/ &>> $INSTALLLOG || OwnError "Unable To Copy ee.conf File"

# EE /usr/share/easyengine Files
cp -a /tmp/easyengine/etc/nginx/* /usr/share/easyengine/nginx/ &>> $INSTALLLOG || OwnError "Unable To Copy Configuration Files "
cp -a /tmp/easyengine/usr/share/easyengine/* /usr/share/easyengine/ &>> $INSTALLLOG || OwnError "Unable To Copy Configuration Files "

# EE Command
cp -a /tmp/easyengine/usr/local/sbin/easyengine /usr/local/sbin/ &>> $INSTALLLOG || OwnError "Unable To Copy EasyEngine Command"

# EE Man Pages
{'fraction_non_alphanumeric': 0.14421352463340015, 'fraction_numerical': 0.03354784259943032, 'mean_word_length': 3.5620789220404236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 65, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6359999', 'n_tokens_mistral': 3926, 'n_tokens_neox': 3594, 'n_words': 1102}