Skip to content

Instantly share code, notes, and snippets.

@ZEROF
Last active January 29, 2016 03:32
Show Gist options
  • Save ZEROF/f7f8caa9c86a84c4ac66 to your computer and use it in GitHub Desktop.
Save ZEROF/f7f8caa9c86a84c4ac66 to your computer and use it in GitHub Desktop.
THIS IS OLD VERSION NOT SUPPORTED ANYMORE
Check: https://gist.github.com/ZEROF/10743343
#!/bin/bash
# This script will help you to set Hiawatha Server.
# Tested with Debian 7/8 32/64bit.
# Script author ZEROF zerof at backbox dot org
# If you like Linux and security join http://backbox.org
# Script version 0.5t
# This script is distributed under a DO WHAT THE F*** YOU WANT TO PUBLIC LICENSE.
# http://rmlh.me/license.html
clear
function banner ()
{
echo ""
echo -e "╦ ╦┬┌─┐┬ ┬┌─┐┌┬┐┬ ┬┌─┐ ╔═╗╦ ╦╔═╗ ╔═╗╔═╗╔╦╗ ╔╦╗┌─┐┬─┐┬┌─┐╔╦╗╔╗ "
echo -e "╠═╣│├─┤│││├─┤ │ ├─┤├─┤───╠═╝╠═╣╠═╝───╠╣ ╠═╝║║║───║║║├─┤├┬┘│├─┤ ║║╠╩╗"
echo -e "╩ ╩┴┴ ┴└┴┘┴ ┴ ┴ ┴ ┴┴ ┴ ╩ ╩ ╩╩ ╚ ╩ ╩ ╩ ╩ ╩┴ ┴┴└─┴┴ ┴═╩╝╚═╝"
}
# Vars
config="/etc/hiawatha/hiawatha.conf"
fpm="/etc/php5/fpm/pool.d/www.conf"
connect1="ConnectTo = 127.0.0.1:2005"
connect2="ConnectTo = /var/lib/hiawatha/php5-fpm.sock"
www="listen = /var/run/php5-fpm.sock"
www1="listen = /var/lib/hiawatha/php5-fpm.sock"
info="[!]This is only for fresh installed servers, script don't check if you made changes on your system.\n[!]If something goes wrong, you can find hiawatha.conf.backup in /etc/hiawatha/."
up="\033[1;33m[!]\e[0m"
#User check. Must be r00t
if [ $USER != 'root' ]; then
echo "[!]Are you root? NO. Then try again."
exit
fi
# End function
function enter ()
{
echo ""
read -sn 1 -p "Press any key to continue..."
clear
}
#Check for system versin and egrep last package from tuxhelp
download_deb() {
wget "https://files.tuxhelp.org/hiawatha/$(wget -O- https://files.tuxhelp.org/hiawatha | egrep -o "hiawatha_[0-9\.]+_$1.deb" | sort -V | sort -V | tail -1)"
}
#Download
down() {
if [ "$(getconf LONG_BIT)" = "64" ]; then
download_deb amd64
else
download_deb i386
fi
}
# Just to be sure that menu will work around
$selection
# Restart Hiawatha
function restart ()
{
service hiawatha restart
}
# Install MariaDB
function mariadb ()
{
echo -e "\n$up \e[40;38;5;82m SETTING InnoDB ENGINE \e[0m\n"
echo ""
# read -p "Do you want to use InnoDB Storage Engines (y/n)? " choice
# case "$choice" in
# y|Y ) sed -i 's/\# Read the manual for more InnoDB related options. There are many\!/\# Read the manual for more InnoDB related options.There are many\!\n\# Enable the two below to disable XtraDB+ and enable the standard InnoDB Plugin\n\[mysqld]\nignore_builtin_innodb\nplugin_load=innodb=ha_innodb.so\n\# The following should not be needed if you are using a mariadb package:\nplugin_dir=\/usr\/lib\/mysql\/plugin/g' /etc/mysql/my.cnf;;
# n|N ) selection;;
# * ) echo -e "$up Wrong answer. Don't worry you can use InnoDB settings when you are ready";;
#esac
clear
}
# Setting wordpress vhost [s]
function wordpress_vhost()
{
echo -e "\e[31m\n$up This script will remove any directory with name wordpress, take care about that.\nControl + C if you want to check then start script again.\e[0m"
sleep 5
echo -e -n "\n$up Set site/vhost remove number(example 1-10): "
read number
echo -e -n "\n$up Enter domain name or your server IP: "
read domain
echo -e -n "\n$up Enter site folder (example /var/www/hiawatha/wordpress): "
read root
echo -e -n "\n$up Enter site default page (index.php or index.html): "
read index
echo -e "\n#${number}\nVirtualHost {\n\tHostname = ${domain} \n\tWebsiteRoot = ${root}\n\tStartFile = ${index} #Use index.php or index.html\n\t#AccessLogfile = ${root}/access.log\n\t#ErrorLogfile = ${root}/error.log\n\tTimeForCGI = 5\n\tUseFastCGI = PHP5\n\tUseToolKit = wordpress\n}\n
#${number}\nUrlToolkit {\nToolkitID = wordpress\nRequestURI exists Return\nMatch .*\?(.*) Rewrite /index.php?$1\nMatch .* Rewrite /index.php\n}" >> $config
}
# wget last version from WP site
function wordpress ()
{
if [ -d "$wordpress)" ]; then
rm -rf wordpress
else
echo -e "\n$up We are going to install your Wordpress site.\n"
enter
fi
wget http://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
echo -e -n "$up Your wordpress vhost directory (ex./var/www/hiawatha/wordpress): "
read path
cp -r wordpress ${path}
chown -R www-data:www-data ${path}
rm latest.tar.gz
rm -rf wordpress
}
# Removing wordpress installation
function rem_wordpress()
{
echo -n "\n\t$up Type Wordpress path directory (ex./var/www/hiawatha/wordpress):"
read word_path
rm -rf $word_path
echo -e -n "\n\t$up Enter your mysql user name: "
read user
echo -e -n "\n\t$up Type mysql password(you can't see your password): "
stty_orig=`stty -g`
stty -echo
read pass
stty $stty_orig
echo ""
echo -e -n "\n\t$up Type wordpress database name: "
read db_name
mysql -u $user -p$pass -e "drop database $db_name"
service mysql restart
}
# Setting MySql server details
function set_mysql ()
{
echo -e -n "\n\t$up Enter your mysql user name: "
read user
echo -e -n "\n\t$up Type mysql password(you can't see your password): "
stty_orig=`stty -g`
stty -echo
read pass
stty $stty_orig
echo ""
echo -e -n "\n\t$up Type database name: "
read db_name
mysql -u $user -p$pass -e "create database $db_name"
service mysql remove
}
# Simple function yes and no when user start installation of phpmyadmin
function yes_no ()
{
echo -e "\n$up \e[40;38;5;82mPHPMYADMIN INSTALLATION \e[0m\n"
read -p "Install phpMyAdmin (y/n)? " choice
case "$choice" in
y|Y ) phpmyadmin;admin_hiawatha;where_phpmyadmin;;
n|N ) selection;;
* ) echo -e "$up Wrong answer. Don't worry you can start phpMyadmin installation when you are ready";;
esac
}
# Need to be set for vhost needs
function where_phpmyadmin ()
{
echo -e -n "\n$up Type your main site path directory (ex./var/www/hiawatha/wordpress): "
read phpadmin
ln -s /usr/share/phpmyadmin $phpadmin
}
# Get last version from server and install
function phpmyadmin ()
{
apt-get install unzip
wget http://linux.re.rs/phpmyadmin-4.4.13.1/phpMyAdmin-4.4.13.1-all-languages.zip
unzip -q phpMyAdmin-4.4.13.1-all-languages.zip
mv phpMyAdmin-4.4.13.1-all-languages /usr/share/phpmyadmin
rm phpMyAdmin-4.4.13.1-all-languages.zip
}
# To use phpadmin hiawatha need to use index.php as default start page
function admin_hiawatha ()
{
sed -i '/#Use index.php or index.html/s/$/\n\tAlias = \/phpmyadmin:\/usr\/share\/phpmyadmin/' $config
restart
enter
}
# Hiawatha function to protect folders and file
function protect ()
{
echo -e -n "\n$up Enter order number for removing rules in the future(ex 1,2): "
read number
echo -e -n "\n$up Enter path directory you want to protect (example /var/www/hiawatha/): "
read directory
echo -e "\n#${number}0\nDirectory {\nPath = $directory\nAccessList = Deny All\n}" >> /etc/hiawatha/hiawatha.conf
restart
}
# Removing protection rule
function protect_remove ()
{
echo -e -n "\n$up Enter remove number: "
read n
for i in "${n[@]}"
do sed -i "/#${n}\0/,/} /d" $config
done
sed -i 's/ $//' $config
restart
}
#Add Balocco repository and install MaraDNS server
function maradns ()
{
echo "deb http://cdn.content-network.net/mirror/apt.balocco.name wheezy main" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FDDC810C92B84A1E
apt-get update
apt-get install maradns
clear
}
#Install Knot DNS server
function knot ()
{
file=/etc/apt/sources.list
if grep -q "deb http://deb.knot-dns.cz/debian/ wheezy main" "$file"; then
apt-get update
apt-get install -y knot
else
wget -O - http://deb.knot-dns.cz/debian/apt.key | apt-key add -
echo -e "#KnotDNS\ndeb http://deb.knot-dns.cz/debian/ $(lsb_release -sc) main" >> /etc/apt/sources.list
apt-get update
apt-get install -y knot
fi
}
# Menu
function print_menu()
{
banner
echo ""
echo "[1] - system update, upgrade and dist-upgrade."
echo "[2]- install required dependencies for Hiawatha."
echo "[3] - install PHP5 and PHP5 modules."
echo "[4] - installation of MariaDB (need more testing 'and InnoDB enabled for better performances')."
echo "[5] - secure MariaDB installation."
echo "[6] - install Hiawatha Webserver."
echo "[7] - set VPS/SERVER time zone."
echo -e "\n\e[40;38;5;82m SETTING HIAWATHA \e[30;48;5;82m WEB SERVER \e[0m \n"
echo "[8] - setting PHP-FPM (FastCGI)."
echo "[9] - add new VHOST (ex. site order number, yoursite.com, /var/www, index.php)"
echo "[10] - install Wordpress (don't run option 9)"
echo "[11] - remove VHOST."
echo "[12] - install phpMyadmin (run only after setting first vhost)"
echo "[13] - remove phpMyadmin."
echo "[14] - remove Wordpress installation."
echo -e "\n\e[40;38;5;82m HIAWATHA \e[30;48;5;82m SECURITY \e[0m \n"
echo "[15] - protect site directory."
echo "[16] - remove directory protection."
echo -e "\n\e[40;38;5;82m INSTALL \e[30;48;5;82m MARADNS \e[0m \n"
echo "[17] Install MaraDNS 2.0.09."
echo "[18] Install KnotDNS."
echo ""
echo "[0] - exit program"
echo ""
echo -e -n "$up Enter selection: "
}
selection=
until [ "$selection" = "0" ]; do
print_menu
read selection
echo ""
case $selection in
1 ) apt-get update;apt-get upgrade -y;apt-get dist-upgrade -y; apt-get install python-pip -y; apt-get install asciinema;clear;;
2 ) apt-get install libc6-dev libssl-dev dpkg-dev debhelper lynx curl fakeroot libxml2-dev libxslt1-dev -y;clear;;
3 ) apt-get install php5-cgi php5 php5-cli php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-xcache apache2-utils php5-fpm -y;enter;;
# 4 ) gpg --keyserver hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A;gpg -a --export CD2EFD2A | apt-key add -;echo -e "deb http://repo.percona.com/apt wheezy main\ndeb-src http://repo.percona.com/apt wheezy main" >> /etc/apt/sources.list;apt-get update;apt-get install percona-server-server-5.5 percona-server-client-5.5;enter ;;
4 ) apt-get install python-software-properties -y; apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db;add-apt-repository 'deb http://ftp.igh.cnrs.fr/pub/mariadb/repo/5.5/debian wheezy main' ;apt-get update;apt-get install mariadb-server -y;sleep 2;mariadb;service mysql restart;sed -i 's/find_mysql_client/#find_mysql_client/g' /usr/bin/mysql_secure_installation;enter;clear ;;
5 ) mysql_secure_installation;enter;clear ;;
6 ) down; dpkg -i hiawatha_*.deb; rm hiawatha_*;enter ;;
7 ) dpkg-reconfigure tzdata; enter; echo "We are done.It was cool? NO :)";enter ;;
# Two way to write this shit (line by line, or x, for in and then sed): 8 ) sed -i '47s/#//' $config; sed -i '51s/#//' $config; sed -i '53s/#//' $config;sed -i '58/#//' $config; enter ;;
8 ) echo -e $info; sleep 3; cp $config $config\.backup;x=( 47 51 53 54 55 56 57 );for i in "${x[@]}";do sed -i "${i}s/^#//" $config;done; sed -i s#"$connect1"#"$connect2"#g $config; sed -i s#"$www"#"$www1"#g $fpm; service php5-fpm restart; enter ;;
9 ) echo -e -n "\n$up Set site/vhost remove number(example 1-10): ";read number; echo -e -n "\n$up Enter domain name or your server IP: ";read domain;echo -e -n "\n$up Enter site folder (example /var/www/hiawatha): ";read root;echo -e -n "\n$up Enter site default page (index.php or index.html): ";read index;echo -e "\n#${number}\nVirtualHost {\n\tHostname = ${domain} \n\tWebsiteRoot = ${root}\n\tStartFile = ${index} #Use index.php or index.html\n\t#AccessLogfile = ${root}/access.log\n\t#ErrorLogfile = ${root}/error.log\n\tTimeForCGI = 5\n\tUseFastCGI = PHP5\n}" >> $config;enter ;;
10 ) wordpress_vhost;wordpress;set_mysql;echo "";restart;echo "";service php5-fpm restart;echo -e "\e[31m\n$up Open your browser with your domain or ip and start wordpress installation.\nIf something goes wrong check your settings (/etc/hiawatha/hiawatha.conf)\e[0m";sleep 3;yes_no ;;
11 ) echo -e -n "\n$up Enter site/vhost remove number: " ;read n; for i in "${n[@]}";do sed -i "/#${n}/,/} /d" $config;done;sed -i '$d' $config;enter ;;
12 ) echo -e "\n$up\e[31m If you tested script v0.3 (v0.3b is ok) then you need to check #1 vhost settings, find \e[40;38;5;82m \"StartFile = index.php\" \e[0m, \e[31mand replace it with:\n\n\tStartFile = index.php ##Use index.php or index.html\e[0m\n";enter;phpmyadmin;admin_hiawatha;where_phpmyadmin; ;;
13 ) rem=$(find / -type d -name phpmyadmin); rm -rf $rem;enter;;
14 ) rem_wordpress;enter ;;
15 ) echo -e "\n$up\e[31m If you want to protect directory from public access use this option\e[0m";protect ;;
16 ) protect_remove ;;
17 ) maradns ;;
18 ) knot;enter ;;
0 ) exit ;;
* ) echo -e "$up Please enter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ,13, 14, 15, 16, 17,18 or 0"
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment