khanat-server-docker-NeL/server/debian/common/serverimage_initialize_patch_server.sh

218 lines
6.9 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
#
# install / compile data / configure patch server
# 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/>.
echo "INITIALIZE PATCH SERVER"
#######################
# GET ENVIRONMENT
#######################
source /etc/apache2/envvars
export KHANAT_CLIENT_VERSION=1
if [[ ! -f /home/gameserver/.bashrc ]]
then
echo "ERROR - missing /home/gameserver/.bashrc"
exit 2
fi
# load environment
source /home/gameserver/.bashrc
# Load
if [[ -f /opt/khanat_config.sh ]]
then
echo "Configuration loaded"
source /opt/khanat_config.sh
echo "KHANAT_CLIENT_VERSION:$KHANAT_CLIENT_VERSION"
fi
#
# Serveur Patch
# Account use : gameserver
# Generate data to client
echo "PATCH - CREATE DIRECTORY"
echo "PATCH_HOME:$PATCH_HOME"
echo "PATCH_CLIENT_SYSTEM:$PATCH_CLIENT_SYSTEM"
mkdir -p $PATCH_HOME/patch_service/dataserver || exit 2
# Search le nombre de langue
listlang=$(ls $KHANAT_DATA/translation/translated | cut -f 1 -d '.' | sed 's/^.*\(.\{2\}\)$/\1/' | sort | uniq)
echo "LIST LANG : $listlang"
for lang in $listlang
do
echo "create dir : $PATCH_HOME/patch_service/dataserver/kh_translate_$lang"
mkdir -p $PATCH_HOME/patch_service/dataserver/kh_translate_$lang || exit 2
done
mkdir -p $PATCH_HOME/patch_service/kh_server || exit 2
mkdir -p $PATCH_HOME/patch_service/dataserver || exit 2
mkdir -p $PATCH_CLIENT_SYSTEM/patch_game/bnp/
echo "COPY DATA TO GENERATE PATCH"
cp $KHANAT_PATH/common/data_common/database.xml $PATCH_CLIENT_SYSTEM/kh_server/ || exit 2
cp $KHANAT_PATH/common/data_common/msg.xml $PATCH_CLIENT_SYSTEM/kh_server/ || exit 2
cp /opt/sheets_packer/client/data/*.packed_sheets $PATCH_CLIENT_SYSTEM/kh_server/ || exit 2
cp /opt/sheets_packer/client/data/*.packed $PATCH_CLIENT_SYSTEM/kh_server/ || exit 2
cp $KHANAT_PATH/common/data_common/visual_slot.tab $PATCH_CLIENT_SYSTEM/kh_server/ || exit 2
cp $KHANAT_DATA/leveldesign/game_elem/sheet_id.bin $PATCH_CLIENT_SYSTEM/kh_server/ || exit 2
cd $PATCH_HOME/patch_service/dataserver; tar xzf /opt/khanat-client-data.tar.gz || exit 2
# language : copy to client (to generate client patch)
for lang in $listlang
do
cp $KHANAT_DATA/translation/translated/*$lang.* $PATCH_CLIENT_SYSTEM/dataserver/kh_translate_$lang/ || exit 2
done
echo "GENERATE PATCH"
for lang in $listlang
do
cd $PATCH_CLIENT_SYSTEM/dataserver/; bnp_make -p kh_translate_$lang || exit 2
done
# tous les bnp de khanat-client-data
cd $PATCH_HOME/patch_service/dataserver/data/; bnp_make -p fonts || exit 2
for dir in $PATCH_HOME/patch_service/dataserver/data/kh/*
do
cd $dir/..; bnp_make -p $(basename $dir) || exit 2
done
for dir in $PATCH_HOME/patch_service/dataserver/data/kh_shard/*
do
cd $dir/..; bnp_make -p $(basename $dir) || exit 2
done
for dir in $PATCH_HOME/patch_service/dataserver/data/ryz/*
do
cd $dir/..; bnp_make -p $(basename $dir) || exit 2
done
## TODO - check how generate '.ref' files
for dir in $PATCH_HOME/patch_service/dataserver/client/*
do
cd $dir/..; bnp_make -p $(basename $dir) || exit 2
done
for file in $PATCH_HOME/patch_service/dataserver/client/*.bnp
do
mv "$file" "${file%.bnp}_.ref" || exit 2
done
# kh_server
cd $PATCH_CLIENT_SYSTEM/; bnp_make -p kh_server || exit 2
echo "MOVE PATCH"
for file in $PATCH_HOME/patch_service/dataserver/client/*.ref
do
mv "$file" $PATCH_CLIENT_SYSTEM/patch_game/bnp/ || exit 2
done
for file in $PATCH_HOME/patch_service/dataserver/data/kh/*.bnp
do
mv "$file" $PATCH_CLIENT_SYSTEM/patch_game/bnp/ || exit 2
done
#for file in $PATCH_HOME/patch_service/dataserver/data/kh_shard/*.bnp
#do
# mv "$file" $PATCH_CLIENT_SYSTEM/patch_game/bnp/ || exit 2
#done
for file in $PATCH_HOME/patch_service/dataserver/data/ryz/*.bnp
do
mv "$file" $PATCH_CLIENT_SYSTEM/patch_game/bnp/ || exit 2
done
for lang in $listlang
do
mv $PATCH_CLIENT_SYSTEM/dataserver/kh_translate_$lang.bnp $PATCH_CLIENT_SYSTEM/patch_game/bnp/ || exit 2
done
mv kh_server.bnp $PATCH_CLIENT_SYSTEM/patch_game/bnp/ || exit 2
chown -R gameserver:$APACHE_RUN_GROUP $PATCH_HOME/patch_service || exit 2
echo "PREPARE PATCH"
#
su -c "cd $PATCH_HOME/patch_service; patch_gen createNewProduct patch_game/ryzom.xml" gameserver || exit 2
su -c "cd $PATCH_HOME/patch_service;touch patch_game/Lirria.version" gameserver || exit 2
sed -i -r 's/value="main"/value="khanat_lirria"/g' patch_game/ryzom.xml || exit 2
sed -i -r 's/_NextVersionFile type="STRING" value=""/_NextVersionFile type="STRING" value="patch_game\/Lirria.version"/g' patch_game/ryzom.xml || exit 2
# Edit RYZOM file
# search all ref files
ADDREF=""
for file in /home/gameserver/patch_service/patch_game/bnp/*.ref
do
ADDREF="$ADDREF"'<_Files type=\"STRING\" value=\"'$(basename $file)'\"/>'
done
# Remove other _Category (keep 1st) and add ref file
cp patch_game/ryzom.xml patch_game/ryzom.xml.ref || exit 2
awk 'BEGIN{found=0}{
if(found==0 && $1 == "<_Category>") {
found = 1;
} else if(found == 1 && $1 == "</_Category>") {
found = 2;
print "'"$ADDREF"'";
print $0;
} else if(found == 2 && $1 == "</_Categories>") {
found = 3;
}
if ( found != 2 ) {
print $0
}
}' patch_game/ryzom.xml.ref > patch_game/ryzom.xml || exit 2
# Force version release
if [[ $KHANAT_CLIENT_VERSION -gt 1 ]]
then
# rm $PATCH_HOME/patch_service/patch_game/ryzom.hist
# rm $PATCH_HOME/patch_service/patch_game/ref/*
echo -n "$KHANAT_CLIENT_VERSION" > $PATCH_HOME/patch_service/patch_game/Lirria.version
fi
# Generate patch
su -c "cd $PATCH_HOME/patch_service; patch_gen updateProduct patch_game/ryzom.xml" gameserver || exit 2
# Edit release note
cat << EOF > $PATCH_HOME/patch_service/patch_game/patch/index.php
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>New test data - Release $KHANAT_CLIENT_VERSION</h1>
<p>An update will now be performed to your client(the /user directory to be exact).
Please help us test the deployment of our free MMORPG server!!
</body>
</html>
EOF
chown gameserver:$APACHE_RUN_GROUP $PATCH_HOME/patch_service/patch_game/patch/index.php
# TODO - Strange, we need update patch - to be check
cat << EOF > $PATCH_HOME/patch_service/patch_game/patch/Lirria.version
$KHANAT_CLIENT_VERSION $KHANAT_CLIENT_VERSION
EOF
# configure right (apache can read files)
chown -R gameserver:$APACHE_RUN_GROUP $PATCH_HOME/patch_service
chmod g+w -R $PATCH_HOME/patch_service