2017-11-21 21:10:28 +00:00
#!/bin/bash
#
# Configure MySQL
# 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/>.
declare DEBUG = 0
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/ext/servercontainer_function.sh
2017-11-22 20:13:50 +00:00
msg_info " [ $( basename $0 ) : $LINENO ] => START "
2017-11-21 21:10:28 +00:00
while test $# -gt 0
do
case " $1 " in
-h| --help)
usage
exit 1
; ;
-d| --debug)
DEBUG = 1
shift
; ;
*)
msg_error " options ' $1 ' not recognize "
usage
exit 1
; ;
esac
done
####################################
# Load Environment
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Load environment "
2017-11-21 21:10:28 +00:00
if [ [ ! -f /opt/khanat_config.sh ] ]
then
2018-04-22 19:12:51 +00:00
msg_critical " [ $( basename $0 ) : $LINENO ] missing /opt/khanat_config.sh "
2017-11-21 21:10:28 +00:00
fi
source /opt/khanat_config.sh
if [ [ ! -f /home/gameserver/.bashrc ] ]
then
2018-04-22 19:12:51 +00:00
msg_critical " [ $( basename $0 ) : $LINENO ] Missing /home/gameserver/.bashrc "
2017-11-21 21:10:28 +00:00
fi
source /home/gameserver/.bashrc
####################################
# Start mysql & apache
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Start mysql "
2017-11-21 21:10:28 +00:00
# start/restart service mysql & apache
sudo service mysql start || exit 2
# Wait mysql start
2017-11-22 20:13:50 +00:00
msg_info " [ $( basename $0 ) : $LINENO ] Check database is started "
2017-11-21 21:10:28 +00:00
sleep 1
until sudo /usr/bin/mysqladmin ping >/dev/null 2>& 1
do
echo -n "."
sleep 1
done
echo ""
sleep 1
msg_debug "start apache"
2018-04-22 19:12:51 +00:00
sudo service apache2 start || msg_critical " [ $( basename $0 ) : $LINENO ] Impossible to start apache "
2017-11-21 21:10:28 +00:00
####################################
# Create account
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Create account "
2017-11-21 21:10:28 +00:00
# Create account shard on MySQL
2018-04-22 19:12:51 +00:00
mysql -u root -e "CREATE USER IF NOT EXISTS 'shard'@'localhost' IDENTIFIED BY '';" || msg_critical " [ $( basename $0 ) : $LINENO ] create use impossible "
mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'shard'@'localhost' WITH GRANT OPTION;" || msg_critical " [ $( basename $0 ) : $LINENO ] update privileges impossible "
2017-11-21 21:10:28 +00:00
####################################
# launch web configuration for khanat
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] launch web configuration for khanat "
2018-04-22 19:12:51 +00:00
httpcode = $( curl -L -w "%{http_code}" 'http://localhost:40916/setup/install.php' \
2017-11-21 21:10:28 +00:00
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: en-US' \
-H 'Connection: keep-alive' \
-H 'Cookie: PHPSESSID=9jr1ssig58929bp777nrj2fa92' \
-H 'DNT: 1' \
-H 'Host: localhost:40916' \
-H 'Referer: http://localhost:40916/setup/install.php' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20100101 Firefox/6.0' \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data 'roleService=on' \
'&roleSupport=on' \
'&roleDomain=on' \
'&privatePhpDirectory=..%2Fprivate_php%2F' \
'&nelSetupPassword=admin' \
'&nelSqlHostname=localhost' \
'&nelSqlUsername=root' \
'&nelSqlPassword=' \
'&nelDatabase=nel' \
'&toolDatabase=nel_tool' \
'&toolsAdminUsername=admin' \
'&toolsAdminPassword=admin' \
'&amsSqlHostname=localhost' \
'&amsSqlUsername=root' \
'&amsSqlPassword=' \
'&amsDatabase=nel_ams' \
'&amsLibDatabase=nel_ams_lib' \
'&amsAdminUsername=admin' \
'&amsAdminPassword=admin' \
'&nelDomainName=Lirria' \
'&domainDatabase=ring_mini01' \
'&submit=Configure' \
2018-04-22 19:12:51 +00:00
-o $KHANAT_HOME /log/configure/world_setup.html || msg_critical " [ $( basename $0 ) : $LINENO ] curl error (impossible to create world) " )
if [ [ $httpcode != "200" ] ]
then
msg_critical " [ $( basename $0 ) : $LINENO ] impossible to create world (http return: $httpcode ) "
fi
2017-11-21 21:10:28 +00:00
chown_gameserver $KHANAT_HOME /log/configure/world_setup.html
# Check account is create
2018-04-22 19:12:51 +00:00
grep "Domain role successfully installed" $KHANAT_HOME /log/configure/world_setup.html >/dev/null || msg_critical " [ $( basename $0 ) : $LINENO ] Missing message 'Domain role successfully installed' "
2017-11-21 21:10:28 +00:00
####################################
# Get IP ADDRESS
####################################
msg_debug "Get IP ADDRESS"
tmp = $( hostname -I)
export addressip = ${ tmp //[[ : blank : ]]/ }
####################################
## Configure Domain
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Configure Domain "
2017-11-21 21:10:28 +00:00
mysql -u root -e " use nel;
2018-04-22 19:12:51 +00:00
INSERT INTO nel.domain ( domain_id, domain_name, status, patch_version, backup_patch_url, patch_urls, login_address, session_manager_address, ring_db_name, web_host, web_host_php, description) VALUES ( '12' , 'Lirria' , 'ds_open' , '$KHANAT_CLIENT_VERSION' , '$addressip:23001' , '$addressip/patch' , '$addressip:49998' , '$addressip:49999' , 'ring_mini01' , '$addressip:30000' , '$addressip:40916' , NULL) ; " || msg_critical " [ $( basename $0 ) :$LINENO ] MYSQL - Configure Domain"
2017-11-21 21:10:28 +00:00
####################################
# Configure nel.shard
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Configure nel.shard "
2017-11-21 21:10:28 +00:00
mysql -u root -e " use nel;
2018-04-22 19:12:51 +00:00
INSERT INTO nel.shard ( ShardId, domain_id, WsAddr, NbPlayers, Name, Online, Version, FixedSessionId, State, MOTD) VALUES ( '302' , '12' , '$addressip:' , '0' , 'Lirria shard' , '0' , '' , '0' , 'ds_open' , '' ) ; " || msg_critical " [ $( basename $0 ) :$LINENO ] MYSQL - Configure nel.shard"
2017-11-21 21:10:28 +00:00
####################################
# Configure nel_tool.neltool_domains
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Configure nel_tool.neltool_domains "
2017-11-21 21:10:28 +00:00
mysql -u root -e " use nel;
2018-04-22 19:12:51 +00:00
INSERT INTO nel_tool.neltool_domains ( domain_id, domain_name, domain_as_host, domain_as_port, domain_rrd_path, domain_las_admin_path, domain_las_local_path, domain_application, domain_sql_string, domain_hd_check, domain_mfs_web, domain_cs_sql_string) VALUES ( '12' , 'Lirria' , '$addressip' , '46700' , '/home/gameserver/khanat/server/save_shard/rrd_graphs' , '' , '' , 'ryzom_open' , '' , '0' , NULL, NULL) ; " || msg_critical " [ $( basename $0 ) :$LINENO ] MYSQL - Configure nel_tool.neltool_domains"
2017-11-21 21:10:28 +00:00
####################################
# configure nel_tool.neltool_shards
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Configure nel_tool.neltool_shards "
2017-11-21 21:10:28 +00:00
mysql -u root -e " use nel;
2018-04-22 19:12:51 +00:00
INSERT INTO nel_tool.neltool_shards ( shard_id, shard_name, shard_as_id, shard_domain_id, shard_lang, shard_restart) VALUES ( '302' , 'open' , 'open' , '12' , 'fr' , '0' ) ; " || msg_critical " [ $( basename $0 ) :$LINENO ] MYSQL - Configure nel_tool.neltool_shards"
2017-11-21 21:10:28 +00:00
####################################
# configure nel_tool.neltool_user_domains
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Configure nel_tool.neltool_user_domains "
2017-11-21 21:10:28 +00:00
mysql -u root -e " use nel;
2018-04-22 19:12:51 +00:00
INSERT INTO nel_tool.neltool_user_domains ( user_domain_id, user_domain_user_id, user_domain_domain_id) VALUES ( '1' , '1' , '12' ) ; " || msg_critical " [ $( basename $0 ) :$LINENO ] MYSQL - Configure nel_tool.neltool_user_domains"
2017-11-21 21:10:28 +00:00
####################################
# configure nel_tool.neltool_user_shards
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Configure nel_tool.neltool_user_shards "
2017-11-21 21:10:28 +00:00
mysql -u root -e " use nel;
2018-04-22 19:12:51 +00:00
INSERT INTO nel_tool.neltool_user_shards ( user_shard_id, user_shard_user_id, user_shard_shard_id, user_shard_domain_id) VALUES ( '1' , '1' , '302' , '12' ) ; " || msg_critical " [ $( basename $0 ) :$LINENO ] MYSQL - Configure nel_tool.neltool_user_shards"
2017-11-21 21:10:28 +00:00
####################################
# configure ring_mini01.sessions
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Configure ring_mini01.sessions "
2017-11-21 21:10:28 +00:00
mysql -u root -e " use ring_mini01;
2018-04-22 19:12:51 +00:00
INSERT INTO ring_mini01.sessions ( session_id, session_type, title, owner, plan_date, start_date, description, orientation, level, rule_type, access_type, state, host_shard_id, subscription_slots, reserved_slots, free_slots, estimated_duration, final_duration, folder_id, lang, icone, anim_mode, race_filter, religion_filter, guild_filter, shard_filter, level_filter, subscription_closed, newcomer) VALUES ( '302' , 'st_mainland' , '' , '0' , '2005-09-21 12:41:33.000000' , '2005-08-31 00:00:00.000000' , '' , 'so_other' , 'sl_a' , 'rt_strict' , 'at_private' , 'ss_planned' , '0' , '0' , '0' , '0' , 'et_short' , '0' , '0' , '' , '' , 'am_dm' , '' , '' , 'gf_only_my_guild' , 'sf_shard00,sf_shard01,sf_shard02,sf_shard03,sf_shard04,sf_shard05,sf_shard06,sf_shard07,sf_shard08,sf_shard09,sf_shard10,sf_shard11,sf_shard12,sf_shard13,sf_shard14,sf_shard15,sf_shard16,sf_shard17,sf_shard18,sf_shard19,sf_shard20,sf_shard21,sf_shard22,sf_shard23,sf_shard24,sf_shard25,sf_shard26,sf_shard27,sf_shard28,sf_shard29,sf_shard30' , 'lf_a,lf_b,lf_c,lf_d,lf_e,lf_f' , '0' , '0' ) ; " || msg_critical " [ $( basename $0 ) :$LINENO ] MYSQL - Configure ring_mini01.sessions"
2017-11-21 21:10:28 +00:00
####################################
## Create one user 'tester' (password : tester)
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Create one user "
2017-11-21 21:10:28 +00:00
declare accountuser = "tester"
declare passworduser = "tester"
2018-04-22 19:12:51 +00:00
httpcode = $( curl -L -w "%{http_code}" 'http://localhost:40916/ams/index.php' \
2017-11-21 21:10:28 +00:00
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: en-US' \
-H 'Connection: keep-alive' \
-H 'Cookie: PHPSESSID=lsoumn9f0ljgm3vo3hgjdead03' \
-H 'DNT: 1' \
-H 'Host: localhost:40916' \
-H 'Referer: http://localhost:40916/ams/index.php?page=register' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20100101 Firefox/6.0' \
-H 'Content-Type: application/x-www-form-urlencoded' \
2018-04-30 18:34:08 +00:00
--data 'Username=' " $accountuser " '&Password=' " $passworduser " '&ConfirmPass=' " $passworduser " '&Email=tester%40khaganat.net&TaC=on&function=add_user' \
2018-04-22 19:12:51 +00:00
-o $KHANAT_HOME /log/configure/world_account_tester.log || msg_critical " [ $( basename $0 ) : $LINENO ] curl - Create one user " )
if [ [ $httpcode != "200" ] ]
then
msg_critical " [ $( basename $0 ) : $LINENO ] curl - Create one user "
fi
2017-11-21 21:10:28 +00:00
####################################
# configure nel.permission
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Create nel.permission "
2017-11-21 21:10:28 +00:00
mysql -u root -e " use nel;
UPDATE nel.permission SET AccessPrivilege = 'OPEN,DEV,RESTRICTED' ;
2018-04-22 19:12:51 +00:00
" || msg_critical " [ $( basename $0 ) :$LINENO ] mysql - Create nel.permission"
2017-11-21 21:10:28 +00:00
####################################
# Stop Database & apache
####################################
2017-11-22 20:13:50 +00:00
msg_debug " [ $( basename $0 ) : $LINENO ] Stop Database & apache "
2017-11-21 21:10:28 +00:00
# start/restart service mysql & apache
2018-04-22 19:12:51 +00:00
sudo service apache2 stop || msg_critical " [ $( basename $0 ) : $LINENO ] apache2 stop "
sudo service mysql stop || msg_critical " [ $( basename $0 ) : $LINENO ] mysql stop "
2017-11-21 21:10:28 +00:00
# Change right for file mysql
# TODO - remove creation of this file
chown_gameserver " $KHANAT_HOME /database/mysql_upgrade_info "
####################################
# End
####################################
2017-11-22 20:13:50 +00:00
msg_info " [ $( basename $0 ) : $LINENO ] => END "
2017-11-21 21:10:28 +00:00