diff --git a/etc/change_hardcoded_world_name_first/backup-mts-world b/etc/change_hardcoded_world_name_first/backup-mts-world index d505e98..c0dda85 100644 --- a/etc/change_hardcoded_world_name_first/backup-mts-world +++ b/etc/change_hardcoded_world_name_first/backup-mts-world @@ -4,21 +4,46 @@ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -date_string=`date +%Y-%m-%d` MT_WORLDS_PATH=$HOME/.minetest/worlds +WORLD_NAME=FCAWorldB +WORLD_PATH=$MT_WORLDS_PATH/$WORLD_NAME +MT_MYWORLD_ENV_META_PATH="$WORLD_PATH/env_meta.txt" +MT_MYWORLD_ENV_META_BAK_PATH="$WORLD_PATH/env_meta.bak" +echo +echo +if [ ! -d "$HOME/Backup" ]; then + mkdir "$HOME/Backup" +fi + +date_string=`date +%Y-%m-%d` cd $MT_WORLDS_PATH ls -name_string=FCAGameAWorld-$date_string.tar.gz -echo "Attempting to create $name_string" -if [ ! -f "$name_string" ] - then - tar -czvf "$name_string" FCAGameAWorld - if [ -f "$name_string" ] - then - echo "Successfully created $MT_WORLDS_PATH/$name_string" + +echo "Making in-place copy of env_meta.txt if good..." +actualsize=$(stat -c%s "$MT_MYWORLD_ENV_META_PATH") +#minsize should actually be more but this should do: +minsize=2 +if [ $actualsize -ge $minsize ]; then + cp -f "$MT_MYWORLD_ENV_META_PATH" "$MT_MYWORLD_ENV_META_BAK_PATH" + echo " copied to $MT_MYWORLD_ENV_META_BAK_PATH" +else + echo " skipping bad $MT_MYWORLD_ENV_META_PATH" +fi + +dated_name=$WORLD_NAME-$date_string.tar.gz +echo "Attempting to create $dated_name..." +if [ ! -f "$dated_name" ]; then + tar -czvf "$dated_name" $WORLD_NAME + dest_path=$HOME/Backup/$dated_name + if [ -f $dated_name ]; then + mv -f "$dated_name" "$HOME/Backup/" + fi + if [ -f "$dest_path" ]; then + echo " successfully created and moved to $dest_path" else - echo "Failed to create $MT_WORLDS_PATH/$name_string" + echo " failed to create $MT_WORLDS_PATH/$dated_name" fi else - echo "Nothing to do. Already saved $MT_WORLDS_PATH/$name_string" + echo " nothing to do since already saved $MT_WORLDS_PATH/$dated_name" fi +echo diff --git a/etc/change_hardcoded_world_name_first/restore-env-meta b/etc/change_hardcoded_world_name_first/restore-env-meta new file mode 100644 index 0000000..2f33180 --- /dev/null +++ b/etc/change_hardcoded_world_name_first/restore-env-meta @@ -0,0 +1,21 @@ +#!/bin/sh +MT_WORLDS_PATH=$HOME/.minetest/worlds +WORLD_NAME=FCAWorldB +WORLD_PATH=$MT_WORLDS_PATH/$WORLD_NAME +MT_MYWORLD_ENV_META_PATH="$WORLD_PATH/env_meta.txt" +MT_MYWORLD_ENV_META_BAK_PATH="$WORLD_PATH/env_meta.bak" + +actualsize=$(stat -c%s "$MT_MYWORLD_ENV_META_PATH") +#minsize should actually be more but this should do: +minsize=2 +if [ $actualsize -ge $minsize ]; then + echo "WARNING: nothing done since already non-zero-sized $MT_MYWORLD_ENV_META_PATH" + exit 0 +fi + + +if [ -f "$MT_MYWORLD_ENV_META_BAK_PATH" ]; then + mv -f "$MT_MYWORLD_ENV_META_BAK_PATH" "$MT_MYWORLD_ENV_META_PATH" +else + echo "ERROR: nothing done since there is no $MT_MYWORLD_ENV_META_BAK_PATH (would be created by backup-mts-world if ran when source was non-zero-size)" +fi