Browse Source

working on updater script

master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
4691eea36c
  1. 2
      README.md
  2. 31
      chunkymap-regen.py
  3. 111
      chunkymap.php
  4. 11
      index-example.php
  5. 12
      install-chunkymap-on-ubuntu-from-web.sh
  6. 11
      install-chunkymap-on-ubuntu.sh
  7. 13
      update-chunkymap-installer-only.sh
  8. 18
      update-chunkymap-on-ubuntu-from-web.sh

2
README.md

@ -18,7 +18,7 @@ This program comes without any warranty, to the extent permitted by applicable l
* Install the git version of minetest (or otherwise install 0.4.13 or other version compatible with the map generators used by chunkymap) * Install the git version of minetest (or otherwise install 0.4.13 or other version compatible with the map generators used by chunkymap)
OPTION 2: IF you are using Ubuntu go to a terminal, cd to this folder, OPTION 2: IF you are using Ubuntu go to a terminal, cd to this folder,
then switch user to the one that will run minetestserver then switch user to the one that will run minetestserver
(since install-chunkymap-on-ubuntu.sh DOES replace "/home/owner" with current user's home in all chunkymap scripts in destination folder) (since install-chunkymap-on-ubuntu.sh DOES replace "/home/owner" with current user's home [replace-with-current-user.py, which is automatically called by install, will change /home/owner to current user's folder in each script that install copies to $HOME/minetest/util])
then go to Terminal and run: then go to Terminal and run:
`minetestserver` `minetestserver`
then when it is finished loading, press Ctrl C then run: then when it is finished loading, press Ctrl C then run:

31
chunkymap-regen.py

@ -93,11 +93,11 @@ is_save_output_ok = True
def get_dict_from_conf_file(path,assignment_operator="="): def get_dict_from_conf_file(path,assignment_operator="="):
results = None results = None
print "Checking "+str(path)+" for settings..."
if os.path.isfile(path): if os.path.isfile(path):
results = {} results = {}
ins = open(yaml_path, 'r') ins = open(path, 'r')
line = True line = True
operator = ":"
while line: while line:
line = ins.readline() line = ins.readline()
if line and len(line)>0: if line and len(line)>0:
@ -109,7 +109,7 @@ def get_dict_from_conf_file(path,assignment_operator="="):
if ao_index<len(line_strip)-1: # skip yaml implicit nulls or yaml objects if ao_index<len(line_strip)-1: # skip yaml implicit nulls or yaml objects
result_name = line_strip[:ao_index] result_name = line_strip[:ao_index]
result_value = line_strip[ao_index+1:] result_value = line_strip[ao_index+1:]
print " CHECKING MAP..."+result_name+":"+result_value print " CHECKING... "+result_name+":"+result_value
results[result_name]=result_value results[result_name]=result_value
ins.close() ins.close()
return results return results
@ -117,7 +117,7 @@ def get_dict_from_conf_file(path,assignment_operator="="):
if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
chunkymap_data_path=os.path.join(website_root,"chunkymapdata") chunkymap_data_path=os.path.join(website_root,"chunkymapdata")
yaml_name = "metadata.yml" yaml_name = "generated.yml"
yaml_path = os.path.join(chunkymap_data_path, yaml_name) yaml_path = os.path.join(chunkymap_data_path, yaml_name)
if not os.path.isdir(chunkymap_data_path): if not os.path.isdir(chunkymap_data_path):
os.mkdir(chunkymap_data_path) os.mkdir(chunkymap_data_path)
@ -142,12 +142,12 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
if line: if line:
ao_index = line.find("=") ao_index = line.find("=")
if ao_index > 0: if ao_index > 0:
ini_name = line[:ao_index].strip() found_name = line[:ao_index].strip()
ini_value = line[ao_index+1:].strip() found_value = line[ao_index+1:].strip()
if ini_name=="name": if found_name=="name":
player_name = ini_value player_name = found_value
elif ini_name=="position": elif found_name=="position":
player_position = ini_value player_position = found_value
if (player_name is not None) and (player_position is not None): if (player_name is not None) and (player_position is not None):
has_enough_data = True has_enough_data = True
break break
@ -155,6 +155,8 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
player_dest_path = os.path.join(chunkymap_players_path,filename+".yml") player_dest_path = os.path.join(chunkymap_players_path,filename+".yml")
if has_enough_data: if has_enough_data:
#if player_name!="singleplayer": #if player_name!="singleplayer":
map_player_dict = get_dict_from_conf_file(player_dest_path,":")
if (map_player_dict is None) or (map_player_dict["position"]!=player_position):
outs = open(player_dest_path, 'w') outs = open(player_dest_path, 'w')
outs.write("name:"+player_name+"\n") # python automatically uses correct newline for your os when you put "\n" outs.write("name:"+player_name+"\n") # python automatically uses correct newline for your os when you put "\n"
outs.write("position:"+player_position+"\n") outs.write("position:"+player_position+"\n")
@ -196,8 +198,8 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
total_generated_count = 0 total_generated_count = 0
#values for command arguments: #values for command arguments:
maxheight = 100 maxheight = 50
minheight = -50 minheight = -25
pixelspernode = 1 pixelspernode = 1
#ALSO save to YAML: #ALSO save to YAML:
#world_name #world_name
@ -233,6 +235,9 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
dest_png_path = os.path.join(chunkymap_data_path, png_name) dest_png_path = os.path.join(chunkymap_data_path, png_name)
dest_mapper_out_path = os.path.join(chunkymap_data_path, mapper_out_name) dest_mapper_out_path = os.path.join(chunkymap_data_path, mapper_out_name)
is_empty_chunk = False is_empty_chunk = False
if os.path.isfile(dest_mapper_out_path):
if os.path.isfile(dest_png_path):
os.remove(dest_mapper_out_path)
if os.path.isfile(dest_mapper_out_path): if os.path.isfile(dest_mapper_out_path):
ins = open(dest_mapper_out_path) ins = open(dest_mapper_out_path)
line = True line = True
@ -274,7 +279,7 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
if os.path.isfile(dest_png_path): if os.path.isfile(dest_png_path):
total_generated_count += 1 total_generated_count += 1
square_generates_count += 1 square_generates_count += 1
print("Skipping existing map tile " + png_name + " since not full_render") print("Skipping existing map tile file " + png_name + " (delete it to re-render)")
elif is_empty_chunk: elif is_empty_chunk:
print("Skipping empty chunk " + chunk_luid + " since not full_render") print("Skipping empty chunk " + chunk_luid + " since not full_render")
print "" # blank line before next z so output is human readable print "" # blank line before next z so output is human readable

111
chunkymap.php

@ -0,0 +1,111 @@
<?php
include_once('browser.php');
foreach($_REQUEST as $key => $value) {
//in case auto_globals is not enabled
$GLOBALS[$key]=$value;
}
date_default_timezone_set('EST'); //required by PHP >=5.1.0
$chunkymapdata_path = "chunkymapdata";
$showplayers=true;
function get_dict_from_conf($path, $assignment_operator) {
$handle = fopen($path, "r");
$result = null;
if ($handle) {
while (($line = fgets($handle)) !== false) {
$line_strip = trim($line);
if (strlen($line_strip)>0) {
if (substr($line_strip)!="#") {
$ao_index = strpos($line_strip, $assignment_operator);
if ($ao_index>0 and $ao_index<(strlen($line_strip)-1)) { //skip blank variable OR value
$found_name = substr($line_strip, 0, $ao_index);
$found_value_index = $ao_index + 1;
$found_value = substr($line_strip, $found_value_index, strlen($line_strip)-$found_value_index);
if ($result===null) {
$result = array();
}
$result[$found_name]=$found_value;
}
}
}
}
fclose($handle);
} else {
echo "<span style=\"color:read\">Failed to read $path</span> (run chunkymap-cronjob script as root first, otherwise see README.md in minetest-chunkymap to ensure installation is correct).<br/>";
}
return $result;
}//end get_dict_from_conf
$map_dict = get_dict_from_conf($chunkymapdata_path."/generated.yml";
//startsWith and endsWith are from:
//Salmon A. stackoverflow. <http://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php>. 5 Feb 2016. 19 Feb, 2016.
function startsWith($haystack, $needle) {
// search backwards starting from haystack length characters from the end
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
}
function endsWith($haystack, $needle) {
// search forward starting from end minus needle length characters
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false);
}
function echo_chunkymap_table($center_x, $center_z, $zoom_min_1_max_100) {
global $chunkymapdata_path;
global $map_dict;
if ($zoom_min_1_max_100<1) $zoom_min_1_max_100 = 1;
if ($zoom_min_1_max_100>100) $zoom_min_1_max_100 = 100;
$zoom_divisor = int(100/$zoom_min_1_max_100);
$chunk_assoc = array();
$chunk_count = 0;
$x_opener="chunk_x";
$z_opener="z";
$dot_and_ext = ".png";
$x = $map_dict["chunkx_min"];
$z = $map_dict["chunkz_min"];
$x_count = $map_dict["chunkx_max"] - $map_dict["chunkx_min"]
$z_count = $map_dict["chunkz_max"] - $map_dict["chunkz_min"]
echo "<table border=\"0\">";
while ($z <= $map_dict["chunkz_max"]) {
echo " <tr>";
while ($x <= $map_dict["chunkx_max"]) {
echo " <td>";
$chunk_luid = "x".$x."z".$z;
$chunk_img_name = $x_opener.$x.$z_opener.$z."$dot_and_ext";
$chunk_img_path = $chunkymapdata_path.'/'.$chunk_img_name;
if (is_file($chunk_img_path)) {
echo "<img src=\"$chunk_img_path\"/ style=\"width:$zoom_min_1_max_100%\">";
}
echo " <br/>".$x.",0,".$z
echo " </td>";
$x++;
}
echo " </tr>";
$z++;
}
echo "</table>";
//NOTE: no need to detect range since using $map_dict
/*
$x_max = 0;
$x_min = 0;
$z_min = 0;
$z_max = 0;
if ($handle = opendir($chunkymapdata_path)) {
while (false !== ($file = readdir($handle))) {
if (substr($file, 0, 1) != ".") {
$file_lower = strtolower($file);
if (endsWith($file_lower, $dot_and_ext) and startsWith($file_lower, $x_opener)) {
$z_opener_index = strpos($file_lower, $z_opener, strlen($x_opener));
if ($z_opener_index !== false) {
$x_len = $z_opener_index - strlen($x_opener);
$z_len = strlen($file_lower) - strlen($x_opener) - $x_len - strlen($z_opener) - $dot_and_ext;
$x = substr($file_lower, strlen($x_opener), $x_len);
$z = substr($file_lower, $z_opener_index + strlen($z_opener), $z_len);
}
}
}
}
}
*/
}
?>

11
index-example.php

@ -0,0 +1,11 @@
<html>
<title>Chunkymap Example Page</title>
<body>
Live Map:
<?php
include_once('chunkymap.php');
echo_chunkymap_table(0,0,25);
?>
<center><small>Powered by <a href="https://github.com/expertmm/minetest-chunkymap">Chunkymap</a></small></center>
</body>
</html>

12
install-chunkymap-on-ubuntu-from-web.sh

@ -1,10 +1,4 @@
#!/bin/sh #!/bin/sh
cd ~/minetest-stuff CHUNKYMAP_INSTALLER_DIR=~/minetest-stuff/minetest-chunkymap
rm master.zip ./update-chunkymap-installer-only.sh
wget https://github.com/expertmm/minetest-chunkymap/archive/master.zip sh $CHUNKYMAP_INSTALLER_DIR/install-chunkymap-on-ubuntu.sh
mv master.zip minetest-chunkymap.zip
unzip minetest-chunkymap.zip
mv minetest-chunkymap-master minetest-chunkymap
cd minetest-chunkymap
chmod +x install-chunkymap-on-ubuntu.sh
./install-chunkymap-on-ubuntu.sh

11
install-chunkymap-on-ubuntu.sh

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
CHUNKYMAP_INSTALLER_DIR=~/minetest-stuff/minetest-chunkymap
MINETEST_UTIL=$HOME/minetest/util MINETEST_UTIL=$HOME/minetest/util
CHUNKYMAP_DEST=$MINETEST_UTIL CHUNKYMAP_DEST=$MINETEST_UTIL
@ -8,15 +9,15 @@ sudo apt-get install python-numpy python-pil
#rm -f ~/minetestmapper-numpy.py #rm -f ~/minetestmapper-numpy.py
#wget https://github.com/spillz/minetest/raw/master/util/minetestmapper-numpy.py #wget https://github.com/spillz/minetest/raw/master/util/minetestmapper-numpy.py
#since colors.txt is in ~/minetest/util: #since colors.txt is in ~/minetest/util:
cp -f minetestmapper-numpy.py $HOME/minetest/util/minetestmapper-numpy.py cp -f "$CHUNKYMAP_INSTALLER_DIR/minetestmapper-numpy.py" "$HOME/minetest/util/minetestmapper-numpy.py"
mkdir "$CHUNKYMAP_DEST" mkdir "$CHUNKYMAP_DEST"
cp -f chunkymap-regen.py "$CHUNKYMAP_DEST/" cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen.py" "$CHUNKYMAP_DEST/"
#chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.py" #chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.py"
cp -f chunkymap-regen.sh "$CHUNKYMAP_DEST/" cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen.sh" "$CHUNKYMAP_DEST/"
chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.sh" chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.sh"
cp -f chunkymap-cronjob "$CHUNKYMAP_DEST/" cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-cronjob" "$CHUNKYMAP_DEST/"
chmod +x "$CHUNKYMAP_DEST/chunkymap-cronjob" chmod +x "$CHUNKYMAP_DEST/chunkymap-cronjob"
cp -f set-minutely-crontab-job.sh "$CHUNKYMAP_DEST/" cp -f "$CHUNKYMAP_INSTALLER_DIR/set-minutely-crontab-job.sh" "$CHUNKYMAP_DEST/"
chmod +x "$CHUNKYMAP_DEST/set-minutely-crontab-job.sh" chmod +x "$CHUNKYMAP_DEST/set-minutely-crontab-job.sh"
python replace-with-current-user.py python replace-with-current-user.py

13
update-chunkymap-installer-only.sh

@ -0,0 +1,13 @@
#!/bin/sh
CHUNKYMAP_INSTALLER_DIR=~/minetest-stuff/minetest-chunkymap
cd ~/minetest-stuff
rm master.zip
wget https://github.com/expertmm/minetest-chunkymap/archive/master.zip
mv master.zip minetest-chunkymap.zip
unzip minetest-chunkymap.zip
#mv minetest-chunkymap-master minetest-chunkymap
mv minetest-chunkymap-master "$CHUNKYMAP_INSTALLER_DIR"
#cd minetest-chunkymap
chmod +x "$CHUNKYMAP_INSTALLER_DIR/install-chunkymap-on-ubuntu.sh"
chmod +x "$CHUNKYMAP_INSTALLER_DIR/update-chunkymap-on-ubuntu-from-web.sh"

18
update-chunkymap-on-ubuntu-from-web.sh

@ -0,0 +1,18 @@
#!/bin/sh
CHUNKYMAP_INSTALLER_DIR=~/minetest-stuff/minetest-chunkymap
./update-chunkymap-installer-only.sh
#./install-chunkymap-on-ubuntu.sh
cp -f "$CHUNKYMAP_INSTALLER_DIR/minetestmapper-numpy.py" "$HOME/minetest/util/minetestmapper-numpy.py"
mkdir "$CHUNKYMAP_DEST"
cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen.py" "$CHUNKYMAP_DEST/"
#chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.py"
cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen.sh" "$CHUNKYMAP_DEST/"
chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.sh"
cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-cronjob" "$CHUNKYMAP_DEST/"
chmod +x "$CHUNKYMAP_DEST/chunkymap-cronjob"
cp -f "$CHUNKYMAP_INSTALLER_DIR/set-minutely-crontab-job.sh" "$CHUNKYMAP_DEST/"
chmod +x "$CHUNKYMAP_DEST/set-minutely-crontab-job.sh"
python replace-with-current-user.py
Loading…
Cancel
Save