#!/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 . 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 cat << ENDOFCOMMENT +--------------------------+ | KHANAT SERVER DOCKER | +--------------------------+ Version: \$(cat /home/gameserver/version.txt) IP:\$(hostname -i) WEB : http://\$(hostname -i)/ SSH : ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no gameserver@\$(hostname -i) +------------+----------+-------------------+ | Account | Password | Where | +------------+----------+-------------------+ | gameserver | khanat | ssh/terminal | | root | | mysql/phpmyadmin | | admin | admin | khaganat (admin) | | tester | tester | khaganat (player) | +------------+----------+-------------------+ Use 'sudo bash' to connect on root (ssh/terminal) ----------------------------------------- SCREEN -------- +A+N : next windows +A+P : previous windows +A+0 : windows 0 (terminal) +A+1 : windows 1 (AES) ----------------------------------------- To launch server : go to windows AES and ENTER ----------------------------------------- ENDOFCOMMENT 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 DOCKER * ************************ +------------+----------+-------------------+ | Account | Password | Where | +------------+----------+-------------------+ | gameserver | khanat | ssh/terminal | +------------+----------+-------------------+ EOF # After Login msg_debug "Configure banner" cat << EOF > /etc/motd *************************************************** EOF # After Login and on gameserver (can use bash and other command) # Bash_profile cat << EOF > /home/gameserver/.bash_profile cat << ENDOFCOMMENT +--------------------------+ | KHANAT SERVER DOCKER | +--------------------------+ Version: \$(cat /home/gameserver/version.txt) IP:\$(hostname -i) WEB : http://\$(hostname -i)/ SSH : ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no gameserver@\$(hostname -i) +------------+----------+-------------------+ | Account | Password | Where | +------------+----------+-------------------+ | gameserver | khanat | ssh/terminal | | root | | mysql/phpmyadmin | | admin | admin | khaganat (admin) | | tester | tester | khaganat (player) | +------------+----------+-------------------+ Use 'sudo bash' to connect on root (ssh/terminal) --------------------------------------------------- log khanat server : /home/gameserver/khanat/server/log/log.log *************************************************** ENDOFCOMMENT EOF chown gameserver:gameserver /home/gameserver/.bash_profile # Activate banner msg_debug "Activate banner" sed -i 's/^[#]*[[:space:]]*Banner.*$/Banner \/etc\/issue.net/g' /etc/ssh/sshd_config # Define default version (empty) touch /home/gameserver/version.txt chown gameserver:gameserver /home/gameserver/version.txt chmod uga+wr /home/gameserver/version.txt # Initialize ssh /etc/init.d/ssh restart #################################### # End #################################### msg_info "$(basename $0) => END"