Skip to content

Instantly share code, notes, and snippets.

@sozforex
Forked from b2cc/pathfinder.sh
Created January 15, 2019 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sozforex/be707f0064fb8098f27c42f463971b68 to your computer and use it in GitHub Desktop.
Save sozforex/be707f0064fb8098f27c42f463971b68 to your computer and use it in GitHub Desktop.
Find wrong pathnames when running Battletech mods in Linux (check case-sensitivity)
#!/bin/bash
#
# pathfinder.sh
#
# Find wrong pathnames when running Battletech mods
# in Linux (check case-sensitivity)
#
# navigate to your BATTLETECH install folder and execute this script, i.e.
#
# cd /home/$(whoami)/.local/share/Steam/steamapps/common/BATTLETECH
# bash ./pathfinder.sh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
LOGGER="$(which logger)"
# set term colors via tput
# see man terminfo
black=$(tput setaf 0)
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
magenta=$(tput setaf 5)
cyan=$(tput setaf 6)
white=$(tput setaf 7)
bold=$(tput bold)
reset=$(tput sgr0)
debug="disabled"
counter=""
log_generic() {
logdate=$(date "+%h %d %H:%M:%S")
logproc=$(echo $$)
logmessage="$logdate ${HOST} ${scriptname}[${logproc}]: (${USER}) ${LOGLEVEL}: $1"
echo "${logmessage}"
${LOGGER} "$1"
}
log() {
LOGLEVEL="${white}${bold}INFO${reset}"
log_generic "$@"
}
log_debug() {
if [[ ${debug} == enabled ]]; then
LOGLEVEL="${blue}${bold}DEBUG${reset}"
log_generic "$@"
fi
}
log_warn() {
LOGLEVEL="${yellow}${bold}WARN${reset}"
log_generic "$@"
}
die() {
LOGLEVEL="${red}${bold}ERROR${reset}"
log_generic "$@"
exit 1
}
trap "die 'Program interrupted! Exiting...'" SIGHUP SIGINT SIGQUIT SIGABRT
BINARIES=(jq)
for binary in "${BINARIES[@]}"; do
[[ -x $(which ${binary} 2>/dev/null) ]] || die "${binary} binary not found, exiting."
done
log " * checking if we are in the right folder"
if ! [[ -d ./BattleTech_Data ]] || ! [[ -d ./Mods ]]; then
die " can't locate either BattleTech_Data (n)or Mods folder, please run this script from the BATTLETECH install directory. exiting."
else
log " found BattleTech_Data and Mods folders, continuing."
fi
log " * testing if lowercase symlink for Mods folder exists:"
if ! [[ $(readlink ./mods) == Mods ]]; then
log_warn " symlink mods to folder Mods doesn't exist - some mods may misbehave!"
else
log " mods -> Mods symlink found, continuing."
fi
log " * evaluating mod folders and checking for mod.json files..."
read_mods() {
find ./Mods -mindepth 1 -maxdepth 1 -type d -prune -not -path './Mods/.modtek' | sort
}
read_path(){
jq -r '.Manifest[].Path' "${mod}"/mod.json 2>/dev/null | egrep -v '[Aa]ssets|AssetBundleName'
}
readarray -t modmap < <(read_mods)
for mod in "${modmap[@]}"; do
log " mod: ${mod}"
counter=0
if [[ -r "${mod}"/mod.json ]]; then
log_debug " extracting paths from mod.json"
readarray -t pathmap < <(read_path)
if [[ -z "${pathmap}" ]]; then
log " - mod seems to not define any paths, continuing..."
else
log_debug " - testing paths in mod \"${mod}\"..."
for path in "${pathmap[@]}"; do
log_debug " - testing for existing path \"${path}\" in folder \"${mod}\""
if [[ -d "${mod}/${path}" ]]; then
log_debug " - ${mod}/${path} ...${green}${bold}OK${reset}"
log_debug ""
else
log_warn " - ${mod}/${path} ...${red}${bold}NOT FOUND!${reset}"
counter=$((counter+1))
fi
done
fi
else
log_warn " couldn't find mod.json - possibly not a mod folder? please make your checks."
log_warn ""
fi
if [[ ${counter} -eq 0 ]]; then log " - mod ${green}${bold}OK!${reset}"; fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment