diff --git a/.gitignore b/.gitignore index b1c44ca..7fcc6a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # chunkymap generated data chunkymapdata/ +chunkymap-genresults/ # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/README.md b/README.md index 5bfc788..f075016 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,22 @@ License: (see LICENSE in notepad or your favorite text editor) This program comes without any warranty, to the extent permitted by applicable law. ## Features: -* To loop program (reduces disc reads since stores certain info) run like: - chunkymap-regen.py --loop true -* Change program status while looping by placing chunkymap-signals.txt in the same folder as chunkymap-regen.py (see chunkymap-signals example.txt) -* Has static html version of map (echo_chunkymap_table() php function) +* Runs as python script (loop by default to reduce disc reads since stores certain info) run like: + python chunkymap-regen.py + or to get back to it later with screen -r, instead install screen command (or tmux may work) then run: + screen -t chunkymapregen python /home/owner/minetest/util/chunkymap-regen.py + #where -t chunkymapregen just names the screen chunkymapregen + #Then if you are using screen and want to leave the output without terminating the process press Ctrl a d + #NOTE: now that loop is default, cron job scripts, which now disable loop for compatibility with new version, are ALL optional and NOT recommended + # ( to run only once, run: python chunkymap-regen.py --no-loop true ) +* Change program options (or stop it) while looping or rendering by placing chunkymap-signals.txt in the same directory as chunkymap-regen.py (see chunkymap-signals example files) + - to maintain stability of your text editor, save the file, close it, then move/copy it to the directory (or save it as something else then rename it to chunkymap-signals.txt). +* Has static html version of map (echo_chunkymap_table() php function) -- see example.php * Zoom in and out * optionally echo name of world that was detected by the scheduled py file - * shows player location (and only first 2 characters of name, for privacy; there is no saved setting yet, so to adjust, you must change the value of $nonprivate_name_beginning_char_count in chunkymap.php) + * shows player location (can optionally show only first characters of name, for privacy; there is no saved setting yet, so to adjust, you must change the value of $nonprivate_name_beginning_char_count in chunkymap.php) * Ghost players if they stay in one spot long enough (see $player_file_age_idle_max_seconds in chunkymap.php) * Hide players if they stay in one spot long enough (see $player_file_age_expired_max_seconds in chunkymap.php) avoiding logout detection, and not requiring mods - * Has optional script to add crontab entry (to schedule update script every minute that runs the py file unless the py file is not complete [took longer than 1 minute]) ## Developer Notes: @@ -28,24 +34,26 @@ This program comes without any warranty, to the extent permitted by applicable l * Other requirements for Windows are below; other requirements for GNU/Linux are flock command (only if you schedule the chunkymap-cronjob script), and anything installed by install-chunkymap-on-ubuntu.sh (for other distros, modify it and send me a copy as a GitHub issue as described below in the Installation section) ## Installation -(NOTE: map refresh skips existing tiles unless you delete the related png and text files in your chunkymapdata folder) +(NOTE: map refresh skips existing tiles unless you delete the related png and text files in your chunkymapdata directory) * If you are not using Ubuntu, first edit the installer for your distro (and please send the modified file to me [submit as new issue named such as: DISTRONAME installer except instead of DISTRONAME put the distro you made work]) * If you are using Ubuntu * 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 directory, 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 [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]) + (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 directory in each script that install copies to $HOME/minetest/util]) then go to Terminal and run: `minetestserver` then when it is finished loading, press Ctrl C then run: `chmod +x install-chunkymap-on-ubuntu.sh && ./install-chunkymap-on-ubuntu.sh` - * IF you are using a distro such as Ubuntu 14.04 where first line of /etc/crontab is "m h dom mon dow user command" then if you want regular refresh of map then run + + Installing as cron job is OPTIONAL (and NOT recommended): + * IF you are using a distro such as Ubuntu 14.04 where first line of /etc/crontab is "m h dom mon dow user command" then if you want regular refresh of map then run: (otherwise first edit the script to fit your crontab then) - (if you are not using /var/www/html/minetest/chunkymapdata, edit chunkymap-cronjob script to use the correct folder, then) + (if you are not using /var/www/html/minetest/chunkymapdata, edit chunkymap-cronjob script to use the correct directory, then) `chmod +x set-minutely-crontab-job.sh && ./set-minutely-crontab-job.sh` * IF you are using Linux * Either copy your code to example.php and use it, or just rename it to map.php (or anything you want) then link to it. - # The commands below will work if you are using the web installer, or have done mv minetest-chunkymap-master "$HOME/Downloads/minetest-chunkymap" (and if you are using /var/www/html/minetest -- otherwise change that) + # The commands below will work if you are using the web installer, or have done mv minetest-chunkymap-master "$HOME/Downloads/minetest-chunkymap" (and if you are using /var/www/html/minetest -- otherwise change that below) MT_MY_WEBSITE_PATH=/var/www/html/minetest sudo cp -f "$HOME/Downloads/minetest-chunkymap/web/chunkymap.php" "$MT_MY_WEBSITE_PATH/chunkymap.php" sudo cp --no-clobber "$HOME/Downloads/minetest-chunkymap/web/example.php" "$MT_MY_WEBSITE_PATH/viewchunkymap.php" @@ -54,7 +62,6 @@ This program comes without any warranty, to the extent permitted by applicable l # after you do this, the update script will do it for you if you are using /var/www/html/minetest, otherwise edit the update script before using it to get these things updated * IF you are using Windows * put these files anywhere - * manually schedule a task in Task Scheduler to run C:\Python27\python chunkymap-regen.py every minute * python 2.7.x such as from python.org * run get_python_architecture.py to make sure you know whether to download the following in 32-bit or 64-bit Administrator Command Prompt (to find it in Win 10, right-click windows menu) @@ -74,7 +81,9 @@ This program comes without any warranty, to the extent permitted by applicable l (but put your specific downloaded whl file instead, such as Pillow-3.1.1-cp27-none-win_amd64.whl) * edit chunkymap_regen.py and uncomment website_root="/var/www/html/minetest" then change the value in quotes to your web server's htdocs folder such as, if you are using Apache, can be found as the value of the DocumentRoot variable in httpd.conf in the Apache folder in Program Files * edit chunkymap_regen.py and change world_name to your world name - + * run (or if your python executable does not reside in C:\Python27\ then first edit the file): + chunkymap-regen-loop.bat + * copy example.php and chunkymap.php (and optionally browser.php) to your DocumentRoot or whatever folder will contain the chunkymapdata folder ## Known Issues * chunkymap.php should read the size of the chunks -- see near is_file($chunk_genresult_path) in chunkymap.php * optionally hide player location diff --git a/chunkymap-regen-loop.bat b/chunkymap-regen-loop.bat new file mode 100644 index 0000000..79aa759 --- /dev/null +++ b/chunkymap-regen-loop.bat @@ -0,0 +1,4 @@ +C:\Python27\python.exe chunkymap-regen.py +pause + + diff --git a/chunkymap-regen-loop.sh b/chunkymap-regen-loop.sh new file mode 100644 index 0000000..d5c77bc --- /dev/null +++ b/chunkymap-regen-loop.sh @@ -0,0 +1,2 @@ +#!/bin/sh +flock -n /var/run/chunkymap-loop.lockfile -c screen -t chunkymapregen python /home/owner/minetest/util/chunkymap-regen.py diff --git a/chunkymap-regen.py b/chunkymap-regen.py index bde3365..54933cb 100644 --- a/chunkymap-regen.py +++ b/chunkymap-regen.py @@ -31,14 +31,14 @@ def get_dict_from_conf_file(path,assignment_operator="="): return results def RepresentsInt(s): - try: + try: int(s) return True except ValueError: return False def RepresentsFloat(s): - try: + try: float(s) return True except ValueError: @@ -57,7 +57,7 @@ def get_dict_modified_by_conf_file(this_dict, path,assignment_operator="="): line = ins.readline() if line and len(line)>0: line_strip=line.strip() - if not line_strip[0]=="#": # if not comment + if len(line_strip)>0 and not line_strip[0]=="#": # if not comment if not line_strip[0]=="-": # ignore yaml arrays ao_index = line_strip.find(assignment_operator) if ao_index>=1: # intentionally skip zero-length variable names @@ -145,7 +145,7 @@ class MTChunk: self.is_player_in_this_chunk = False self.is_fresh = False - + self.chunk_dict["is_marked_empty"] = False self.chunk_dict["is_marked"] = False self.chunk_dict["width"] = None @@ -294,13 +294,15 @@ class MTChunks: #ALSO save to YAML: #total_generated_count = 0 #endregion values to save to YAML - + loop_enable = None is_verbose = None world_blacklist = None + run_count = None def __init__(self): #formerly checkpaths() in global scope + self.run_count = 0 self.is_verbose = True self.loop_enable = True self.refresh_map_enable = True @@ -341,7 +343,8 @@ class MTChunks: self.world_path = os.path.join(self.worlds_path, self.world_name) auto_chosen_world = False self.world_blacklist = list() - self.world_blacklist.append("abiyahhgamebv7world1") + self.world_blacklist.append("CarbonUnit") + #self.world_blacklist.append("abiyahhgamebv7world1") if not os.path.isdir(self.world_path): #for item in os.walk(self.worlds_path): print ("LOOKING FOR WORLDS IN " + self.worlds_path) @@ -369,7 +372,7 @@ class MTChunks: self.is_save_output_ok = True # Keeping output after analyzing it is no longer necessary since results are saved to YAML, but keeping output provides debug info since is the output of minetestmapper-numpy.py - + try: alt_path = "C:\\python27\python.exe" if os.path.isfile(alt_path): @@ -438,7 +441,7 @@ class MTChunks: def get_chunk_genresults_tmp_folder(self, chunk_luid): return os.path.join(os.path.dirname(os.path.abspath(__file__)), "chunkymap-genresults") - + def get_chunk_genresult_tmp_path(self, chunk_luid): return os.path.join(self.get_chunk_genresults_tmp_folder(chunk_luid), self.get_chunk_genresult_name(chunk_luid)) @@ -572,14 +575,14 @@ class MTChunks: if not self.is_save_output_ok: if os.path.isfile(genresult_path): os.remove(genresult_path) - + except: print ("Could not finish deleting/moving output") return result - + def check_players(self): # NOT NEEDED: if os.path.isfile(self.mtmn_path) and os.path.isfile(self.colors_path): @@ -633,7 +636,7 @@ class MTChunks: chunk_x = None chunk_y = None chunk_z = None - + player_position_tuple = get_tuple_from_notation(player_position, filename) if player_position_tuple is not None: #Divide by 10 because I don't know why (minetest issue) @@ -664,9 +667,9 @@ class MTChunks: saved_player_y = float(map_player_dict["y"]) if "z" in map_player_dict.keys(): saved_player_z = float(map_player_dict["z"]) - + #if (map_player_dict is None) or not is_same_fvec3( map_player_position_tuple, player_position_tuple): - if (map_player_dict is None) or (saved_player_x is None) or (saved_player_z is None) or (int(saved_player_x)!=int(player_x)) or (int(saved_player_y)!=int(player_y)) or (int(saved_player_z)!=int(player_z)): + if (map_player_dict is None) or (saved_player_x is None) or (saved_player_z is None) or (int(saved_player_x)!=int(player_x)) or (int(saved_player_y)!=int(player_y)) or (int(saved_player_z)!=int(player_z)): # don't check y since y is elevation in minetest, don't use float since subblock position doesn't matter to map if map_player_dict is not None and saved_player_x is not None and saved_player_y is not None and saved_player_z is not None: #print("PLAYER MOVED: "+str(player_name)+" moved from "+str(map_player_position_tuple)+" to "+str(player_position_tuple)) @@ -699,7 +702,7 @@ class MTChunks: if not self.is_verbose: print("PLAYERS:") print(" saved: "+str(player_written_count)+" (moved:"+str(players_moved_count)+"; new:"+str(players_saved_count)+")") - print(" didn't move: "+str(player_name)) + print(" didn't move: "+str(players_didntmove_count)) def is_player_at_luid(self, chunk_luid): result = False @@ -712,7 +715,7 @@ class MTChunks: if chunk_luid in self.chunks.keys(): result = self.chunks[chunk_luid].is_fresh return result - + def check_map(self): if os.path.isfile(self.mtmn_path) and os.path.isfile(self.colors_path): rendered_count = 0 @@ -784,8 +787,17 @@ class MTChunks: print("PROCESSING MAP DATA") while outline_generates_count > 0: outline_generates_count = 0 + self.read_then_remove_signals() + if not self.refresh_map_enable: + break for z in range (self.chunkz_min,self.chunkz_max+1): + self.read_then_remove_signals() + if not self.refresh_map_enable: + break for x in range(self.chunkx_min,self.chunkx_max+1): + self.read_then_remove_signals() + if not self.refresh_map_enable: + break #python ~/minetest/util/minetestmapper-numpy.py --region -1200 800 -1200 800 --drawscale --maxheight 100 --minheight -50 --pixelspernode 1 ~/.minetest/worlds/FCAGameAWorld ~/map.png #sudo mv ~/map.png /var/www/html/minetest/images/map.png @@ -924,9 +936,11 @@ class MTChunks: def read_then_remove_signals(self): signal_path = self.get_signal_path() if os.path.isfile(signal_path): - signals = get_dict_from_conf_file(signal_path) + signals = get_dict_from_conf_file(signal_path,":") if signals is not None: - for this_key in signals.keys: + print("RECEIVED "+str(len(signals))+" signal(s)") + for this_key in signals.keys(): + print("RECEIVED SIGNAL "+str(this_key)+":"+str(signals[this_key])) if this_key=="loop_enable": if not signals[this_key]: self.loop_enable = False @@ -961,15 +975,15 @@ class MTChunks: else: print("ERROR: unknown signal '"+this_key+"'") - + else: print("WARNING: blank '"+signal_path+"'") try: - os.remove() + os.remove(signal_path) except: - print("FATAL ERROR: "+__file__+" must have permission to remove '"+signal_path+"' so exiting to avoid inability to avoid repeating commands at next launch.") - self.loop_enable = False + print("ERROR: "+__file__+" must have permission to remove '"+signal_path+"'. Commands will be repeated unless command was loop_enable:false.") # so exiting to avoid inability to avoid repeating commands at next launch.") + #self.loop_enable = False def run_loop(self): #self.last_run_second = best_timer() @@ -981,19 +995,24 @@ class MTChunks: if self.refresh_players_seconds < run_wait_seconds: run_wait_seconds = self.refresh_players_seconds print("") + print("Ran "+str(self.run_count)+" time(s)") self.read_then_remove_signals() if self.loop_enable: if self.refresh_players_enable: if self.last_players_refresh_second is None or (best_timer()-self.last_players_refresh_second > self.refresh_players_seconds ): - last_players_refresh_second = best_timer() + #if self.last_players_refresh_second is not None: + #print ("waited "+str(best_timer()-self.last_players_refresh_second)+"s for map update") + self.last_players_refresh_second = best_timer() self.check_players() else: print("waiting before doing player update") else: print("player update is not enabled") if self.refresh_map_enable: - if self.last_map_refresh_second is None or (best_timer()-self.last_map_refresh_second > self.refresh_map_seconds): - last_map_refresh_second = best_timer() + if (self.last_map_refresh_second is None) or (best_timer()-self.last_map_refresh_second > self.refresh_map_seconds): + #if self.last_map_refresh_second is not None: + #print ("waited "+str(best_timer()-self.last_map_refresh_second)+"s for map update") + self.last_map_refresh_second = best_timer() self.check_map() else: print("waiting before doing map update") @@ -1003,7 +1022,9 @@ class MTChunks: self.is_verbose = True run_wait_seconds -= (best_timer()-before_second) if (int(float(run_wait_seconds)+.5)>0.0): + print ("sleeping for "+str(run_wait_seconds)+"s") time.sleep(run_wait_seconds) + self.run_count += 1 def run(self): if self.refresh_players_enable: @@ -1018,9 +1039,9 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description='A mapper for minetest') parser.add_argument('--skip-map', type = bool, metavar = ('skip_map'), default = False, help = 'draw map tiles and save YAML files for chunkymap.php to use') parser.add_argument('--skip-players', type = bool, metavar = ('skip_players'), default = False, help = 'update player YAML files for chunkymap.php to use') - parser.add_argument('--loop', type = bool, metavar = ('loop'), default = False, help = 'keep running until "'+signal_path+'" contains the line '+stop_line) + parser.add_argument('--no-loop', type = bool, metavar = ('no_loop'), default = False, help = 'keep running until "'+signal_path+'" contains the line '+stop_line) args = parser.parse_args() - + if not args.skip_players: if not args.skip_map: print("Drawing players and map") @@ -1036,8 +1057,8 @@ if __name__ == '__main__': mtchunks.refresh_map_enable = False print("Nothing to do since "+str(args)) if mtchunks.refresh_players_enable or mtchunks.refresh_map_enable: - if args.loop: + if args.no_loop: + mtchunks.run() + else: print("To stop chunkymap-regen loop, save a line '"+stop_line+"' to '"+signal_path+"'") mtchunks.run_loop() - else: - mtchunks.run() diff --git a/chunkymap-signals example - change map refresh.txt b/chunkymap-signals example - change map refresh.txt new file mode 100644 index 0000000..42ad323 --- /dev/null +++ b/chunkymap-signals example - change map refresh.txt @@ -0,0 +1,2 @@ +#Chunk files read frequency (does not keep reading png files if in loop mode since freshness booleans are saved in memory) +refresh_map_seconds:300 \ No newline at end of file diff --git a/chunkymap-signals example - change player refresh.txt b/chunkymap-signals example - change player refresh.txt new file mode 100644 index 0000000..96e3235 --- /dev/null +++ b/chunkymap-signals example - change player refresh.txt @@ -0,0 +1,3 @@ +#Change player file read frequency +refresh_players_seconds:60 + diff --git a/chunkymap-signals example - no player update.txt b/chunkymap-signals example - no player update.txt new file mode 100644 index 0000000..5f25b0c --- /dev/null +++ b/chunkymap-signals example - no player update.txt @@ -0,0 +1,2 @@ +#to stop checking for player movements (players will timeout and the php will stop showing the players due to old file modified times) +refresh_players_enable:False diff --git a/chunkymap-signals example - prevent or cancel map refresh.txt b/chunkymap-signals example - prevent or cancel map refresh.txt new file mode 100644 index 0000000..04df62a --- /dev/null +++ b/chunkymap-signals example - prevent or cancel map refresh.txt @@ -0,0 +1,3 @@ +#to stop checking for map updates (NOTE: the map update function is only able to detect new chunks, and only checks edge chunks if player is present in one) +refresh_map_enable:False +# ALSO stops map generation early if still processing chunks \ No newline at end of file diff --git a/chunkymap-signals example - stop looping.txt b/chunkymap-signals example - stop looping.txt new file mode 100644 index 0000000..bd3473a --- /dev/null +++ b/chunkymap-signals example - stop looping.txt @@ -0,0 +1,3 @@ +#to stop looping: +loop_enable:False + diff --git a/chunkymap-signals example.txt b/chunkymap-signals example.txt deleted file mode 100644 index 686982c..0000000 --- a/chunkymap-signals example.txt +++ /dev/null @@ -1,11 +0,0 @@ -#to stop program: -loop_enable:False - -#to stop checking for player movements (players will timeout and the php will stop showing the players due to old file modified times) -refresh_players_enable:False -#to stop checking for map updates (NOTE: the map update function is only able to detect new chunks, and only checks edge chunks if player is present in one) -refresh_map_enable:False - -#other options: -refresh_players_seconds:60 -refresh_map_seconds:300 \ No newline at end of file diff --git a/install-chunkymap-on-ubuntu.sh b/install-chunkymap-on-ubuntu.sh index 2cabbc8..b7170e7 100644 --- a/install-chunkymap-on-ubuntu.sh +++ b/install-chunkymap-on-ubuntu.sh @@ -1,7 +1,8 @@ #!/bin/sh cd $HOME +MT_MY_WEBSITE_PATH=/var/www/html/minetest rm -Rf $HOME/minetest-stuff/minetest-chunkymap -CHUNKYMAP_INSTALLER_DIR=$HOME/Downloads/minetest-chunkymap +CHUNKYMAP_INSTALLER_PATH=$HOME/Downloads/minetest-chunkymap if [ ! -d "$HOME/Downloads" ]; then mkdir "$HOME/Downloads" fi @@ -13,31 +14,51 @@ CHUNKYMAP_DEST=$MINETEST_UTIL #rm -f $HOME/minetestmapper-numpy.py #wget https://github.com/spillz/minetest/raw/master/util/minetestmapper-numpy.py #since colors.txt is in $HOME/minetest/util: -cp -f "$CHUNKYMAP_INSTALLER_DIR/minetestmapper-numpy.py" "$HOME/minetest/util/minetestmapper-numpy.py" +cp -f "$CHUNKYMAP_INSTALLER_PATH/minetestmapper-numpy.py" "$HOME/minetest/util/minetestmapper-numpy.py" if [ ! -d "$CHUNKYMAP_DEST" ]; then # Control will enter here if $DIRECTORY doesn't exist. mkdir "$CHUNKYMAP_DEST" fi -cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen.py" "$CHUNKYMAP_DEST/" +if [ ! -d "$CHUNKYMAP_DEST/unused/" ]; then + mkdir "$CHUNKYMAP_DEST/unused/" +fi +cp -f "$CHUNKYMAP_INSTALLER_PATH/unused/chunkymap-regen.py" "$CHUNKYMAP_DEST/unused/" #chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.py" -cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen.sh" "$CHUNKYMAP_DEST/" -cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen-players.sh" "$CHUNKYMAP_DEST/" -cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-cronjob" "$CHUNKYMAP_DEST/" -cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-players-cronjob" "$CHUNKYMAP_DEST/" -cp -f "$CHUNKYMAP_INSTALLER_DIR/set-minutely-players-crontab-job.sh" "$CHUNKYMAP_DEST/" -cd "$CHUNKYMAP_INSTALLER_DIR" -python replace-with-current-user.py # the py file only manipulates the minetest/util folder -# so chmod those files AFTER running the py above: -chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.sh" -chmod +x "$CHUNKYMAP_DEST/chunkymap-regen-players.sh" -chmod +x "$CHUNKYMAP_DEST/chunkymap-cronjob" -chmod +x "$CHUNKYMAP_DEST/set-minutely-crontab-job.sh" + +cp -f "$CHUNKYMAP_INSTALLER_PATH/README.md" "$CHUNKYMAP_DEST/" +#remove files place in dest by old version of installer script: +rm -f "$CHUNKYMAP_DEST/chunkymap-regen.sh" +rm -f "$CHUNKYMAP_DEST/chunkymap-regen-players.sh" +rm -f "$CHUNKYMAP_DEST/chunkymap-cronjob" +rm -f "$CHUNKYMAP_DEST/chunkymap-players-cronjob" +rm -f "$CHUNKYMAP_DEST/set-minutely-players-crontab-job.sh" +#install scripts: +cp -f "$CHUNKYMAP_INSTALLER_PATH/unused/chunkymap-regen.sh" "$CHUNKYMAP_DEST/unused/" +cp -f "$CHUNKYMAP_INSTALLER_PATH/unused/chunkymap-regen-players.sh" "$CHUNKYMAP_DEST/unused/" +cp -f "$CHUNKYMAP_INSTALLER_PATH/unused/chunkymap-cronjob" "$CHUNKYMAP_DEST/unused/" +cp -f "$CHUNKYMAP_INSTALLER_PATH/unused/chunkymap-players-cronjob" "$CHUNKYMAP_DEST/unused/" +cp -f "$CHUNKYMAP_INSTALLER_PATH/unused/set-minutely-players-crontab-job.sh" "$CHUNKYMAP_DEST/unused/" +cp -f "$CHUNKYMAP_INSTALLER_PATH/chunkymap-regen-loop.sh" "$CHUNKYMAP_DEST/" +cd "$CHUNKYMAP_INSTALLER_PATH" +python replace-with-current-user.py # the py file only manipulates the minetest/util directory +# so chmod those files AFTER running the py above (since it rewrites them and therefore removes x attribute if present): +chmod +x "$CHUNKYMAP_DEST/chunkymap-regen-loop.sh" +chmod -x "$CHUNKYMAP_DEST/unused/chunkymap-regen.sh" +chmod -x "$CHUNKYMAP_DEST/unused/chunkymap-regen-players.sh" +chmod -x "$CHUNKYMAP_DEST/unused/chunkymap-cronjob" +chmod -x "$CHUNKYMAP_DEST/unused/set-minutely-crontab-job.sh" sudo apt-get install python-numpy python-pil echo "" -echo "To learn about chunkymap:" +echo "To see what needs to be in your $MT_MY_WEBSITE_PATH directory (if you don't use that directory, modify chunkymap-regen.py to use your directory):" +echo "cd $CHUNKYMAP_DEST/web" +echo "" +echo "To view helpful scripts:" echo "cd $CHUNKYMAP_DEST" echo "" +echo "To learn more about chunkymap:" +echo "nano $CHUNKYMAP_DEST/README.md" +echo # NOTE: colors.txt should ALREADY be in $HOME/minetest/util diff --git a/replace-with-current-user.py b/replace-with-current-user.py index 1d94af1..afdf94f 100644 --- a/replace-with-current-user.py +++ b/replace-with-current-user.py @@ -3,37 +3,45 @@ import os from os.path import expanduser filenames = list() -filenames.append("chunkymap-cronjob") -filenames.append("chunkymap-regen.sh") -filenames.append("set-minutely-crontab-job.sh") +filenames.append(os.path.join("unused","chunkymap-cronjob")) +filenames.append(os.path.join("unused","chunkymap-players-cronjob")) +filenames.append(os.path.join("unused","chunkymap-regen-players.sh")) +filenames.append(os.path.join("unused","chunkymap-regen.sh")) +filenames.append(os.path.join("unused","set-minutely-players-crontab-job.sh")) +filenames.append(os.path.join("unused","set-minutely-crontab-job.sh")) +filenames.append("chunkymap-regen-loop.sh") home_path = expanduser("~") home_minetest_chunkymap_path = os.path.join(home_path,"minetest/util") +#home_minetest_chunkymap_unused_path = os.path.join(home_minetest_chunkymap_path, "unused") #for dirname, dirnames, filenames in os.walk(home_minetest_chunkymap_path): if "\\" not in home_minetest_chunkymap_path: if os.path.isdir(home_minetest_chunkymap_path): for filename in filenames: file_path = os.path.join(home_minetest_chunkymap_path, filename) - temp_path = file_path+".tmp" - os.rename(file_path, temp_path) - if not os.path.isfile(file_path): - ins = open(temp_path, 'r') - outs = open(file_path, 'w') - line = True - while line: - line = ins.readline() - if line: - line = line.replace("/home/owner", home_path) - outs.write(line+"\n") - outs.close() - os.remove(temp_path) - ins.close() - else: - print "FAILED to rewrite the file '"+file_path+"' (to change minetest util path to '"+home_minetest_chunkymap_path+"')--perhaps it is in use. Make the file writeable then try running "+__FILE__+" again." - input("Press enter to continue...") + if os.path.isfile(file_path): + temp_path = file_path+".tmp" + os.rename(file_path, temp_path) + if not os.path.isfile(file_path): + ins = open(temp_path, 'r') + outs = open(file_path, 'w') + line = True + while line: + line = ins.readline() + if line: + line = line.replace("/home/owner", home_path) + outs.write(line+"\n") + outs.close() + os.remove(temp_path) + ins.close() + else: + print "FAILED to rewrite the file '"+file_path+"' (to change minetest util path to '"+home_minetest_chunkymap_path+"')--perhaps it is in use. Make the file writeable then try running "+__FILE__+" again." + input("Press enter to continue...") + else: + print "SKIPPED "+filename+" since not installed (probably ok since deprecated files are still listed here)" else: print "FAILED to find '"+home_minetest_chunkymap_path+"'" print "Please install a compatible version of minetest-server package, run minetestserver once, then if you were running a chunkymap installer that called this py file, re-run that installer (otherwise re-run this script if you are sure that installer was successful)." input("Press enter to continue...") else: - print "This script only works on GNU/Linux systems (it is not needed on Windows, since on Windows, chunkymap will detect the scripts and colors.txt in the same folder as itself instead of using the minecraftserver minetest/util folder)" + print "This script only works on GNU/Linux systems (it is not needed on Windows, since on Windows, chunkymap will detect the scripts and colors.txt in the same directory as itself instead of using the minecraftserver minetest/util directory)" diff --git a/chunkymap-cronjob b/unused/chunkymap-cronjob similarity index 100% rename from chunkymap-cronjob rename to unused/chunkymap-cronjob diff --git a/chunkymap-players-cronjob.sh b/unused/chunkymap-players-cronjob similarity index 100% rename from chunkymap-players-cronjob.sh rename to unused/chunkymap-players-cronjob diff --git a/chunkymap-regen-players.bat b/unused/chunkymap-regen-players.bat similarity index 55% rename from chunkymap-regen-players.bat rename to unused/chunkymap-regen-players.bat index 7c515af..ab77cae 100644 --- a/chunkymap-regen-players.bat +++ b/unused/chunkymap-regen-players.bat @@ -1,4 +1,4 @@ -C:\Python27\python.exe chunkymap-regen.py --skip-map=true +C:\Python27\python.exe chunkymap-regen.py --skip-map true --no-loop true REM C:\Python27\python.exe chunkymap-regen.py --skip-players=true --skip-map=true pause diff --git a/chunkymap-regen-players.sh b/unused/chunkymap-regen-players.sh similarity index 51% rename from chunkymap-regen-players.sh rename to unused/chunkymap-regen-players.sh index 8ddff81..35ae2ab 100644 --- a/chunkymap-regen-players.sh +++ b/unused/chunkymap-regen-players.sh @@ -1,4 +1,4 @@ #!/bin/sh # NOTE: only works since all scripts in /etc/cron.*/ or crontab run as root -python /home/owner/minetest/util/chunkymap-regen.py --skip-map=true +python /home/owner/minetest/util/chunkymap-regen.py --skip-map true --noloop true diff --git a/chunkymap-regen.sh b/unused/chunkymap-regen.sh similarity index 56% rename from chunkymap-regen.sh rename to unused/chunkymap-regen.sh index 6eb1921..506aa19 100644 --- a/chunkymap-regen.sh +++ b/unused/chunkymap-regen.sh @@ -1,5 +1,5 @@ #!/bin/sh # NOTE: only works since all scripts in /etc/cron.*/ or crontab run as root -python /home/owner/minetest/util/chunkymap-regen.py +python /home/owner/minetest/util/chunkymap-regen.py --no-loop true diff --git a/set-minutely-crontab-job.sh b/unused/set-minutely-crontab-job.sh similarity index 100% rename from set-minutely-crontab-job.sh rename to unused/set-minutely-crontab-job.sh diff --git a/set-minutely-players-crontab-job.sh b/unused/set-minutely-players-crontab-job.sh similarity index 100% rename from set-minutely-players-crontab-job.sh rename to unused/set-minutely-players-crontab-job.sh diff --git a/update-chunkymap-on-ubuntu-from-web.sh b/update-chunkymap-on-ubuntu-from-web.sh index 64c2355..d01f3ca 100644 --- a/update-chunkymap-on-ubuntu-from-web.sh +++ b/update-chunkymap-on-ubuntu-from-web.sh @@ -17,10 +17,11 @@ sh "$CHUNKYMAP_INSTALLER_DIR/install-chunkymap-on-ubuntu.sh" MT_MY_WEBSITE_PATH=/var/www/html/minetest +# IF already installed to default MT_MY_WEBSITE_PATH, update the files: if [ -f "$HOME/Downloads/minetest-chunkymap/web/chunkymap.php" ]; then if [ -f "$MT_MY_WEBSITE_PATH/chunkymap.php" ]; then sudo cp -f "$HOME/Downloads/minetest-chunkymap/web/chunkymap.php" "$MT_MY_WEBSITE_PATH/" - sudo cp --no-clobber "$HOME/Downloads/minetest-chunkymap/web/example.php" "$MT_MY_WEBSITE_PATH/viewchunkymap.php" + sudo cp --no-clobber "$HOME/Downloads/minetest-chunkymap/web/example.php" "$MT_MY_WEBSITE_PATH/map.php" # cannot put wildcard in quotes on unix sudo cp -R --no-clobber $HOME/Downloads/minetest-chunkymap/web/images/* "$MT_MY_WEBSITE_PATH/images/" #--no-clobber: do not overwrite existing