fix: updating now works properly
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
VERSION="0.3.14"
|
||||
VERSION="0.3.15"
|
||||
|
||||
# --- Globals ---
|
||||
|
||||
@@ -1263,7 +1263,7 @@ function main() {
|
||||
mod_reset "$@"
|
||||
;;
|
||||
"version"|"v"|"-v"|"--version")
|
||||
log INFO "${VERSION}"
|
||||
echo "$VERSION"
|
||||
;;
|
||||
"update"|"up")
|
||||
self_update
|
||||
|
||||
+61
-53
@@ -40,19 +40,25 @@ https://github.com/v4n00/h2mm-cli
|
||||
|
||||
EOF
|
||||
|
||||
# check if update
|
||||
|
||||
# breaking changes hash table
|
||||
breaking_changes_patches=(
|
||||
["2"]='sed -i "s/^\([0-9]\+\),/\1,ENABLED,/" "$1/mods.csv"'
|
||||
["3"]='sed -i "1 i\\3" "$1/mods.csv"'
|
||||
)
|
||||
|
||||
# handle breaking changes
|
||||
# notify if update is happening
|
||||
installed_version=""
|
||||
latest_version=""
|
||||
if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
|
||||
installed_version=$($SCRIPT_NAME --version)
|
||||
# version 1 show the help message, if the first character is not a 0, store installed version as 0.1.6
|
||||
[[ ${installed_version:0:1} != "0" ]] && { installed_version="0.1.6"; }
|
||||
|
||||
# if installed version isn't x.x.x crash
|
||||
if [[ ! "$installed_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
log ERROR "Installed version is not in the correct format."
|
||||
log ERROR "h2mm is installed here -> $(which h2mm)"
|
||||
log ERROR "Delete the script file and retry the install script, any mods installed will not be lost."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
latest_version=$(curl -sS "$REPO_URL"/version)
|
||||
if [[ "$latest_version" == "$installed_version" ]]; then
|
||||
@@ -60,54 +66,6 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
|
||||
else
|
||||
log INFO "You are upgrading from ${ORANGE}$installed_version${NC} -> ${GREEN}$latest_version${NC}."
|
||||
fi
|
||||
|
||||
# split version numbers
|
||||
installed_major=""
|
||||
latest_major=""
|
||||
IFS='.' read -r _1 installed_major _2 <<< "$installed_version"
|
||||
IFS='.' read -r _1 latest_major _2 <<< "$latest_version"
|
||||
|
||||
if [[ $latest_major -gt $installed_major ]]; then
|
||||
log INFO "Major version upgrade detected."
|
||||
log INFO "Check out the changelogs here -> https://github.com/v4n00/h2mm-cli/releases"
|
||||
log INFO "The script will proceed to upgrade the database file to avoid breaking changes."
|
||||
|
||||
# find hd2 path
|
||||
search_dir="${HOME}"
|
||||
target_dir="Steam/steamapps/common/Helldivers\ 2/data"
|
||||
log INFO "Searching for the Helldivers 2 data directory... (20 seconds timeout)"
|
||||
|
||||
game_dir=$(timeout 20 find "$search_dir" -type d -path "*/$target_dir" 2>/dev/null | head -n 1)
|
||||
if [[ -z "$game_dir" ]]; then
|
||||
log INFO "Could not find the Helldivers 2 data directory automatically."
|
||||
log PROMPT "Please enter the path to the Helldivers 2 data directory: "
|
||||
IFS= read -e game_dir
|
||||
if [[ ! -d "$game_dir" ]]; then
|
||||
log ERROR "Provided path is not a valid directory."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ ! -f "$game_dir/mods.csv" ]] && { log ERROR "mods.csv not found in $game_dir." ; exit 1; }
|
||||
|
||||
# iterate from installed major number to latest major number
|
||||
for ((i = installed_major + 1; i <= latest_major; i++)); do
|
||||
if [[ -n "${breaking_changes_patches[$i]}" ]]; then
|
||||
eval $(echo "${breaking_changes_patches[$i]}" | sed "s:\$1:$game_dir:")
|
||||
else
|
||||
log INFO "No breaking changes for version $i."
|
||||
fi
|
||||
if [[ $? -ne 0 ]]; then
|
||||
log ERROR "Failed to apply breaking changes patch for version $i. Do you want to continue? (Y/n): "
|
||||
read -er response
|
||||
|
||||
[[ "$response" != "y" && "$response" != "Y" && -n "$response" ]] && { log INFO "Exiting. Uninstall the script, then retry the install script." ; exit 1; }
|
||||
else
|
||||
log INFO "Breaking changes patch for version ${ORANGE}$i${NC} applied ${GREEN}successfully${NC}."
|
||||
fi
|
||||
done
|
||||
fi
|
||||
log INFO ""
|
||||
fi
|
||||
|
||||
# if steam deck, set destination path to ~/.local/bin
|
||||
@@ -146,10 +104,60 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
# handle breaking changes
|
||||
installed_major=""
|
||||
latest_major=""
|
||||
IFS='.' read -r _1 installed_major _2 <<< "$installed_version"
|
||||
IFS='.' read -r _1 latest_major _2 <<< "$latest_version"
|
||||
|
||||
if [[ $latest_major -gt $installed_major ]]; then
|
||||
log INFO ""
|
||||
log INFO "Major version upgrade detected."
|
||||
log INFO "Check out the changelogs here -> https://github.com/v4n00/h2mm-cli/releases"
|
||||
log INFO "The script will proceed to upgrade the database file to avoid breaking changes."
|
||||
|
||||
# find hd2 path
|
||||
search_dir="${HOME}"
|
||||
target_dir="Steam/steamapps/common/Helldivers\ 2/data"
|
||||
log INFO "Searching for the Helldivers 2 data directory... (20 seconds timeout)"
|
||||
|
||||
game_dir=$(timeout 20 find "$search_dir" -type d -path "*/$target_dir" 2>/dev/null | head -n 1)
|
||||
if [[ -z "$game_dir" ]]; then
|
||||
log INFO "Could not find the Helldivers 2 data directory automatically."
|
||||
log PROMPT "Please enter the path to the Helldivers 2 data directory: "
|
||||
IFS= read -e game_dir
|
||||
if [[ ! -d "$game_dir" ]]; then
|
||||
log ERROR "Provided path is not a valid directory."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ ! -f "$game_dir/mods.csv" ]] && { log ERROR "mods.csv not found in $game_dir." ; exit 1; }
|
||||
|
||||
# iterate from installed major number to latest major number
|
||||
for ((i = installed_major + 1; i <= latest_major; i++)); do
|
||||
if [[ -n "${breaking_changes_patches[$i]}" ]]; then
|
||||
eval $(echo "${breaking_changes_patches[$i]}" | sed "s:\$1:$game_dir:")
|
||||
else
|
||||
log INFO "No breaking changes for version $i."
|
||||
fi
|
||||
if [[ $? -ne 0 ]]; then
|
||||
log ERROR "Failed to apply breaking changes patch for version $i. Do you want to continue? (Y/n): "
|
||||
read -er response
|
||||
|
||||
[[ "$response" != "y" && "$response" != "Y" && -n "$response" ]] && { log INFO "Exiting. Uninstall the script, then retry the install script." ; exit 1; }
|
||||
else
|
||||
log INFO "Successfully applied breaking changes patch for version $i."
|
||||
fi
|
||||
done
|
||||
log INFO ""
|
||||
fi
|
||||
|
||||
# install
|
||||
log INFO "Installing $SCRIPT_NAME to $DESTINATION_PATH."
|
||||
sudo curl "$REPO_URL"/h2mm --output "$DESTINATION_PATH/$SCRIPT_NAME"
|
||||
sudo chmod +x "$DESTINATION_PATH/$SCRIPT_NAME"
|
||||
log INFO ""
|
||||
|
||||
[[ ! -x "$(command -v $SCRIPT_NAME)" ]] && { log ERROR "Installation failed. Mod manager was not found in \$PATH." ; exit 1; }
|
||||
log INFO "Helldivers 2 Mod Manager CLI ${GREEN}successfully${NC} installed: $DESTINATION_PATH/$SCRIPT_NAME."
|
||||
|
||||
Reference in New Issue
Block a user