#https://github.com/Neo-Oli/termux-ubuntu References # EMPIRESSERVERHEADER
echo PARAM DEBUG ${currdir} ${currentexecfile}
if [ -z ${currdir} ] ;then
export currdir=$(pwd)
fi
#This prevent new instances to overwrite current directory causes multiple problems
if [ -z ${currentexecfile} ] ;then
export currentexecfile=${0}
fi
powershell.exe -Command "Start-Process PowerShell 'Install-Package Bash -Confirm' -Verb RunAs"
powershell.exe -Command "Start-Process PowerShell 'Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))' -Verb RunAs"
powershell.exe -Command "Start-Process PowerShell 'Set-ExecutionPolicy RemoteSigned -Scope CurrentUser' -Verb RunAs"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
##############################
# Install dependencies
brew install python wget gnu-tar subversion gnu-sed dialog
##############################







########################################################## Install Logic ############################################33

#if [ $(whoami) != root ]; then
#echo Please re run this compile script with root
#echo Thank you
#exit
#fi


export installTarget=/usr/local/bin
empiresServer="${installTarget}/empires-server"
echo " Please Enter your password as we install empires-server in your PATH"
sudo cat > "${empiresServer}" <<- EOM
#!/bin/sh
bash ${currdir}/${0}
EOM
chmod 777 "${empiresServer}"

if [ ! -d empiresservercontainer ] || [ $(cat empiresservercontainer/buildnumber) -lt 6969696 ] ; then
lineno=94 #This line is the position of the md5hash stored #Please Change this Number to successfully compiles +2 from last line
initorigindir=$(pwd)
integrity=$(sed -n "${lineno}p" "$0") #https://stackoverflow.com/questions/21651310/reading-a-particular-line-from-a-file-in-bash-script-using-variable-as-line-numb
echo "${integrity}" > hash
echo Preparing package empires-server
echo Pulling Package from the script
if [ -z $(which busybox) ]; then echo no busybox detec.. wait this is macOS environment mode ;fi
echo 'Preparing For installation'
tail -n +95 $0 > empires-RNT #Please Change this Number to successfully compiles +3 from last line IF 87 Line then 89
if md5sum -c hash ; then
echo Archive Integrity Verified
rm hash
else
echo It is altered or ruined thus installation is aborted
rm hash
echo "Hash is skipped on macOS for weird reason"
fi
tar -xf empires-RNT
rm -rf empires-RNT ; echo Installation Successfull


fi
#####################################################################################################################


#FILESHRINKING LOGIC#########################################

echo "#!/bin/sh" > ${0}
echo "cd ${currdir}/empiresservercontainer" >> ${0}
echo "bash empires-server-routines.sh" >> ${0}


#############################################################


########## Handing over control ##################

echo Starting EALServer
echo Entering Directory and handing over control

cd ${currdir}/empiresservercontainer
bash empires-server-routines.sh

##################################################

#FILESHRINKING LOGIC CLEANING#########################################
rm -rf ${currdir}/*_minimized
#delete temporary file
##################################################################
exit
EOF
