#!/bin/bash
# /opt/dist/docker/server/init-khanat.sh
# install new package
cd /; tar xzf /opt/ryzomcore.tar.gz --strip 1 || exit 2
cd /opt; tar xzf ryzom-ressources.tar.gz || exit 2
# configure environment
cat << EOF > /opt/shard.sh
export RYHOME=/home/compil
export RYZOM_PATH=/home/compil/ryzom
export PATH=$PATH:/usr/local/bin:$RYZOM_PATH/tools/scripts/linux
export RYDATA=/home/compil/khanat-ressources
echo "Environment loaded"
EOF
# configure environment
cat << EOF > /home/compil/.bashrc
export RYHOME=/home/compil
export RYZOM_PATH=/home/compil/ryzom
export PATH=$PATH:/usr/local/bin:$RYZOM_PATH/tools/scripts/linux
export RYDATA=/home/compil/khanat-ressources
echo "Environment loaded"
EOF
# load environment
source /opt/shard.sh
if [[ -f /opt/khanat_config.sh ]]
then
echo "Configuration loaded"
source /opt/khanat_config.sh
echo "KHANAT_CLIENT_VERSION:$KHANAT_CLIENT_VERSION"
fi
mkdir -p $RYHOME $RYZOM_PATH $PATH || exit 2
mkdir -p $RYDATA/ressources
(cd $RYDATA; tar xzf /opt/khanat-ressources.tar.gz) || exit 2
#cp -r /opt/ressources $RYDATA || exit 2
mkdir -p $RYZOM_PATH/tools/scripts/linux
cp -r /opt/code/ryzom/tools/scripts/linux/* $RYZOM_PATH/tools/scripts/linux || exit 2
# configure ryzom
mkdir -p $RYZOM_PATH/server || exit 2
cp -r /opt/code/ryzom/common/ $RYZOM_PATH/common || exit 2
cp -r /opt/code/ryzom/client/ $RYZOM_PATH/client || exit 2
cp /opt/code/ryzom/server/*.cfg $RYZOM_PATH/server/. || exit 2
sed -i -r 's/(FSListenHost)(.*)(=)(.*)(;)/FSListenHost = "localhost";/g' $RYZOM_PATH/server/frontend_service.cfg || exit 2
sed -i -r 's/(DBHost)(.*)(=)(.*)(;)/DBHost = "localhost";/g' $RYZOM_PATH/server/sql.cfg || exit 2
sed -i -r 's/(DBRingName)(.*)(=)(.*)(;)/ DBRingName = "ring_mini01";/g' $RYZOM_PATH/server/sql.cfg || exit 2
# install web ryzom
cp -r /opt/code/web $RYZOM_PATH/ryzomweb || exit 2
chmod -R a+w $RYZOM_PATH/ryzomweb || exit 2
chown -R www-data:www-data $RYZOM_PATH/ryzomweb || exit 2
# configure apache
cat << EOF > /etc/apache2/sites-available/000-default.conf
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
DirectoryIndex index.php
AddType text/html .php .phps
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps
ServerName lirria.khaganat.net
ServerAdmin webmaster@localhost
DocumentRoot $RYZOM_PATH/ryzomweb/public_php/
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
ServerName lirria.khaganat.net
ServerAdmin admin@localhost
DocumentRoot $RYZOM_PATH/ryzomweb/public_php
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
EOF
cat << EOF > /etc/apache2/ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80
Listen 40916
Listen 443
Listen 443
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EOF
# start/restart service mysql & apache
service mysql restart || exit 2
service apache2 restart || exit 2
mysql -u root -e "CREATE USER 'shard'@'localhost' IDENTIFIED BY '';" || exit 2
mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'shard'@'localhost' WITH GRANT OPTION;" || exit 2
## DATABASE
# launch web configuration for ryzom
# -H 'Accept-Encoding: gzip, deflate'
curl 'http://localhost:40916/setup/install.php' \
-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' \
-o /opt/setup.log || exit 2
grep "Domain role successfully installed" /opt/setup.log >/dev/null || exit 2
# configure domain
tmp=$(hostname -I)
export addressip=${tmp//[[:blank:]]/}
mysql -u root -e "use nel;
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);" || exit 2
mysql -u root -e "use nel;
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', '');" || exit 2
mysql -u root -e "use nel;
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/compil/ryzom/server/save_shard/rrd_graphs', '', '', 'ryzom_open', '', '0', NULL, NULL);" || exit 2
mysql -u root -e "use nel;
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');" || exit 2
mysql -u root -e "use nel;
INSERT INTO nel_tool.neltool_user_domains (user_domain_id, user_domain_user_id, user_domain_domain_id) VALUES ('1', '1', '12');" || exit 2
mysql -u root -e "use nel;
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');" || exit 2
mysql -u root -e "use ring_mini01;
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');" || exit 2
## Create an user
# tester / tester
curl 'http://localhost:40916/ams/index.php' \
-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' \
--data 'Username=tester&Password=tester&ConfirmPass=tester&Email=tester%40get2mail.fr&TaC=on&function=add_user' \
-o /opt/account_tester.log || exit 2
mysql -u root -e "use nel;
UPDATE nel.permission SET AccessPrivilege = 'OPEN,DEV,RESTRICTED';
" || exit 2
###
# create link resource
# Les dossiers :
ln -s $RYDATA/collisions $RYZOM_PATH/server/
ln -s $RYDATA/leveldesign $RYZOM_PATH/server/
ln -s $RYDATA/primitives $RYZOM_PATH/server/
ln -s $RYDATA/translation $RYZOM_PATH/server/
ln -s $RYDATA/continents $RYZOM_PATH/server/
ln -s $RYDATA/common $RYZOM_PATH/server/
# Les fichiers :
mkdir -p $RYZOM_PATH/server/data_shard
cp -r /opt/code/ryzom/server/data_shard/* $RYZOM_PATH/server/data_shard/.
ln -s $RYDATA/shard/su/dev_gm_names.xml $RYZOM_PATH/server/data_shard/dev_gm_names.xml
ln -s $RYDATA/shard/su/invalid_entity_names.txt $RYZOM_PATH/server/data_shard/invalid_entity_names.txt
ln -s $RYDATA/shard/su/reserved_names.xml $RYZOM_PATH/server/data_shard/reserved_names.xml
ln -s $RYDATA/shard/egs/game_event.txt $RYZOM_PATH/server/data_shard/game_event.txt
ln -s $RYDATA/shard/egs/mission_queues.txt $RYZOM_PATH/server/data_shard/mission_queues.txt
ln -s $RYDATA/shard/egs/named_items.txt $RYZOM_PATH/server/data_shard/named_items.txt
mkdir -p $RYDATA/mirror_sheets
cp -r /opt/code/ryzom/server/data_shard/mirror_sheets/* $RYDATA/mirror_sheets
cd /usr/local; /usr/local/bin/make_sheet_id \
-c/usr/local/etc/nel/make_sheet_id.cfg \
-o$RYDATA/leveldesign/game_elem/sheet_id.bin \
$RYDATA/leveldesign/game_elem \
$RYDATA/leveldesign/game_element \
$RYDATA/leveldesign/world \
$RYDATA/leveldesign/ecosystems \
$RYDATA/sound \
$RYDATA/mirror_sheets || exit 2
rm -rf /opt/sheets_packer/*
mkdir -p /opt/sheets_packer/common /opt/sheets_packer/khanat-ressources /opt/sheets_packer/client
cat << EOF > /opt/sheets_packer/sheets_packer.cfg
/////////////////////////////////
/////////////////////////////////
/// SHEETS PACKER CONFIG FILE ///
/////////////////////////////////
/////////////////////////////////
DataPath = { "/opt/sheets_packer/common/data_leveldesign",
"/opt/sheets_packer/common/data_common",
"/opt/sheets_packer/client/data",
"/opt/sheets_packer/khanat-ressources/common",
"/opt/sheets_packer/khanat-ressources/leveldesign",
"/opt/sheets_packer/khanat-ressources/primitives" };
WorldSheet = "ryzom.world";
PrimitivesPath = "/opt/sheets_packer/khanat-ressources/primitives";
OutputDataPath = "/opt/sheets_packer/client/data";
LigoPrimitiveClass = "world_editor_classes.xml";
DumpVisualSlotsIndex = 1;
EOF
cp -r /opt/code/ryzom/common/* /opt/sheets_packer/common || exit 2
cp -r $RYDATA/* /opt/sheets_packer/khanat-ressources || exit 2
cp -r /opt/code/ryzom/client/* /opt/sheets_packer/client || exit 2
cd /opt/sheets_packer; sheets_packer 1>/opt/sheets_packer/sheets_packer.log 2>/opt/sheets_packer/sheets_packer.err || exit 2
cp /opt/sheets_packer/visual_slot.tab $RYZOM_PATH/common/data_common/visual_slot.tab || exit 2
cp /opt/sheets_packer/visual_slot.tab $RYZOM_PATH/client/data/visual_slot.tab || exit 2
for var in $RYDATA/translation/translated/*_en.txt; do nomfic=${var##*/}; ln -s $nomfic ${var%/*}/${nomfic/_en/_de}; done
for var in $RYDATA/translation/translated/*_en.txt; do nomfic=${var##*/}; ln -s $nomfic ${var%/*}/${nomfic/_en/_es}; done
for var in $RYDATA/translation/translated/*_wk.txt; do nomfic=${var##*/}; ln -s $nomfic ${var%/*}/${nomfic/_wk/_ru}; done
cp /opt/code/ryzom/server/shard.screen.rc $RYZOM_PATH/server/shard.screen.rc
ln -s /usr/local /home/compil/build
/etc/init.d/ssh restart
cp /usr/local/sbin/* /usr/local/bin
cat << EOF
source /opt/shard.sh
/home/compil/ryzom/tools/scripts/linux/shard
EOF
cat << EOF > /opt/autostart.sh
#!/bin/bash
/etc/init.d/mysql restart
/etc/init.d/apache2 restart
/etc/init.d/ssh restart
source /opt/shard.sh
tmp=\$(hostname -I)
export addressip=\${tmp//[[:blank:]]/}
sed -i -r 's/(FSListenHost)(.*)(=)(.*)(;)/FSListenHost = "'"\$addressip"'";/g' \$RYZOM_PATH/server/frontend_service.cfg || exit 2
/home/compil/ryzom/tools/scripts/linux/shard start
EOF
chmod +x /opt/autostart.sh
mkdir -p $RYZOM_PATH/server/save_shard/rrd_graphs
## See on https://ryzomcore.atlassian.net/wiki/display/RC/Configure+Linux+Web+Services
#mkdir -p $RYZOM_PATH/tools/server/admin/graphs_output
#mkdir -p $RYZOM_PATH/tools/server/admin/templates/default_c
#mkdir -p $RYZOM_PATH/tools/server/www/login/logs
#mkdir -p $RYZOM_PATH/tools/server/ryzom_ams/www/
#mkdir -p $RYZOM_PATH/tools/server/ryzom_ams/www/html/cache
#mkdir -p $RYZOM_PATH/tools/server/ryzom_ams/www/html/templates_c
#shard
#
# Serveur Patch
# TODO - need add other step to initialize patch server
# Account use : gameserver
su -c "mkdir -p /home/gameserver/patch_service/" gameserver || exit 2
su -c "cd /home/gameserver/patch_service; patch_gen createNewProduct patch_game/ryzom.xml" gameserver || exit 2
#
# Stop All
#
service ssh stop || exit 2
service apache2 stop|| exit 2
service mysql stop || exit 2