Reduce mod metadata. Reduce console output...

...and make minetestenv.rc require minetestenv-in-place.rc. Begin to
share code between them.
master
poikilos 2020-05-26 16:51:01 -04:00
parent 6612b16083
commit e3b810e78a
3 changed files with 234 additions and 43 deletions

View File

@ -1,6 +1,8 @@
#!/bin/bash
EM_CONFIG_PATH="$HOME/.config/EnlivenMinetest"
EM_CACHE_PATH="$HOME/.cache/EnlivenMinetest"
GIT_REPOS_PATH="$EM_CACHE_PATH/git"
GIT_BRANCHES_PATH="$EM_CACHE_PATH/git-branches"
MT_ENV_RUP_NAME="minetestenv-in-place.rc"
if [ -z "$EM_TMP" ]; then
EM_TMP=/tmp/EnlivenMinetest
@ -502,24 +504,103 @@ installOrUpgradeMinetest(){
echo "Release $new_release_version" > "$install_dest/release.txt"
echo " * wrote \"`cat $install_dest/release.txt`\" to \"$install_dest/release.txt\"."
fi
return 0
}
minimize_mod() {
MTMOD_DEST_PATH=$1
MTMOD_DEST_NAME="a"
if [ ! -z "$2" ]; then
MTMOD_DEST_NAME=$2
fi
if [ ! -d "$MTMOD_DEST_PATH" ]; then
echo " [minetestenv-in-place minimize_mod] ERROR: $MTMOD_DEST_PATH is missing."
return 1
fi
if [ -d "$MTMOD_DEST_PATH/.git" ]; then
rm -Rf "$MTMOD_DEST_PATH/.git"
fi
if [ -f "$MTMOD_DEST_PATH/.gitignore" ]; then
rm -Rf "$MTMOD_DEST_PATH/.gitignore"
fi
# remove etc to make users downloading mods faster:
if [ -d "$MTMOD_DEST_PATH/etc" ]; then
echo " optimizing $MTMOD_DEST_NAME mod: removing non-game data at $MTMOD_DEST_PATH/etc..."
rm -Rf "$MTMOD_DEST_PATH/etc"
fi
if [ -d "$MTMOD_DEST_PATH/projects" ]; then
rm -Rf "$MTMOD_DEST_PATH/projects"
echo " optimizing $MTMOD_DEST_NAME mod: removing non-game data at $MTMOD_DEST_PATH/projects..."
fi
if [ -d "$MTMOD_DEST_PATH/src" ]; then
if [ -z "`ls $MTMOD_DEST_PATH/src/*.lua`" ]; then
rm -Rf "$MTMOD_DEST_PATH/src"
echo " optimizing $MTMOD_DEST_NAME mod: removing non-game data at $MTMOD_DEST_PATH/src since it contains no lua files..."
fi
fi
for EXTRA_NAME in screenshot.png screenshot.jpg screenshot.bmp screenshot.tif screenshot.gif
do
# if ls ${MTMOD_DEST_PATH}/*.png &>/dev/null
if [ -f "$MTMOD_DEST_PATH/$EXTRA_NAME" ]; then
echo " optimizing $MTMOD_DEST_NAME mod: removing $MTMOD_DEST_PATH/$EXTRA_NAME..."
rm -f "$MTMOD_DEST_PATH/$EXTRA_NAME"
fi
done
}
install_git_mod_here(){
PREV_DIR="`pwd`"
THIS_MODS_PATH="`pwd`"
git_url="$1"
mod_name="$2"
if [ -z "$git_url" ]; then
customExit "install_git_mod_here requires a URL."
customExit " * ERROR: install_git_mod_here requires a URL."
fi
if [ -z "$mod_name" ]; then
customExit "install_git_mod_here requires a mod name as the second parameter."
customExit " * ERROR: install_git_mod_here requires a mod name as the second parameter."
fi
if [ ! -d "$mod_name" ]; then
git clone "$git_url" "$mod_name"
MTMOD_DEST_PATH="$THIS_MODS_PATH/$mod_name"
if [ ! -d "$GIT_REPOS_PATH" ]; then
mkdir -p "$GIT_REPOS_PATH"
fi
THIS_MOD_REPO="$GIT_REPOS_PATH/$mod_name"
if [ -d "$MTMOD_DEST_PATH/.git" ]; then
if [ ! -d "$THIS_MOD_REPO" ]; then
# Deal with remnants from old versions of this function
# that left git metadata in the mod directory.
mv "$MTMOD_DEST_PATH" "$THIS_MOD_REPO"
fi
fi
if [ ! -d "$THIS_MOD_REPO" ]; then
git clone "$git_url" "$THIS_MOD_REPO"
else
cd "$mod_name" || customExit "(install_git_mod_here) 'cd \"$mod_name\"' failed in '`pwd`'"
echo "* updating '`pwd`' from git..."
git pull || echo "WARNING: (install_git_mod_here) 'git pull' failed in '`pwd`'"
cd .. || customExit "(install_git_mod_here) 'cd ..' failed in '`pwd`'"
cd "$THIS_MOD_REPO" || customExit "(install_git_mod_here) 'cd \"$THIS_MOD_REPO\"' failed in '`pwd`'"
# echo " * updating '`pwd`' from git..."
GIT_OUTPUT=$(git pull)
if [ "$GIT_OUTPUT" != "Already up to date." ]; then
echo "$GIT_OUTPUT"
fi
if [ $? -ne 0 ]; then
echo "WARNING: (install_git_mod_here) 'git pull' failed in '`pwd`'"
fi
fi
cd "$PREV_DIR" || customExit "(install_git_mod_here) 'cd ..' failed in '`pwd`'"
if [ -d "$THIS_MOD_REPO" ]; then
echo " * updating $mod_name from $THIS_MOD_REPO..."
if [ -f "`command -v rsync`" ]; then
rsync -rt "$THIS_MOD_REPO/" "$MTMOD_DEST_PATH"
else
echo " removing old `pwd`/$mod_name since rsync is not present..."
rm -Rf "$MTMOD_DEST_PATH" || customExit "rm -Rf \"$MTMOD_DEST_PATH\" failed."
cp -R "$THIS_MOD_REPO" "$MTMOD_DEST_PATH" || customExit "cp -R \"$THIS_MOD_REPO\" \"$MTMOD_DEST_PATH\" failed."
fi
minimize_mod "$MTMOD_DEST_PATH"
else
customExit " * ERROR: Creating $THIS_MOD_REPO failed."
fi
}
@ -615,6 +696,7 @@ addEnlivenMinetestPatches(){
if [ -f "$minetest_conf_dest" ]; then
cat << END
NOTE: minetest.org releases allow you to put a world.conf file in your
world, so that is the file you should edit manually in your world
--this installer overwrites $minetest_conf_dest and

View File

@ -1,3 +1,69 @@
clear
me=`basename "$0"`
echo
echo
echo
scripting_rc_path=~/.config/EnlivenMinetest/scripting.rc
if [ -f "$EM_CONFIG_PATH/scripting.rc" ]; then
echo "* [$MT_ENV_RUP_NAME] using $scripting_rc_path..."
source $scripting_rc_path
fi
if [ -z "$REPO_PATH" ]; then
REPO_PATH="$HOME/git/EnlivenMinetest"
fi
MT_BASH_RC_NAME="minetestenv-in-place.rc"
CURRENT_MT_SCRIPTS_DIR="$HOME/.local/bin"
MT_BASH_RC_PATH="$CURRENT_MT_SCRIPTS_DIR/$MT_BASH_RC_NAME"
TRY_CURRENT_MT_SCRIPTS_DIR="$REPO_PATH"
TRY_MT_BASH_RC_PATH="$TRY_CURRENT_MT_SCRIPTS_DIR/$MT_BASH_RC_NAME"
if [ -f "$TRY_MT_BASH_RC_PATH" ]; then
CURRENT_MT_SCRIPTS_DIR="$TRY_CURRENT_MT_SCRIPTS_DIR"
MT_BASH_RC_PATH="$TRY_MT_BASH_RC_PATH"
fi
#if [ ! -f "$MT_BASH_RC_PATH" ]; then
if [ ! -d "$REPO_PATH" ]; then
if [ -f "$MT_BASH_RC_PATH" ]; then
echo "* updating \"$MT_BASH_RC_PATH\"..."
rm $MT_BASH_RC_PATH
fi
# ^ Always upgrade the rc file manually if it is not in the repo.
if [ ! -d "$CURRENT_MT_SCRIPTS_DIR" ]; then
mkdir -p "$CURRENT_MT_SCRIPTS_DIR"
fi
MT_BASH_RC_URL=https://raw.githubusercontent.com/poikilos/EnlivenMinetest/master/$MT_BASH_RC_NAME
curl $MT_BASH_RC_URL -o "$MT_BASH_RC_PATH"
if [ $? -ne 0 ]; then
#if [ ! -f "$MT_BASH_RC_PATH" ]; then
# This is necessary on cygwin for some reason.
curl $MT_BASH_RC_URL > "$MT_BASH_RC_PATH"
fi
#if [ $? -ne 0 ]; then
if [ ! -f "$MT_BASH_RC_PATH" ]; then
# This is necessary on cygwin for some reason.
wget -O "$MT_BASH_RC_PATH" $MT_BASH_RC_URL
fi
if [ $? -ne 0 ]; then
echo
echo "ERROR: Downloading $MT_BASH_RC_URL to $MT_BASH_RC_PATH failed."
echo
sleep 10
exit 1
fi
else
echo "* using existing $MT_BASH_RC_PATH"
echo " * to update it, run: cd \"$REPO_PATH\" && git pull"
fi
if [ ! -f "$MT_BASH_RC_PATH" ]; then
echo
echo "$MT_BASH_RC_PATH is not present."
echo
sleep 10
exit 1
fi
source $MT_BASH_RC_PATH
# ^ same as install-mts.sh, versionize.sh, update-minetest-linux64.sh
err_txt=$HOME/err-enliven.txt
echo "# * minetestenv.rc started `date`" > "$err_txt"
@ -398,13 +464,16 @@ add_git_mod()
add_mod_from_here $MTMOD_DEST_NAME $MTMOD_GOT_NAME
}
add_mod_from_here()
{
MTMOD_DEST_NAME=$1
MTMOD_GOT_NAME=$2
THIS_MODS_PATH=$MT_MYGAME_MODS_PATH
if [ ! -f "$MOD_LIST" ]; then touch "$MOD_LIST"; fi
echo "$MTMOD_DEST_NAME" >> "$MOD_LIST"
MTMOD_DEST_PATH=$MT_MYGAME_MODS_PATH/$MTMOD_DEST_NAME
MTMOD_DEST_PATH=$THIS_MODS_PATH/$MTMOD_DEST_NAME
if [ -z "$MTMOD_DEST_NAME" ]; then
customExit "ERROR: nothing done since add_mod_from_here FAILED to receive 'MTMOD_DEST_NAME' (1st param)"
fi
@ -443,24 +512,7 @@ add_mod_from_here()
echo " * synchronizing..."
rsync -rt "$MTMOD_GOT_NAME/" "$MTMOD_DEST_PATH"
fi
if [ -d "$MTMOD_DEST_PATH/.git" ]; then
rm -Rf "$MTMOD_DEST_PATH/.git"
fi
if [ -f "$MTMOD_DEST_PATH/.gitignore" ]; then
rm -Rf "$MTMOD_DEST_PATH/.gitignore"
fi
# remove etc to make users downloading mods faster:
if [ -d "$MTMOD_DEST_PATH/etc" ]; then
rm -Rf "$MTMOD_DEST_PATH/etc"
fi
if [ -d "$MTMOD_DEST_PATH/src" ]; then
if [ -z "`ls $MTMOD_DEST_PATH/src/*.lua`" ]; then
rm -Rf "$MTMOD_DEST_PATH/src"
fi
fi
if [ -f "$MTMOD_DEST_PATH/screenshot.png" ]; then
rm -f "$MTMOD_DEST_PATH/screenshot.png"
fi
minimize_mod $MTMOD_DEST_PATH $MTMOD_DEST_NAME
fi
if [ ! -d "$MTMOD_DEST_PATH" ]; then
customExit " MTMOD_DEST_PATH $MTMOD_DEST_PATH is not a directory."
@ -480,7 +532,8 @@ remove_mod()
{
cd $HOME/Downloads
MTMOD_DEST_NAME=$1
MTMOD_DEST_PATH=$MT_MYGAME_MODS_PATH/$MTMOD_DEST_NAME
THIS_MODS_PATH=$MT_MYGAME_MODS_PATH
MTMOD_DEST_PATH=$THIS_MODS_PATH/$MTMOD_DEST_NAME
if [ -d "$MTMOD_DEST_PATH" ]; then
rm -Rf "$MTMOD_DEST_PATH"
if [ -d "$MTMOD_DEST_PATH" ]; then

View File

@ -50,6 +50,9 @@ if [ ! -d "$REPO_PATH" ]; then
sleep 10
exit 1
fi
else
echo "* using existing $MT_BASH_RC_PATH"
echo " * to update it, run: cd \"$REPO_PATH\" && git pull"
fi
if [ ! -f "$MT_BASH_RC_PATH" ]; then
echo
@ -59,7 +62,7 @@ if [ ! -f "$MT_BASH_RC_PATH" ]; then
exit 1
fi
source $MT_BASH_RC_PATH
# ^ same as install-mts.sh, versionize.sh
# ^ same as install-mts.sh, versionize.sh, minetestenv.rc
#INSTALL_SCRIPT_NAME="update-minetest-linux64.sh"
@ -79,7 +82,7 @@ fi
SHORTCUT_PATH="$INSTALL_PATH/misc/net.minetest.minetest.desktop"
TRY_ORG_PATH="$INSTALL_PATH/misc/org.minetest.minetest.desktop"
if [ -f "$TRY_ORG_PATH" ]; then
SHORTCUT_PATH="$TRY_ORG_PATH"
SHORTCUT_PATH="$TRY_ORG_PATH"ungitify_mod
fi
mkdir -p "$EM_TMP"
@ -155,6 +158,60 @@ fi
RELEASE_TXT_URL="https://downloads.minetest.org/release.txt"
detect_mt_version_at "$EM_TMP" "https://downloads.minetest.org/release.txt" "new"
findAndInstallENLIVENOrAskDL() {
if [ ! -d "$INSTALL_PATH/games/ENLIVEN" ]; then
if [ ! -d "$REPO_PATH" ]; then
if [ -f "`command -v git`" ]; then
mkdir -p "$REPO_PATH"
rmdir --ignore-fail-on-non-empty "$REPO_PATH"
git clone https://github.com/poikilos/EnlivenMinetest "$REPO_PATH"
else
echo "* INFO: Installing ENLIVEN has been skipped. This script and the ENLIVEN build script require git for that. On Ubuntu or Debian, first try 'sudo apt-get -y install git' or if on Fedora, try 'sudo dnf -y install git'. Otherwise, try to find git in your \"Software\" or other software center application."
fi
else
echo "* ENLIVEN build scripts were detected in: $REPO_PATH"
echo " To update them, run: cd \"$REPO_PATH\" && git pull"
fi
fi
if [ -d "$REPO_PATH" ]; then
# If it didn't
installOrUpgradeENLIVEN "$INSTALL_PATH"
code=$?
if [ $code -eq 2 ]; then
echo " * skipped"
elif [ $code -eq 0 ]; then
echo " * Installing ENLIVEN to $INSTALL_PATH/games is complete."
else
echo "(installOrUpgradeMinetest failed with error code $code)"
fi
fi
}
installAmhiPatchIfPresent() {
aGameID=amhi_game
aMinetest="$INSTALL_PATH"
if [ -d "$aMinetest/games/amhi_game" ]; then
if [ -d "$REPO_PATH/patches/$aGameID" ]; then
echo "* patching $aGameID from $REPO_PATH/patches/$aGameID..."
if [ "`command -v rsync`" ]; then
rsync -rt --ignore-times "$REPO_PATH/patches/$aGameID/" "$aMinetest/games/amhi_game/"
else
if [ ! -d "$aMinetest/games/amhi_game/menu" ]; then
mkdir -p "$aMinetest/games/amhi_game/menu"
fi
" using cp for known files since rsync is not present..."
cp -f $REPO_PATH/patches/$aGameID/menu/icon.* $aMinetest/games/amhi_game/menu/
fi
if [ $? -eq 0 ]; then
echo " OK"
else
echo " FAILED"
fi
fi
fi
}
if [ "@$old_release_version" = "@$new_release_version" ]; then
install_mt_in_place_shortcut "$SHORTCUT_PATH" "$INSTALL_PATH"
#if [ ! -f "$SHORTCUT_PATH" ]; then
@ -164,7 +221,11 @@ if [ "@$old_release_version" = "@$new_release_version" ]; then
echo
echo "* Adding the icon is complete. See the Desktop or applications (under Games usually--otherwise, search for Final Minetest in the Activities menu if in GNOME or GNOME-based Ubuntu versions 18.04 or later and you do not have a desktop icons extension enabled)."
echo
echo "Version $new_release_version is already installed at $INSTALL_PATH. There is nothing more to do."
installAmhiPatchIfPresent
findAndInstallENLIVENOrAskDL
echo
echo "Version $new_release_version is already installed at $INSTALL_PATH."
echo "There is nothing more to do."
echo
exit 0
fi
@ -188,23 +249,18 @@ unzip "$DL_PATH" > /dev/null || customExit "Extracting $DL_PATH failed."
UNUSED_MT_PATH="$INSTALL_PATH.$old_release_version"
installOrUpgradeMinetest "$EXTRACTED_PATH" "$INSTALL_PATH" "$UNUSED_MT_PATH"
if [ $? -eq 2 ]; then
code=$?
if [ $code -eq 2 ]; then
echo "Final Minetest wasn't upgraded. See the message above."
elif [ $? -eq 0 ]; then
elif [ $code -eq 0 ]; then
echo "Installing Final Minetest $new_release_version to $INSTALL_PATH is complete."
else
echo "(installOrUpgradeMinetest failed with error code $?)"
echo "(installOrUpgradeMinetest failed with error code $code)"
fi
echo " - old:$old_release_version; new:$new_release_version"
echo "* installing ENLIVEN..."
installOrUpgradeENLIVEN "$INSTALL_PATH"
if [ $? -eq 2 ]; then
echo " * skipped"
elif [ $? -eq 0 ]; then
echo " * Installing ENLIVEN to $INSTALL_PATH/games is complete."
else
echo "(installOrUpgradeMinetest failed with error code $?)"
fi
installAmhiPatchIfPresent
findAndInstallENLIVENOrAskDL
install_mt_in_place_shortcut "$SHORTCUT_PATH" "$INSTALL_PATH"
echo