Shinmaru
エロルアー Scripter!
[Bash][-Nix][Dialog] TFS Menu
This is a small discussion for a Script I'm making for Linux, it will do from Download Dependencies & Tools, Compile Boost(Thanks to Cykotitan and Fallen), Compile LuaJIT, allow you to add your own flags and compile TFS, this works with 0.2 - Latest, for now It supports Debian - Ubuntu and Fedora - CentOS, there can be more to add if I find it useful to do so.
Goal:
To make Linux OT server easier to manage.
WARNING:
I am new to bash, so go easy on me, I'm writing the script as I read tutorials about it. If you know better ways to write it, please teach me, just don;t come out to murder me for a mistake.
Update: v.3.0 ("Edit" still not worked on, just a few fixes.)
TFS Menu:
[bash]#!/bin/bash
addon=""
LuajitVer=-2.0.0-beta8
boostVer=.1.47.0
boostVer_=_1_47_0
filename=$(basename $0)
extension=${filename##*.}
filename=${filename%.*}
if [[ $EUID -ne 0 ]]; then
if [[ `dpkg -s dialog` || `rpm -qa | grep dialog` ]] ; then
dialog --backtitle "TFS Menu" --title "Warning" --yesno "This script was ran under normal user, in order to install any dependencies and such it is required to run as root.\nDo you want to log in to root?" 0 0
case $? in
0)
clear
if su -c "./$filename.sh" root ; then
exit 0
fi
;;
1)
echo "Continuing..."
;;
esac
else
clear
echo "Run this with root."
exit 0
fi
fi
if [[ $EUID -eq 0 ]]; then
if dpkg -s dialog ; then
echo "Dialog is Installed."
elif apt-get install dialog ; then
echo "Installing dialog..."
elif rpm -qa | grep dialog ; then
echo "Dialog is Installed."
elif yum install dialog ; then
echo "Installing dialog..."
else
echo "This system is not supported by this script."
fi
fi
while :
do
dialog --title "TFS Menu" --nocancel --menu "Choose an option:" 0 0 0 "Compile" "Compile Boost, TFS and more." "Install" "Install dependencies for APT and RPM based OS." "Edit" "Edit compiling files." "Exit" "Exit TFS Menu." 2> /tmp/tfsmenu.tmp.$$
result="TFS Menu"
value=$?
choice=`cat /tmp/tfsmenu.tmp.$$`
rm -f /tmp/tfsmenu.tmp.$$
case $value in
0)
if [ $choice = "Compile" ] ; then
while :
do
dialog --backtitle "TFS Menu" --title "Compile Menu" --nocancel --menu "Choose an option:" 0 0 0 "TFS" "Compile The Forgotten Server." "Boost" "Compile Boost libraries." "LuaJIT" "Compile Lua Just-In-Time." "Back" "Return back to the Main Menu." 2> /tmp/cmpmenu.tmp.$$
value=$?
choice=`cat /tmp/cmpmenu.tmp.$$`
rm -f /tmp/cmpmenu.tmp.$$
case $value in
0)
if [ $choice = "TFS" ] ; then
clear
if [ -f "autogen.sh" ]; then
./autogen.sh
fi
if [ -f "configure.ac" ]; then
./configure --enable-mysql $addon
fi
if [ -f "build.sh" ]; then
./build.sh
else
mkdir obj
make
fi
if [ -d "obj" ] ; then
mv *.o obj/
echo "*.o files where moved to obj/"
else
mkdir obj
mv *.o onj/
echo "*.o files where moved to obj/"
fi
if [ -d "src" ] ; then
mv *.cpp *.h src/
echo "*.cpp and *.h where moved to src/"
else
mkdir src
mv *.cpp *.h src/
echo "*.cpp and *.h where moved to src/"
fi
elif [ $choice = "Boost" ] ; then
clear
if [ -f boost$boostVer_.tar.gz ] || wget "http://dl.dropbox.com/u/36141316/boost$boostVer_.tar.gz" ; then
tar xzf boost$boostVer_.tar.gz
cd boost$boostVer_/
chmod +x bootstrap.sh
if ./bootstrap.sh ; then
if ./bjam variant=release link=static threading=multi ; then
echo "Boost$boostVer_ has been installed."
fi
else
echo "Error: A problem occured with bootstrap.sh ."
fi
cd ..
else
echo "Error: Unable to download Boost$boostVer ."
fi
elif [ $choice = "LuaJIT" ] ; then
clear
if [ -f "/usr/local/bin/luajit$LuajitVer" ]; then
result='LuaJIT has already been installed.'
else
wget http://luajit.org/download/LuaJIT$LuajitVer.tar.gz
tar zxf LuaJIT-2.0.0-beta8.tar.gz
cd LuaJIT-2.0.0-beta8
make && make install
ln -sf luajit-2.0.0-beta8 /usr/local/bin/luajit
cd ..
echo "LUAjit............Compiled & Installed."
fi
elif [ $choice = "Back" ] ; then
break
fi
;;
esac
done
elif [ $choice = "Install" ] ; then
while :
do
dialog --backtitle "TFS Menu" --title "Install Menu" --nocancel --menu "Choose an option:" 0 0 0 "APT" "Install APT based compiling libraries(Debian/Ubuntu)." "RPM" "Install RPM based compiling libraries(Fedora/CentOS)." "Back" "Return to the Main Menu." 2> /tmp/instmenu.tmp.$$
value=$?
choice=`cat /tmp/instmenu.tmp.$$`
rm -f /tmp/instmenu.tmp.$$
case $value in
0)
if [ $choice = "APT" ] ; then
clear
apt-get install build-essential libxml2-dev libxml++2.6-dev liblua5.1-0-dev libboost-all-dev libmysql++-dev libgmp3-dev liblua5.1-sql-mysql-dev liblua5.1-sql-sqlite-dev libsqlite3-dev zlib1g-dev dh-autoreconf
elif [ $choice = "RPM" ] ; then
clear
yum install mysql++-devel lua-devel boost-devel gmp-devel lua-sql-mysql lua-sql-sqlite libsqlite3x-devel zlib-devel libxml2-devel libxml++-devel kernel-devel mysql-connector-c++ mysql-connector-c++-devel && yum groupinstall "Development Tools"
elif [ $choice = "Back" ] ; then
break
fi
;;
esac
done
elif [ $choice = "Edit" ] ; then
while :
do
dialog --backtitle "TFS Menu" --title "Edit Menu" --nocancel --menu "Choose an option:" 0 0 0 "ConAC" "Modify flags inside configure.ac." "Config" "Add additional features." "Back" "Return to the Main Menu." 2> /tmp/edtmenu.tmp.$$
value=$?
choice=`cat /tmp/edtmenu.tmp.$$`
rm -f /tmp/edtmenu.tmp.$$
case $value in
0)
if [ $choice = "Back" ] ; then
break
fi
;;
esac
done
elif [ $choice = "Exit" ] ; then
break
fi
;;
esac
done
clear[/bash]
Screenshot:
TFS Menu, Using dialog.
Compile Menu.
Install Menu.
Edit Menu.
Change:
I will be adding more stuff to it.
Instructions:
Copy this to any text file and save it as a .sh file.
Move the file to where the TFS source files are at.
Type`./NAME-OF-FILE.sh`
Read and follow instructions.
This is not the final script. it's not done.
Note:
Any kind of testing would be appreciated, the OS in which this can be ran, are:
Any Debian/Ubuntu based Distro.(Needs to have apt-get)
Any Fedora based Distro.(Needs to have yum)
This is a small discussion for a Script I'm making for Linux, it will do from Download Dependencies & Tools, Compile Boost(Thanks to Cykotitan and Fallen), Compile LuaJIT, allow you to add your own flags and compile TFS, this works with 0.2 - Latest, for now It supports Debian - Ubuntu and Fedora - CentOS, there can be more to add if I find it useful to do so.
Goal:
To make Linux OT server easier to manage.
WARNING:
I am new to bash, so go easy on me, I'm writing the script as I read tutorials about it. If you know better ways to write it, please teach me, just don;t come out to murder me for a mistake.
Update: v.3.0 ("Edit" still not worked on, just a few fixes.)
TFS Menu:
[bash]#!/bin/bash
addon=""
LuajitVer=-2.0.0-beta8
boostVer=.1.47.0
boostVer_=_1_47_0
filename=$(basename $0)
extension=${filename##*.}
filename=${filename%.*}
if [[ $EUID -ne 0 ]]; then
if [[ `dpkg -s dialog` || `rpm -qa | grep dialog` ]] ; then
dialog --backtitle "TFS Menu" --title "Warning" --yesno "This script was ran under normal user, in order to install any dependencies and such it is required to run as root.\nDo you want to log in to root?" 0 0
case $? in
0)
clear
if su -c "./$filename.sh" root ; then
exit 0
fi
;;
1)
echo "Continuing..."
;;
esac
else
clear
echo "Run this with root."
exit 0
fi
fi
if [[ $EUID -eq 0 ]]; then
if dpkg -s dialog ; then
echo "Dialog is Installed."
elif apt-get install dialog ; then
echo "Installing dialog..."
elif rpm -qa | grep dialog ; then
echo "Dialog is Installed."
elif yum install dialog ; then
echo "Installing dialog..."
else
echo "This system is not supported by this script."
fi
fi
while :
do
dialog --title "TFS Menu" --nocancel --menu "Choose an option:" 0 0 0 "Compile" "Compile Boost, TFS and more." "Install" "Install dependencies for APT and RPM based OS." "Edit" "Edit compiling files." "Exit" "Exit TFS Menu." 2> /tmp/tfsmenu.tmp.$$
result="TFS Menu"
value=$?
choice=`cat /tmp/tfsmenu.tmp.$$`
rm -f /tmp/tfsmenu.tmp.$$
case $value in
0)
if [ $choice = "Compile" ] ; then
while :
do
dialog --backtitle "TFS Menu" --title "Compile Menu" --nocancel --menu "Choose an option:" 0 0 0 "TFS" "Compile The Forgotten Server." "Boost" "Compile Boost libraries." "LuaJIT" "Compile Lua Just-In-Time." "Back" "Return back to the Main Menu." 2> /tmp/cmpmenu.tmp.$$
value=$?
choice=`cat /tmp/cmpmenu.tmp.$$`
rm -f /tmp/cmpmenu.tmp.$$
case $value in
0)
if [ $choice = "TFS" ] ; then
clear
if [ -f "autogen.sh" ]; then
./autogen.sh
fi
if [ -f "configure.ac" ]; then
./configure --enable-mysql $addon
fi
if [ -f "build.sh" ]; then
./build.sh
else
mkdir obj
make
fi
if [ -d "obj" ] ; then
mv *.o obj/
echo "*.o files where moved to obj/"
else
mkdir obj
mv *.o onj/
echo "*.o files where moved to obj/"
fi
if [ -d "src" ] ; then
mv *.cpp *.h src/
echo "*.cpp and *.h where moved to src/"
else
mkdir src
mv *.cpp *.h src/
echo "*.cpp and *.h where moved to src/"
fi
elif [ $choice = "Boost" ] ; then
clear
if [ -f boost$boostVer_.tar.gz ] || wget "http://dl.dropbox.com/u/36141316/boost$boostVer_.tar.gz" ; then
tar xzf boost$boostVer_.tar.gz
cd boost$boostVer_/
chmod +x bootstrap.sh
if ./bootstrap.sh ; then
if ./bjam variant=release link=static threading=multi ; then
echo "Boost$boostVer_ has been installed."
fi
else
echo "Error: A problem occured with bootstrap.sh ."
fi
cd ..
else
echo "Error: Unable to download Boost$boostVer ."
fi
elif [ $choice = "LuaJIT" ] ; then
clear
if [ -f "/usr/local/bin/luajit$LuajitVer" ]; then
result='LuaJIT has already been installed.'
else
wget http://luajit.org/download/LuaJIT$LuajitVer.tar.gz
tar zxf LuaJIT-2.0.0-beta8.tar.gz
cd LuaJIT-2.0.0-beta8
make && make install
ln -sf luajit-2.0.0-beta8 /usr/local/bin/luajit
cd ..
echo "LUAjit............Compiled & Installed."
fi
elif [ $choice = "Back" ] ; then
break
fi
;;
esac
done
elif [ $choice = "Install" ] ; then
while :
do
dialog --backtitle "TFS Menu" --title "Install Menu" --nocancel --menu "Choose an option:" 0 0 0 "APT" "Install APT based compiling libraries(Debian/Ubuntu)." "RPM" "Install RPM based compiling libraries(Fedora/CentOS)." "Back" "Return to the Main Menu." 2> /tmp/instmenu.tmp.$$
value=$?
choice=`cat /tmp/instmenu.tmp.$$`
rm -f /tmp/instmenu.tmp.$$
case $value in
0)
if [ $choice = "APT" ] ; then
clear
apt-get install build-essential libxml2-dev libxml++2.6-dev liblua5.1-0-dev libboost-all-dev libmysql++-dev libgmp3-dev liblua5.1-sql-mysql-dev liblua5.1-sql-sqlite-dev libsqlite3-dev zlib1g-dev dh-autoreconf
elif [ $choice = "RPM" ] ; then
clear
yum install mysql++-devel lua-devel boost-devel gmp-devel lua-sql-mysql lua-sql-sqlite libsqlite3x-devel zlib-devel libxml2-devel libxml++-devel kernel-devel mysql-connector-c++ mysql-connector-c++-devel && yum groupinstall "Development Tools"
elif [ $choice = "Back" ] ; then
break
fi
;;
esac
done
elif [ $choice = "Edit" ] ; then
while :
do
dialog --backtitle "TFS Menu" --title "Edit Menu" --nocancel --menu "Choose an option:" 0 0 0 "ConAC" "Modify flags inside configure.ac." "Config" "Add additional features." "Back" "Return to the Main Menu." 2> /tmp/edtmenu.tmp.$$
value=$?
choice=`cat /tmp/edtmenu.tmp.$$`
rm -f /tmp/edtmenu.tmp.$$
case $value in
0)
if [ $choice = "Back" ] ; then
break
fi
;;
esac
done
elif [ $choice = "Exit" ] ; then
break
fi
;;
esac
done
clear[/bash]
Screenshot:
TFS Menu, Using dialog.
Compile Menu.
Install Menu.
Edit Menu.
Change:
Code:
[B]v.3.0[/B]
* Added a small "cleanup" after compiling TFS.(More to clean)
* Added a "checking" to see if dialog is installed on your system.(Root required)
[B]v.2.9:[/B]
* Improved the whole script to use an actual Terminal GUI
* Added better "checks"(more to be improved).
* Code reduced.
[B]v.2.2:[/B]
* Fixed Boost not compiling.
* Added some "checks" for the commands.
I will be adding more stuff to it.
Instructions:
Copy this to any text file and save it as a .sh file.
Move the file to where the TFS source files are at.
Type`./NAME-OF-FILE.sh`
Read and follow instructions.
This is not the final script. it's not done.
Note:
Any kind of testing would be appreciated, the OS in which this can be ran, are:
Any Debian/Ubuntu based Distro.(Needs to have apt-get)
Any Fedora based Distro.(Needs to have yum)
Last edited: