khanat-code-old/dist/docker/server/debian/common/init-basic.sh

161 lines
4.4 KiB
Bash
Raw Normal View History

#!/bin/bash
# Install all package we need to prepare and install khanat server
#
# Copyright (C) 2017 AleaJactaEst
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
echo "Start Basic"
2017-08-27 14:38:04 +00:00
####################################
# Install some package for server (apache, mysql, screen)
####################################
DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server
apt-get install -y apache2 php5 libapache2-mod-php5 php5-mysql apache2-utils php5-gd php5-imagick rrdtool screen mcrypt php5-mcrypt
2017-08-27 14:38:04 +00:00
####################################
# Initialize database
####################################
/usr/bin/mysql_install_db --user=mysql --skip-name-resolve || exit 2
# Start the MySQL daemon in the background.
/usr/sbin/mysqld &
mysql_pid=$!
2017-08-27 14:38:04 +00:00
# Wait mysql start
until /usr/bin/mysqladmin ping >/dev/null 2>&1
do
echo -n "."
sleep 1
done
# Initialize password root (to empty)
/usr/bin/mysqladmin -u root password '' || exit 2
2017-08-27 14:38:04 +00:00
# Adding phpmyadmin
DEBIAN_FRONTEND=noninteractive apt-get install -y phpmyadmin
ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf || exit 2
a2enconf phpmyadmin.conf || exit 2
cp /etc/phpmyadmin/config.inc.php /etc/phpmyadmin/config.inc.php.ref || exit 2
awk '{if($0 ~ /AllowNoPassword/){$1="";}; print $0;}' /etc/phpmyadmin/config.inc.php.ref > /etc/phpmyadmin/config.inc.php || exit 2
# Stop MySQL
/usr/bin/mysqladmin shutdown
# Wait MySQL stop
wait $mysql_pid
2017-08-27 14:38:04 +00:00
####################################
# Initialize bashrc (for root)
2017-08-27 14:38:04 +00:00
####################################
cat << EOF > /root/.bashrc
# bashrc: executed by bash(1) for non-login shells.
# You may uncomment the following lines if you want 'ls' to be colorized:
export SHELL=/bin/bash
export LS_OPTIONS='--color=auto'
eval "\`dircolors\`"
alias ls='ls \$LS_OPTIONS'
alias ll='ls \$LS_OPTIONS -l'
alias l='ls \$LS_OPTIONS -lA'
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
# Autocompletion
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
EOF
2017-08-27 14:38:04 +00:00
####################################
# Initialize bashrc (for gameserver)
####################################
cat << EOF > /home/gameserver/.bashrc
# bashrc: executed by bash(1) for non-login shells.
# You may uncomment the following lines if you want 'ls' to be colorized:
export SHELL=/bin/bash
export LS_OPTIONS='--color=auto'
eval "\`dircolors\`"
alias ls='ls \$LS_OPTIONS'
alias ll='ls \$LS_OPTIONS -l'
alias l='ls \$LS_OPTIONS -lA'
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
# Autocompletion
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
EOF
chown gameserver:gameserver /home/gameserver/.bashrc
####################################
# Adding sudo command
####################################
# Update sudo rule (you can execute all command as root)
cat << EOF > /etc/sudoers.d/gameserver
# User privilege specification
2017-08-27 14:38:04 +00:00
gameserver ALL=NOPASSWD: ALL
EOF
2017-08-27 14:38:04 +00:00
####################################
# LOGING HEADER
####################################
# Message see when connect on ssh
# Before login
cat << EOF > /etc/issue.net
*********************
* KHANAT SERVER DEV *
*********************
account gameserver
password khanat
EOF
# After Login
cat << EOF > /etc/motd
***************************************************
connect to root use gameserver account and launch sudo command
like :
sudo bash
2017-08-27 14:38:04 +00:00
---------------------------------------------------
mysql : account root (no password)
---------------------------------------------------
log khanat server : /home/gameserver/khanat/server/log/log.log
2017-08-27 14:38:04 +00:00
***************************************************
EOF
# Activate banner
sed -i 's/#Banner/Banner/g' /etc/ssh/sshd_config
####################################
# End
####################################
echo "End Basic"