diff --git a/archive-minetest-debug.sh b/archive-minetest-debug.sh index a800043..90156bf 100755 --- a/archive-minetest-debug.sh +++ b/archive-minetest-debug.sh @@ -1,36 +1,85 @@ -#!/bin/sh -echo "" -minetest_data_path=$HOME/.minetest +#!/bin/bash + +MT_DATA="$HOME" +# DEBUG_TXT is Detected later. logs_folder_name=debug_archived -logs_folder_path=$minetest_data_path/$logs_folder_name +logs_folder_path=$MT_DATA/$logs_folder_name year_string=`date +%Y` -if [ -f "$minetest_data_path/debug.txt" ]; -then - #date_string=`date +%Y-%m-%d` - month_string=`date +%m` - day_string=`date +%d` - if [ ! -d "$logs_folder_path" ]; - then - mkdir "$logs_folder_path" - fi - if [ ! -d "$logs_folder_path/$year_string" ]; - then - mkdir "$logs_folder_path/$year_string" - fi - if [ ! -d "$logs_folder_path/$year_string/$month_string" ]; - then - mkdir "$logs_folder_path/$year_string/$month_string" - fi - - mts_log_archive_today_file_path=$logs_folder_path/$year_string/$month_string/$day_string.txt - mv "$minetest_data_path/debug.txt" "$mts_log_archive_today_file_path" - if [ -f "$mts_log_archive_today_file_path" ]; then - echo "log saved to $mts_log_archive_today_file_path" - else - echo "Failed to save log to $mts_log_archive_today_file_path" - fi + + +archive_debug() { + DEBUG_TXT="$1" + if [ -f "$DEBUG_TXT" ]; then + #date_string=`date +%Y-%m-%d` + month_string=`date +%m` + day_string=`date +%d` + if [ ! -d "$logs_folder_path" ]; then + mkdir "$logs_folder_path" + fi + if [ ! -d "$logs_folder_path/$year_string" ]; then + mkdir "$logs_folder_path/$year_string" + fi + if [ ! -d "$logs_folder_path/$year_string/$month_string" ]; then + mkdir "$logs_folder_path/$year_string/$month_string" + fi + + this_prefix="$logs_folder_path/$year_string/$month_string/$day_string" + this_path="$this_prefix.txt" + i=2 + if [ -f "$this_path" ]; then + while [[ -e "$this_prefix-$i.txt" ]]; do + let i++ + done + echo "- '$this_path' already exists." + this_prefix="$this_prefix-$i" + this_path="$this_prefix.txt" + echo " * using '$this_path'..." + else + echo "* saving '$this_path'" + fi + mv "$DEBUG_TXT" "$this_path" || echo " - ERROR: Moving log '$DEBUG_TXT' to '$this_path' FAILED." + #if [ -f "$this_path" ]; then + # echo " * saved log '$this_path'" + #else + # echo " * ERROR: Moving log '$DEBUG_TXT' to '$this_path' FAILED." + #fi + else + echo + echo "- There is nothing to do (no $MT_DEBUG is present--perhaps it was already archived--check $year_string folder (perhaps this month's $year_string/$month_string folder) in $logs_folder_path/" + echo + echo + fi +} + +count=0 +if [ "$MT_DATA" = "$HOME" ]; then + if [ -f "$MT_DATA/debug.txt" ]; then + let count++ + archive_debug "$MT_DATA/debug.txt" + fi else - echo "nothing to do (no $minetest_data_path/debug.txt is present--perhaps it was already archived--check $year_string folder (perhaps this month's $year_string/$month_string folder) in $logs_folder_path/" + if [ -f "$HOME/debug.txt" ]; then + let count++ + archive_debug "$HOME/debug.txt" + fi +fi + +if [ -f "$HOME/minetest/debug.txt" ]; then + let count++ + archive_debug "$HOME/minetest/debug.txt" +fi + +if [ -f "$HOME/minetest/bin/debug.txt" ]; then + let count++ + archive_debug "$HOME/minetest/bin/debug.txt" +fi + +if [ "$count" -lt "1" ]; then + echo + echo "- There is not a minetest log in a known location yet." + echo " Maybe it was already archived." + echo + echo fi diff --git a/build-MultiCraft.sh b/build-MultiCraft.sh index 8f17df2..06fba2d 100755 --- a/build-MultiCraft.sh +++ b/build-MultiCraft.sh @@ -5,23 +5,120 @@ # cmake . -DOpenGL_GL_PREFERENCE=GLVND && make me="$0" +RAN_FROM="`pwd`" +customDie() { + echo + echo + echo "$me ERROR:" + echo $1 + echo + exit 1 +} +usage() { + cat < to resume with -r # screen -S MinetestServer minetestserver --gameid ENLIVEN --worldname FCAGameAWorld -# screen -S MinetestServer /home/owner/minetest/bin/minetestserver --gameid ENLIVEN --worldname FCAGameAWorld +# screen -S MinetestServer $HOME/minetest/bin/minetestserver --gameid ENLIVEN --worldname FCAGameAWorld MT_MYWORLD_NAME="FCAWorldB" MT_MYWORLD_DIR="$HOME/.minetest/worlds/$MT_MYWORLD_NAME" WORLD_MT_PATH="$MT_MYWORLD_DIR/world.mt" @@ -57,8 +57,8 @@ fi # --worldname # --world # --config -# cmd="$mts --gameid ENLIVEN --world /home/owner/.minetest/worlds/$MT_MYWORLD_NAME --config /home/owner/minetest/games/ENLIVEN/minetest.conf" -cmd="$mts --gameid ENLIVEN --world /home/owner/.minetest/worlds/$MT_MYWORLD_NAME" +# cmd="$mts --gameid ENLIVEN --world $HOME/.minetest/worlds/$MT_MYWORLD_NAME --config $HOME/minetest/games/ENLIVEN/minetest.conf" +cmd="$mts --gameid ENLIVEN --world $HOME/.minetest/worlds/$MT_MYWORLD_NAME" enable_screen=true if [ -z "$screen_cmd" ]; then if [ -f "`command -v screen`" ]; then diff --git a/utilities/extra/uninstall.py b/utilities/extra/uninstall.py new file mode 100644 index 0000000..f45e932 --- /dev/null +++ b/utilities/extra/uninstall.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python +import os +import platform + +def doDie(msg, error_code=1): + print() + print(msg) + print() + print() + exit(error_code) + +rem_cmd = "#" +rm_cmd = "rm " +rmdir_cmd = "rmdir " +if platform.system() == "Windows": + rm_cmd = "DEL " + rmdir_cmd = "RD " + rem_cmd = "REM " +profile_path1 = os.environ.get('HOME') +profile_path = profile_path1 +profile_path2 = os.environ.get('USERPROFILE') +if profile_path2 is not None: + profile_path = profile_path2 + if profile_path1 is not None: + print(rem_cmd + "WARNING: HOME is present, but USERPROFILE '" + + profile_path + "' is being used.") +else: + if profile_path1 is None: + doDie(rem_cmd + "ERROR: There is nothing to do since neither" + + " HOME nor USERPROFILE is present.") + +mnf_name = "install_manifest.txt" +mnf_path = os.path.join(profile_path, mnf_name) + +unsorted_list = [] + +if not os.path.isfile(mnf_path): + doDie(rem_cmd + "Uninstall cannot continue since '" + mnf_path + + "' is missing.") + +with open(mnf_path) as fp: + for cnt, line_original in enumerate(fp): + # print("Line {}: {}".format(cnt, line)) + line = line_original.strip() + if len(line) > 0: + unsorted_list.append(line) + +if len(unsorted_list) < 1: + doDie(rem_cmd + "ERROR: There are no files in the manifest '" + + mnf_path + "'") + +# See https://stackoverflow.com/questions/4659524/\ +# how-to-sort-by-length-of-string-followed-by-alphabetical-order +sorted_list = sorted(unsorted_list, key=len, reverse=True) +# reverse: descending +# or (also reverse): +# the_list.sort(key=lambda item: (-len(item), item)) + +print(rem_cmd + "Uninstalling...") +not_removed_files = [] +not_removed_dirs = [] +does_not_exist = [] +file_count = 0 +dir_count = 0 +for path in sorted_list: + if os.path.isfile(path): + if path[0:1] == ".": + print(rm_cmd + "\"" + path + "\"") + not_removed_files.append(path) + continue + try: + os.remove(path) + file_count += 1 + except: + not_removed_files.append(path) + elif os.path.isdir(path): + if path[0:1] == ".": + print(rmdir_cmd + "\"" + path + "\"") + not_removed_dirs.append(path) + continue + try: + os.rmdir(path) + dir_count += 1 + except: + not_removed_dirs.append(path) + else: + does_not_exist.append(path) + +if len(does_not_exist) > 0: + if len(does_not_exist) == len(sorted_list): + doDie(" " + rem_cmd + " The program is not installed such as" + + " at '" + sorted_list[-1] + "'.") + +show_dot_warning = True +print(rem_cmd + "Uninstall is complete.") +print(rem_cmd + "- files: " + str(file_count)) +print(rem_cmd + "- directories: " + str(dir_count)) +print(rem_cmd + "- missing: " + len(does_not_exist)) +if (len(not_removed_files) + len(not_removed_dirs)) > 0: + for path in not_removed_files: + if path[0:1] == ".": + if show_dot_warning: + print(rem_cmd + "Paths starting with '.' are not yet implemented." + show_dot_warning = False + print(rm_cmd + "\"" + path + "\"") + for path in not_removed_dirs: + print(rmdir_cmd + "\"" + path + "\"") + print(rem_cmd + "Deleting items above FAILED:") + print(" " + rem_cmd + "- files: " + str(not_removed_file_count)) + print(" " + rem_cmd + "- directories: " + str(not_removed_dir_count)) + + +print() +print() diff --git a/utilities/extra/uninstall.sh b/utilities/extra/uninstall.sh index 4bc7688..be1a619 100755 --- a/utilities/extra/uninstall.sh +++ b/utilities/extra/uninstall.sh @@ -1,5 +1,5 @@ #!/bin/sh -extracted_path=/home/owner/Downloads/minetest +extracted_path=$HOME/Downloads/minetest mnf_name=install_manifest.txt customDie() { echo @@ -13,8 +13,27 @@ if [ ! -f "$extracted_path/$mnf_name" ]; then customDie "$extracted_path/$mnf_name is missing, so $0 cannot continue." fi +if [ ! -f "`command -v xargs`" ]; then + customDie "This script cannot work without xargs. Try uninstall.py." +fi cd $extracted_path || customDie "* cannot cd $extracted_path." echo "- about to run 'sudo xargs rm < $mnf_name'..." -sudo xargs rm < $mnf_name +xargs rm < $mnf_name +echo "- about to run 'sudo xargs rmdir --ignore-fail-on-non-empty < $mnf_name'..." +xargs rmdir --ignore-fail-on-non-empty < $mnf_name +echo " - removing level 7 empty directories..." +xargs rmdir --ignore-fail-on-non-empty < $mnf_name +echo " - removing level 6 empty directories..." +xargs rmdir --ignore-fail-on-non-empty < $mnf_name +echo " - removing level 5 empty directories..." +xargs rmdir --ignore-fail-on-non-empty < $mnf_name +echo " - removing level 4 empty directories..." +xargs rmdir --ignore-fail-on-non-empty < $mnf_name +echo " - removing level 3 empty directories..." +xargs rmdir --ignore-fail-on-non-empty < $mnf_name +echo " - removing level 2 empty directories..." +xargs rmdir --ignore-fail-on-non-empty < $mnf_name +echo " - removing level 1 empty directories..." +xargs rmdir --ignore-fail-on-non-empty < $mnf_name # as per http://irc.minetest.net/minetest/2015-08-06