@@ -7,7 +7,7 @@ Helldivers 2 Mod Manager CLI is a command line interface for managing Helldivers
|
|||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
- [Available commands](#available-commands)
|
- [Available commands](#available-commands)
|
||||||
- [Basic usage](#basic-usage)
|
- [Basic usage](#basic-usage)
|
||||||
- [Install a mod](#install-a-mod)
|
- [Install mod(s)](#install-mods)
|
||||||
- [Uninstall a mod](#uninstall-a-mod)
|
- [Uninstall a mod](#uninstall-a-mod)
|
||||||
- [Enable/disable mods](#enabledisable-mods)
|
- [Enable/disable mods](#enabledisable-mods)
|
||||||
- [List installed mods](#list-installed-mods)
|
- [List installed mods](#list-installed-mods)
|
||||||
@@ -52,11 +52,12 @@ h2mm
|
|||||||
|
|
||||||
### Basic usage
|
### Basic usage
|
||||||
|
|
||||||
#### Install a mod
|
#### Install mod(s)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
h2mm install /path/to/mod.zip
|
h2mm install /path/to/mod.zip
|
||||||
h2mm install /path/to/mod/files
|
h2mm install /path/to/mod/files
|
||||||
|
h2mm install /path/to/mod.zip /path/to/mod2.zip /path/to/mod/files
|
||||||
h2mm install -n "Example mod" mod.patch_0 mod.patch_0.stream # -n is mandatory when using files
|
h2mm install -n "Example mod" mod.patch_0 mod.patch_0.stream # -n is mandatory when using files
|
||||||
h2mm install -n "Example mod" mod* # using a wildcard to include all files
|
h2mm install -n "Example mod" mod* # using a wildcard to include all files
|
||||||
```
|
```
|
||||||
@@ -89,7 +90,7 @@ h2mm list
|
|||||||
|
|
||||||
The script is developed and tested on Arch Linux, but it should work on other Linux distributions as well. If you encounter any issues, please open an issue on the repository.
|
The script is developed and tested on Arch Linux, but it should work on other Linux distributions as well. If you encounter any issues, please open an issue on the repository.
|
||||||
|
|
||||||
Status of other platforms:
|
Status of platforms:
|
||||||
|
|
||||||
- Linux :white_check_mark:
|
- Linux :white_check_mark:
|
||||||
- Steam Deck - untested (should work) :grey_question:
|
- Steam Deck - untested (should work) :grey_question:
|
||||||
@@ -141,10 +142,11 @@ Feel free to contribute to this project by creating a pull request or opening an
|
|||||||
|
|
||||||
- [x] Check for mod updates
|
- [x] Check for mod updates
|
||||||
- [x] Enable/disable mods
|
- [x] Enable/disable mods
|
||||||
- [ ] Install mods in batches
|
- [x] Install mods in batches
|
||||||
- [ ] Easier way to change mod presets
|
- [ ] Easier way to change mod presets
|
||||||
- [ ] Find a way to make use of `manifest.json` and simplify installing variants
|
- [ ] Find a way to make use of `manifest.json` and simplify installing variants
|
||||||
- [x] [DEV] Change to `.tar.gz` for exporting and importing
|
- [x] [DEV] Change to `.tar.gz` for exporting and importing
|
||||||
- [x] [DEV] Provide fixes for breaking updates
|
- [x] [DEV] Provide fixes for breaking updates
|
||||||
- [ ] [DEV] Optimize code - throw errors in 1 line
|
- [x] [DEV] Optimize code - throw errors in 1 line
|
||||||
|
- [ ] [DEV] Import/export treat breaking changes
|
||||||
- [ ] [DEV] Rewrite some code to be more readable
|
- [ ] [DEV] Rewrite some code to be more readable
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
VERSION="0.2.2"
|
VERSION="0.2.4"
|
||||||
|
|
||||||
# --- Globals ---
|
# --- Globals ---
|
||||||
|
|
||||||
@@ -20,19 +20,23 @@ REPO_URL="https://github.com/v4n00/h2mm-cli"
|
|||||||
# --- Utility Functions ---
|
# --- Utility Functions ---
|
||||||
|
|
||||||
function get_filename_without_path() {
|
function get_filename_without_path() {
|
||||||
echo $(echo "$1" | awk -F/ '{print $NF}')
|
echo "$1" | awk -F/ '{print $NF}'
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_basename() {
|
function get_basename() {
|
||||||
echo $(get_filename_without_path "$1" | sed -E 's/\.+.*//')
|
get_filename_without_path "$1" | sed -E 's/\.+.*//'
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_basename_with_patch_without_extension() {
|
||||||
|
echo "$1" | sed -E "s/(.*[0-9]+).*/\1/"
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_extension() {
|
function get_extension() {
|
||||||
echo $(get_filename_without_path "$1" | sed -E 's/.*patch_[0-9]+//')
|
get_filename_without_path "$1" | sed -E 's/.*patch_[0-9]+//'
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_files_by_entry_from_db() {
|
function get_files_by_entry_from_db() {
|
||||||
echo $(echo "$1" | cut -d',' -f4- | tr ',' ' ' | head -1)
|
echo "$1" | cut -d',' -f4- | tr ',' ' ' | head -1
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_mod_name_and_index() {
|
function get_mod_name_and_index() {
|
||||||
@@ -136,11 +140,12 @@ function display_install_help() {
|
|||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -n \"<mod_name>\" Name the mod yourself, inside double quotes."
|
echo " -n \"<mod_name>\" Name the mod yourself, inside double quotes."
|
||||||
echo " <mod_files> Multiple mod files, accepts wildcards."
|
echo " <mod_files> Multiple mod files, accepts wildcards."
|
||||||
echo " <mod_dir> Directory containing mod files."
|
echo " <mod_dirs> Directory/directories containing mod files."
|
||||||
echo " <mod_zip> Zip file containing mod files."
|
echo " <mod_zips> Zip file(s) containing mod files."
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo " h2mm install /path/to/mod.zip"
|
echo " h2mm install /path/to/mod.zip"
|
||||||
echo " h2mm install /path/to/mod/files"
|
echo " h2mm install /path/to/mod/files"
|
||||||
|
echo " h2mm install /path/to/mod.zip /path/to/mod2.zip /path/to/mod/files"
|
||||||
echo " h2mm install -n \"Example mod\" mod.patch_0 mod.patch_0.stream # -n is mandatory when using files"
|
echo " h2mm install -n \"Example mod\" mod.patch_0 mod.patch_0.stream # -n is mandatory when using files"
|
||||||
echo " h2mm install -n \"Example mod\" mod* # using a wildcard to include all files"
|
echo " h2mm install -n \"Example mod\" mod* # using a wildcard to include all files"
|
||||||
echo "If the mod has more than 1 variant, you need to install the one you want by unarchiving it separately."
|
echo "If the mod has more than 1 variant, you need to install the one you want by unarchiving it separately."
|
||||||
@@ -368,8 +373,9 @@ function mod_reset() {
|
|||||||
|
|
||||||
function mod_install() {
|
function mod_install() {
|
||||||
local mod_name=""
|
local mod_name=""
|
||||||
local mod_dir=""
|
local mod_dir=()
|
||||||
local mod_files=()
|
local mod_files=()
|
||||||
|
local mod_zip=()
|
||||||
|
|
||||||
[[ $# -eq 0 ]] && { display_install_help; exit 0; }
|
[[ $# -eq 0 ]] && { display_install_help; exit 0; }
|
||||||
|
|
||||||
@@ -384,9 +390,9 @@ function mod_install() {
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [[ -f "$1" && "$1" == *.zip ]]; then
|
if [[ -f "$1" && "$1" == *.zip ]]; then
|
||||||
mod_zip="$1"
|
mod_zip+=("$1")
|
||||||
elif [[ -d "$1" ]]; then
|
elif [[ -d "$1" ]]; then
|
||||||
mod_dir="$1"
|
mod_dir+=("$1")
|
||||||
else
|
else
|
||||||
mod_files+=("$1")
|
mod_files+=("$1")
|
||||||
fi
|
fi
|
||||||
@@ -395,27 +401,55 @@ function mod_install() {
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# zip file containing mod files
|
# edge case when there is a combination of mod zips and directories, call function for all zips and dirs
|
||||||
|
if [[ ${mod_zip} && ${mod_dir} ]]; then
|
||||||
|
mod_install "${mod_zip[@]}"
|
||||||
|
mod_install "${mod_dir[@]}"
|
||||||
|
|
||||||
|
# reset arrays
|
||||||
|
mod_zip=()
|
||||||
|
mod_dir=()
|
||||||
|
|
||||||
|
# if there are no more arguments, exit
|
||||||
|
[[ ${#mod_files[@]} -eq 0 ]] && exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if there's more than 1 zip, call recursively
|
||||||
|
while [[ ${#mod_zip[@]} -gt 1 ]]; do
|
||||||
|
mod_install "${mod_zip[0]}"
|
||||||
|
mod_zip=("${mod_zip[@]:1}")
|
||||||
|
done
|
||||||
|
|
||||||
|
# extract the zip file and pass it to mod dirs
|
||||||
if [[ -n "$mod_zip" ]]; then
|
if [[ -n "$mod_zip" ]]; then
|
||||||
command -v unzip &> /dev/null || { echo -e "${RED}Error${NC}: unzip package is not installed." >&2; exit 1; }
|
command -v unzip &> /dev/null || { echo -e "${RED}Error${NC}: unzip package is not installed." >&2; exit 1; }
|
||||||
|
|
||||||
[[ ! -f "$mod_zip" ]] && { echo -e "${RED}Error${NC}: Zip file $mod_zip does not exist." >&2; exit 1; }
|
[[ ! -f "$mod_zip" ]] && { echo -e "${RED}Error${NC}: Zip file $mod_zip does not exist." >&2; exit 1; }
|
||||||
|
|
||||||
# check if mod name was provided, otherwise use the zip file name, get rid of .zip and version numbers
|
# if the name is not specified, use the name of the directory, last sed for making nexusmods names not have numbers
|
||||||
if [[ -z "$mod_name" ]]; then
|
if [[ -z "$mod_name" ]]; then
|
||||||
mod_name=$(basename "$mod_zip" | sed -E 's/\.zip//' | awk -F/ '{print $NF}' | sed -E 's/-[0-9]+-.*//')
|
mod_name=$(basename "$mod_zip" | sed -E 's/\.zip//' | awk -F/ '{print $NF}' | sed -E 's/-[0-9]+-.*//')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mod_dir=$(mktemp -d)
|
# mod_dir as a temporary directory
|
||||||
|
mod_dir+=$(mktemp -d)
|
||||||
unzip -qq "$mod_zip" -d "$mod_dir"
|
unzip -qq "$mod_zip" -d "$mod_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# if there's more than 1 directory, call recursively
|
||||||
|
while [[ ${#mod_dir[@]} -gt 1 ]]; do
|
||||||
|
mod_install "${mod_dir[0]}"
|
||||||
|
mod_dir=("${mod_dir[@]:1}")
|
||||||
|
done
|
||||||
|
|
||||||
# directory containing mod files
|
# directory containing mod files
|
||||||
if [[ -n "$mod_dir" ]]; then
|
if [[ -n "$mod_dir" ]]; then
|
||||||
# verify directory exists
|
# verify directory exists
|
||||||
[[ ! -d "$mod_dir" ]] && { echo -e "${RED}Error${NC}: Directory $mod_dir does not exist." >&2; exit 1; }
|
[[ ! -d "$mod_dir" ]] && { echo -e "${RED}Error${NC}: Directory $mod_dir does not exist." >&2; exit 1; }
|
||||||
|
|
||||||
|
# read every file from the directory
|
||||||
readarray -d '' mod_files < <(find "$mod_dir" -type f -name "*.patch_*" -print0)
|
readarray -d '' mod_files < <(find "$mod_dir" -type f -name "*.patch_*" -print0)
|
||||||
|
# if the name is not specified, use the name of the directory, last sed for making nexusmods names not have numbers
|
||||||
if [[ -z "$mod_name" ]]; then
|
if [[ -z "$mod_name" ]]; then
|
||||||
mod_name=$(echo "$mod_dir" | sed 's:/*$::' | awk -F/ '{print $NF}' | sed -E 's/-[0-9]+-.*//')
|
mod_name=$(echo "$mod_dir" | sed 's:/*$::' | awk -F/ '{print $NF}' | sed -E 's/-[0-9]+-.*//')
|
||||||
fi
|
fi
|
||||||
@@ -424,14 +458,9 @@ function mod_install() {
|
|||||||
# verify minimum information required
|
# verify minimum information required
|
||||||
[[ -z "$mod_name" || ${#mod_files[@]} -eq 0 ]] && { echo -e "${RED}Error${NC}: Mod name and files are required." >&2; exit 1; }
|
[[ -z "$mod_name" || ${#mod_files[@]} -eq 0 ]] && { echo -e "${RED}Error${NC}: Mod name and files are required." >&2; exit 1; }
|
||||||
|
|
||||||
# verify mod files exist and is not directory
|
# verify mod files exist
|
||||||
for file in "${mod_files[@]}"; do
|
for file in "${mod_files[@]}"; do
|
||||||
if [[ ! -f "$file" ]]; then
|
[[ ! -f "$file" ]] && { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; }
|
||||||
# if it isn't a file, check if it's a directory
|
|
||||||
[[ ! -d "$file" ]] && { echo -e "${RED}Error${NC}: File $file does not exist." >&2; exit 1; }
|
|
||||||
|
|
||||||
mod_files=(${mod_files[@]/$file})
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# hash table - in case multiple named files are needed for 1 mod install, store the patch count
|
# hash table - in case multiple named files are needed for 1 mod install, store the patch count
|
||||||
@@ -444,15 +473,17 @@ function mod_install() {
|
|||||||
for file in "${mod_files[@]}"; do
|
for file in "${mod_files[@]}"; do
|
||||||
base_name=$(get_basename "$file")
|
base_name=$(get_basename "$file")
|
||||||
patch_prefix="$MODS_DIR/${base_name}.patch_"
|
patch_prefix="$MODS_DIR/${base_name}.patch_"
|
||||||
count=$(ls "${patch_prefix}"* 2>/dev/null | grep -E '([0-9]+$)' 2>/dev/null | wc -l) # count installed patches
|
# count already installed patches
|
||||||
|
count=$(ls "${patch_prefix}"* 2>/dev/null | grep -E '([0-9]+$)' 2>/dev/null | wc -l)
|
||||||
|
|
||||||
# set patch count for file name
|
# set patch count for file name if it doesn't exist yet
|
||||||
if [[ -z "${patch_count[$file]+unset}" ]]; then
|
if [[ -z "${patch_count[$file]+unset}" ]]; then
|
||||||
patch_count["$file"]=$count
|
patch_count["$file"]=$count
|
||||||
fi
|
fi
|
||||||
|
# if the file has an extension (e.g. .stream, .gpu_resources), set the last patch number for the next step
|
||||||
patch_count["$base_name"]=$count
|
patch_count["$base_name"]=$count
|
||||||
|
|
||||||
# if the file has an extension, look for the last patch number and use that
|
# if the file has an extension, look for the last patch number and use that, otherwise, the count will be wrong
|
||||||
extension=$(get_extension "$file")
|
extension=$(get_extension "$file")
|
||||||
if [[ -n "$extension" ]]; then
|
if [[ -n "$extension" ]]; then
|
||||||
target_file="${base_name}.patch_$((patch_count[$base_name] - 1))${extension}"
|
target_file="${base_name}.patch_$((patch_count[$base_name] - 1))${extension}"
|
||||||
@@ -495,56 +526,62 @@ function mod_uninstall() {
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z "$mod_name" && -z "$mod_index" ]]; then
|
[[ -z "$mod_name" && -z "$mod_index" ]] && { echo -e "${RED}Error${NC}: Mod name or index is required to uninstall." >&2; exit 1; }
|
||||||
echo -e "${RED}Error${NC}: Mod name or index is required to uninstall." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# find mod files
|
# find mod files
|
||||||
get_mod_name_and_index "$mod_name" "$mod_index"
|
get_mod_name_and_index "$mod_name" "$mod_index"
|
||||||
|
|
||||||
# delete mod files
|
# delete mod files
|
||||||
files=$(get_files_by_entry_from_db "$entry")
|
files=$(get_files_by_entry_from_db "$entry")
|
||||||
echo "$files"
|
declare -A downgrades_versions
|
||||||
declare -A downgrades
|
declare -A downgrades_to_remove
|
||||||
for file in $files; do
|
for file in $files; do
|
||||||
if [[ ! -f "$MODS_DIR/$file" ]]; then
|
[[ ! -f "$MODS_DIR/$file" ]] && { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; }
|
||||||
echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo -e "Removing ${ORANGE}\$MODS_DIR/$file${NC}." >&2
|
|
||||||
rm "$MODS_DIR/$file"
|
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
echo -e "Removing ${ORANGE}\$MODS_DIR/$file${NC}." >&2
|
||||||
echo -e "${RED}Error${NC}: Could not remove mod file $file." >&2
|
rm "$MODS_DIR/$file"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
base_name=$(get_basename "$file")
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not remove mod file $file." >&2; exit 1; }
|
||||||
current_version=$(echo $file | grep -oP '(?<=patch_)\d+')
|
|
||||||
downgrades["$base_name"]=$current_version
|
# save the basename for the files that were deleted into a hash table, so we can downgrade mods with greater version number
|
||||||
fi
|
# also depending on how many patches the mod has, we need to downgrade with more versions
|
||||||
|
current_version=$(echo $file | grep -oP '(?<=patch_)\d+')
|
||||||
|
base_name_with_patch=$(get_basename_with_patch_without_extension "$file")
|
||||||
|
base_name=$(get_basename "$file")
|
||||||
|
downgrades_versions["$base_name_with_patch"]=$current_version
|
||||||
|
[[ -z "${downgrades_to_remove["$base_name"]+unset}" ]] && downgrades_to_remove["$base_name"]=$(echo $files | sed -E "s/(.*[0-9]+).*/\1/" | wc -l)
|
||||||
done
|
done
|
||||||
|
|
||||||
# downgrade any necessary mods
|
# downgrade any necessary mods - it takes ~20 minutes to re-understand this code so I'm writing a comment here
|
||||||
for file in "${!downgrades[@]}"; do
|
# for each base name, find all files that have the same base name, and are greater than the current version, and downgrade them
|
||||||
|
# the downgrades_versions hash table stores the current version, so we can compare it with the version of the files
|
||||||
|
# the downgrades_to_remove hash table stores the number of patches the mod has, so we can downgrade with more versions
|
||||||
|
# for example, if we have:
|
||||||
|
# mod 1: AAA.patch_0 AAA.patch_0.stream AAA.patch_1 AAA.patch_1.stream
|
||||||
|
# mod 2: AAA.patch_2 AAA.patch_2.stream AAA.patch_3 AAA.patch_3.stream
|
||||||
|
# mod 3: AAA.patch_4 AAA.patch_4.stream AAA.patch_5 AAA.patch_5.stream
|
||||||
|
# if we remove mod 2, we need to downgrade mod 3 (which has version 4 and 5 > 3 (last patch removed)) by 2 versions,
|
||||||
|
# the number 2 we get by counting the number of unique base names (without extensions like .stream, but with the .patch_[0-9]) in the files
|
||||||
|
for base_name in "${!downgrades_to_remove[@]}"; do
|
||||||
# find all files that have the same base name, and are greater than the current version, and downgrade them
|
# find all files that have the same base name, and are greater than the current version, and downgrade them
|
||||||
base_name=$(get_basename "$file")
|
IFS=$'\n' mods_to_remove=($(ls "$MODS_DIR/$base_name"* 2>/dev/null | sort -V)); unset IFS
|
||||||
same_patches=$(ls "$MODS_DIR/${base_name}.patch_"* 2>/dev/null)
|
base_name_with_patch=$(get_basename_with_patch_without_extension "$file")
|
||||||
|
|
||||||
for patch in $same_patches; do
|
for mod in "${mods_to_remove[@]}"; do
|
||||||
patch=$(get_filename_without_path "$patch")
|
mod=$(get_filename_without_path "$mod")
|
||||||
patch_version=$(echo $patch | grep -oP '(?<=patch_)\d+')
|
patch_version=$(echo $mod | grep -oP '(?<=patch_)\d+')
|
||||||
if [[ $patch_version -gt ${downgrades[$file]} ]]; then
|
if [[ $patch_version -gt ${downgrades_versions[$base_name_with_patch]} ]]; then
|
||||||
new_version=$((patch_version - downgrades[$base_name] - 1))
|
new_version=$((patch_version - downgrades_to_remove["$base_name"] - 1))
|
||||||
extension=$(get_extension "$path")
|
extension=$(get_extension "$mod")
|
||||||
|
|
||||||
new_patch="${base_name}.patch_${new_version}${extension}"
|
new_patch="${base_name}.patch_${new_version}${extension}"
|
||||||
mv "$MODS_DIR/$patch" "$MODS_DIR/$new_patch"
|
mv "$MODS_DIR/$mod" "$MODS_DIR/$new_patch"
|
||||||
echo -e "Downgraded ${ORANGE}$patch${NC} to ${GREEN}\$MODS_DIR/$new_patch${NC}." >&2
|
|
||||||
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not downgrade mod file $mod." >&2; exit 1; }
|
||||||
|
echo -e "Downgraded ${ORANGE}$mod${NC} to ${GREEN}\$MODS_DIR/$new_patch${NC}." >&2
|
||||||
|
|
||||||
# save changes in database as well
|
# save changes in database as well
|
||||||
sed -i "s/$patch/$new_patch/" "$DB_FILE"
|
sed -i "s/$mod/$new_patch/" "$DB_FILE"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
@@ -556,17 +593,12 @@ function mod_uninstall() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mod_list() {
|
function mod_list() {
|
||||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
[[ "$1" == "--help" || "$1" == "-h" ]] && { display_list_help; exit 0; }
|
||||||
display_list_help
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -s "$DB_FILE" ]]; then
|
[[ ! -s "$DB_FILE" ]] && { echo "No mods installed."; return; }
|
||||||
echo "No mods installed."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Installed mods:" >&2
|
echo "Installed mods:" >&2
|
||||||
|
|
||||||
awk -v GREEN="$GREEN" -v RED="$RED" -v NC="$NC" -F, '{
|
awk -v GREEN="$GREEN" -v RED="$RED" -v NC="$NC" -F, '{
|
||||||
color = ($2 == "DISABLED") ? RED : GREEN;
|
color = ($2 == "DISABLED") ? RED : GREEN;
|
||||||
if (length($4) > 150) $4 = substr($4, 1, 147) "...";
|
if (length($4) > 150) $4 = substr($4, 1, 147) "...";
|
||||||
@@ -574,87 +606,66 @@ function mod_list() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mod_export() {
|
function mod_export() {
|
||||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
[[ "$1" == "--help" || "$1" == "-h" ]] && { display_export_help; exit 0; }
|
||||||
display_export_help
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -ne "Archive file will be saved in the current directory ($(pwd)). Continue? (Y/n): "
|
echo -ne "Archive file will be saved in the current directory ($(pwd)). Continue? (Y/n): "
|
||||||
read -r confirm
|
read -r confirm
|
||||||
if [[ "$confirm" == "y" || "$confirm" == "Y" || "$confirm" = "" ]]; then
|
if [[ "$confirm" == "y" || "$confirm" == "Y" || "$confirm" = "" ]]; then
|
||||||
|
# create a temporary directory to store the mods
|
||||||
OUT_DIR=$(mktemp -d)
|
OUT_DIR=$(mktemp -d)
|
||||||
MODS_EXPORT_DIR="$OUT_DIR/Helldivers 2 Mods"
|
MODS_EXPORT_DIR="$OUT_DIR/Helldivers 2 Mods"
|
||||||
mkdir -p "$MODS_EXPORT_DIR"
|
mkdir -p "$MODS_EXPORT_DIR"
|
||||||
cp "$DB_FILE" "$MODS_EXPORT_DIR"
|
cp "$DB_FILE" "$MODS_EXPORT_DIR"
|
||||||
|
|
||||||
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not copy mods to target directory." >&2; exit 1; }
|
||||||
|
|
||||||
|
# copy all mod files to the export directory
|
||||||
for file in $(ls "$MODS_DIR/" 2>/dev/null | grep -E 'patch_.*'); do
|
for file in $(ls "$MODS_DIR/" 2>/dev/null | grep -E 'patch_.*'); do
|
||||||
cp "$MODS_DIR/$file" "$MODS_EXPORT_DIR"
|
cp "$MODS_DIR/$file" "$MODS_EXPORT_DIR"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not export mods. Possibly because no mods are present." >&2; exit 1; }
|
||||||
echo -e "${RED}Error${NC}: Could not export mods. Possibly because no mods are present." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# zip up the mods with the current date and time in the name
|
||||||
current_path=$(pwd)
|
current_path=$(pwd)
|
||||||
archive_name="Helldivers_2_Mods_$(date +%Y-%m-%d_%H-%M-%S).tar.gz"
|
archive_name="Helldivers_2_Mods_$(date +%Y-%m-%d_%H-%M-%S).tar.gz"
|
||||||
tar -czf "$current_path/$archive_name" -C "$OUT_DIR" "Helldivers 2 Mods"
|
tar -czf "$current_path/$archive_name" -C "$OUT_DIR" "Helldivers 2 Mods"
|
||||||
|
|
||||||
if [[ $? -eq 0 ]]; then
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Failed to export mods." >&2; exit 1; }
|
||||||
echo -e "Mods exported to ${GREEN}$current_path/$archive_name${NC}." >&2
|
echo -e "Mods exported to ${GREEN}$current_path/$archive_name${NC}." >&2
|
||||||
else
|
|
||||||
echo -e "${RED}Error${NC}: Failed to export mods." >&2
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function mod_import() {
|
function mod_import() {
|
||||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
[[ "$1" == "--help" || "$1" == "-h" ]] && { display_import_help; exit 0; }
|
||||||
display_import_help
|
[[ ! -f "$1" ]] && { echo -e "${RED}Error${NC}: File $1 does not exist." >&2; exit 1; }
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -f "$1" ]]; then
|
|
||||||
echo -e "${RED}Error${NC}: File $1 does not exist." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# reset mods before importing
|
||||||
echo -e "Importing mods will ${RED}reset${NC} your mods." >&2
|
echo -e "Importing mods will ${RED}reset${NC} your mods." >&2
|
||||||
mod_reset
|
mod_reset
|
||||||
if [[ $? -eq 1 ]]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
[[ $? -eq 1 ]] && exit 1
|
||||||
|
|
||||||
|
# extract in temp directory
|
||||||
OUT_DIR=$(mktemp -d)
|
OUT_DIR=$(mktemp -d)
|
||||||
tar -xzf "$1" -C "$OUT_DIR"
|
tar -xzf "$1" -C "$OUT_DIR"
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not import mods. Possibly because the zip file is invalid." >&2; exit 1; }
|
||||||
echo -e "${RED}Error${NC}: Could not import mods. Possibly because the zip file is invalid." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
MODS_EXPORT_DIR="$OUT_DIR/Helldivers 2 Mods"
|
MODS_EXPORT_DIR="$OUT_DIR/Helldivers 2 Mods"
|
||||||
if [[ ! -d "$MODS_EXPORT_DIR" ]]; then
|
[[ ! -d "$MODS_EXPORT_DIR" ]] && { echo -e "${RED}Error${NC}: Could not import mods. Possibly because the zip file is invalid." >&2; exit 1; }
|
||||||
echo -e "${RED}Error${NC}: Could not import mods. Possibly because the zip file is invalid." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# copy mods verbosely
|
# copy mods verbosely
|
||||||
cp -v "$MODS_EXPORT_DIR"/* "$MODS_DIR"
|
cp -v "$MODS_EXPORT_DIR"/* "$MODS_DIR"
|
||||||
if [[ $? -eq 0 ]]; then
|
|
||||||
echo -e "Mods imported ${GREEN}successfully${NC}." >&2
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Failed to import mods." >&2; exit 1; }
|
||||||
else
|
echo -e "Mods imported ${GREEN}successfully${NC}." >&2
|
||||||
echo -e "${RED}Error${NC}: Failed to import mods." >&2
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Main ---
|
# --- Main ---
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
if [[ $# -lt 1 ]]; then
|
[[ $# -lt 1 ]] && { display_help; exit 1; }
|
||||||
display_help
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
command="$1"
|
command="$1"
|
||||||
shift
|
shift
|
||||||
|
|||||||
+7
-1
@@ -56,6 +56,8 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
|
|||||||
|
|
||||||
if [[ $latest_major -gt $installed_major ]]; then
|
if [[ $latest_major -gt $installed_major ]]; then
|
||||||
echo -e "${ORANGE}Warning:${NC} Major version upgrade detected."
|
echo -e "${ORANGE}Warning:${NC} Major version upgrade detected."
|
||||||
|
echo "Check out the changelogs here:"
|
||||||
|
echo "https://github.com/v4n00/h2mm-cli/releases"
|
||||||
echo "The script will proceed to upgrade ${SCRIPT_NAME} to avoid breaking changes."
|
echo "The script will proceed to upgrade ${SCRIPT_NAME} to avoid breaking changes."
|
||||||
|
|
||||||
# find hd2 path
|
# find hd2 path
|
||||||
@@ -83,7 +85,11 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
|
|||||||
for ((i = installed_major + 1; i <= latest_major; i++)); do
|
for ((i = installed_major + 1; i <= latest_major; i++)); do
|
||||||
echo -e "Applying breaking changes patch for version $i."
|
echo -e "Applying breaking changes patch for version $i."
|
||||||
|
|
||||||
[[ -n "${breaking_changes_patches[$i]}" ]] && eval $(echo "${breaking_changes_patches[$i]}" | sed "s:\$1:$game_dir:")
|
if [[ -n "${breaking_changes_patches[$i]}" ]]; then
|
||||||
|
eval $(echo "${breaking_changes_patches[$i]}" | sed "s:\$1:$game_dir:")
|
||||||
|
else
|
||||||
|
echo "No breaking changes for version $i."
|
||||||
|
fi
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
echo -ne "${RED}Error:${NC} Failed to apply breaking changes patch for version $i. Do you want to continue? (Y/n): "
|
echo -ne "${RED}Error:${NC} Failed to apply breaking changes patch for version $i. Do you want to continue? (Y/n): "
|
||||||
read -er response
|
read -er response
|
||||||
|
|||||||
Reference in New Issue
Block a user