231 lines
5.8 KiB
Bash
Executable file
231 lines
5.8 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# Configure environment
|
|
# Copyright (C) 2017 AleaJactaEst
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
usage()
|
|
{
|
|
cat << EOF
|
|
usage:$0 [options]
|
|
prepare mysql (create directory, update configuration)
|
|
|
|
options:
|
|
-h, --help : Show this help
|
|
-d, --debug : Show debug message
|
|
EOF
|
|
}
|
|
|
|
#####################
|
|
# MAIN
|
|
#####################
|
|
source /opt/servercontainer_function.sh
|
|
msg_info "$(basename $0) => START"
|
|
|
|
while test $# -gt 0
|
|
do
|
|
case "$1" in
|
|
-h|--help)
|
|
usage
|
|
exit 1
|
|
;;
|
|
-d|--debug)
|
|
set_debug 1
|
|
shift
|
|
;;
|
|
*)
|
|
msg_error "options '$1' not recognize"
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
####################################
|
|
# Load Environment
|
|
####################################
|
|
msg_debug "Load environment"
|
|
if [[ ! -f /opt/khanat_config.sh ]]
|
|
then
|
|
msg_error "Missing /opt/khanat_config.sh"
|
|
exit 2
|
|
fi
|
|
source /opt/khanat_config.sh
|
|
|
|
####################################
|
|
# configure shard.sh
|
|
####################################
|
|
msg_info "configure shard.sh"
|
|
cat << EOF > /opt/shard.sh
|
|
# 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
|
|
|
|
export KHANAT_HOME=/home/gameserver
|
|
export KHANAT_PATH=/home/gameserver/khanat
|
|
export PATH=\$PATH:/usr/local/bin:/usr/local/sbin
|
|
export PATCH_CLIENT_SYSTEM=\$KHANAT_HOME/khanat/patch_service
|
|
|
|
export DIRCLIENT="$DIRCLIENT"
|
|
export PACKAGECLIENT="$PACKAGECLIENT"
|
|
export PREPARE_CLIENT_DIR="khanat/prepare_client/\$DIRCLIENT"
|
|
export CLIENT_DIR="khanat/client_service"
|
|
export HOME_PREPARE_CLIENT="\$KHANAT_HOME/\$PREPARE_CLIENT_DIR"
|
|
export HOME_CLIENT="\$KHANAT_HOME/\$CLIENT_DIR"
|
|
EOF
|
|
|
|
|
|
####################################
|
|
# Initialize bashrc gameserver
|
|
####################################
|
|
msg_info "configure bashrc"
|
|
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
|
|
|
|
export KHANAT_HOME=/home/gameserver
|
|
export KHANAT_PATH=/home/gameserver/khanat
|
|
export PATH=\$PATH:/usr/local/bin
|
|
export PATCH_CLIENT_SYSTEM=\$KHANAT_HOME/khanat/patch_service
|
|
|
|
export DIRCLIENT="$DIRCLIENT"
|
|
export PACKAGECLIENT="$PACKAGECLIENT"
|
|
export PREPARE_CLIENT_DIR="khanat/prepare_client/\$DIRCLIENT"
|
|
export CLIENT_DIR="khanat/client_service"
|
|
export HOME_PREPARE_CLIENT="\$KHANAT_HOME/\$PREPARE_CLIENT_DIR"
|
|
export HOME_CLIENT="\$KHANAT_HOME/\$CLIENT_DIR"
|
|
|
|
EOF
|
|
chown gameserver:$(id -g -n gameserver) /home/gameserver/.bashrc
|
|
|
|
|
|
# load environment
|
|
source /home/gameserver/.bashrc
|
|
|
|
####################################
|
|
# Initialize bashrc (for root)
|
|
####################################
|
|
msg_debug "Configure bashrc (for root)"
|
|
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
|
|
|
|
####################################
|
|
# Adding sudo command
|
|
####################################
|
|
|
|
# Update sudo rule (you can execute all command as root)
|
|
msg_debug "Configure sudo"
|
|
cat << EOF > /etc/sudoers.d/gameserver
|
|
# User privilege specification
|
|
gameserver ALL=NOPASSWD: ALL
|
|
EOF
|
|
|
|
####################################
|
|
# LOGING HEADER
|
|
####################################
|
|
# Message see when connect on ssh
|
|
|
|
# Before login
|
|
msg_debug "Configure message login"
|
|
cat << EOF > /etc/issue.net
|
|
*********************
|
|
* KHANAT SERVER DEV *
|
|
*********************
|
|
|
|
account gameserver
|
|
password khanat
|
|
|
|
EOF
|
|
|
|
# After Login
|
|
msg_debug "Configure banner"
|
|
cat << EOF > /etc/motd
|
|
***************************************************
|
|
connect to root use gameserver account and launch sudo command
|
|
like :
|
|
|
|
sudo bash
|
|
|
|
---------------------------------------------------
|
|
mysql : account root (no password)
|
|
---------------------------------------------------
|
|
log khanat server : /home/gameserver/khanat/server/log/log.log
|
|
***************************************************
|
|
EOF
|
|
|
|
# Activate banner
|
|
msg_debug "Activate banner"
|
|
sed -i 's/#Banner/Banner/g' /etc/ssh/sshd_config
|
|
|
|
|
|
# Initialize ssh
|
|
/etc/init.d/ssh restart
|
|
|
|
####################################
|
|
# End
|
|
####################################
|
|
msg_info "$(basename $0) => END"
|