From 740b0edd9802101843d9e7bb02d296e7b658abd7 Mon Sep 17 00:00:00 2001 From: v4n <105587619+v4n00@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:08:34 +0200 Subject: [PATCH 1/4] fix: docs for help, backup before upgrading script --- h2mm | 24 +++++++++++++----------- install.sh | 9 +++++++-- version | 2 +- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/h2mm b/h2mm index c0e42d7..a2d884e 100755 --- a/h2mm +++ b/h2mm @@ -1,6 +1,6 @@ #!/bin/bash -VERSION="0.2.0" +VERSION="0.2.1" # --- Globals --- @@ -115,17 +115,19 @@ function display_help() { echo "Helldivers 2 Mod Manager v${VERSION}" echo "Usage: h2mm [command] [options]" echo "Commands:" - echo " install Install a mod with files (short form: h2mm i)." - echo " uninstall Uninstall a mod by name (short form: h2mm u)." - echo " list List all installed mods (short form: h2mm l)." - echo " export Export installed mods to a zip file (short form: h2mm ex)." - echo " import Import mods from a zip file (short form: h2mm im)." - echo " reset Reset all installed mods (short form: h2mm rr)." - echo " help Display this help message (short form: h2mm h)." + echo " install Install a mod with files." + echo " uninstall Uninstall a mod by name." + echo " list List all installed mods." + echo " enable Enable a mod by name." + echo " disable Disable a mod by name." + echo " export Export installed mods to a zip file." + echo " import Import mods from a zip file." + echo " reset Reset all installed mods." + echo " help Display this help message." echo "For more information on usage, use h2mm [command] --help, available for install and uninstall." echo "Basic Usage:" - echo " h2mm install -z /path/to/mod.zip" - echo " h2mm install -d /path/to/mod/files" + echo " h2mm install /path/to/mod.zip" + echo " h2mm install /path/to/mod/files" echo " h2mm uninstall \"Example mod\"" } @@ -568,7 +570,7 @@ function mod_list() { echo "Installed mods:" >&2 awk -v GREEN="$GREEN" -v RED="$RED" -v NC="$NC" -F, '{ color = ($2 == "DISABLED") ? RED : GREEN; - if (length($3) > 150) $3 = substr($3, 1, 147) "..."; + if (length($4) > 150) $4 = substr($4, 1, 147) "..."; printf "%2s. [%s%s%s] %s (%s)\n", $1, color, $2, NC, $3, $4}' "$DB_FILE" } diff --git a/install.sh b/install.sh index f098826..bdf2e41 100755 --- a/install.sh +++ b/install.sh @@ -75,10 +75,14 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then fi [[ ! -f "$game_dir/mods.csv" ]] && { echo -e "${RED}Error:${NC} mods.csv not found in $game_dir."; exit 1; } + + # make backup of mods in case something goes wrong + echo "Creating a backup of mods.csv." + h2mm export # iterate from installed major number to latest major number for ((i = installed_major + 1; i <= latest_major; i++)); do - echo -e "${RED}[ ]${NC} 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 [[ $? -ne 0 ]]; then @@ -87,10 +91,11 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then [[ "$response" != "y" && "$response" != "Y" && -n "$response" ]] && { echo "Exiting. Uninstall the script first the retry the install script."; exit 1; } else - echo -e "${GREEN}[X]${NC} Breaking changes patch for version $i applied successfully." + echo -e "Breaking changes patch for version $i applied ${GREEN}successfully${NC}." fi done fi + echo fi # Install diff --git a/version b/version index 341cf11..7dff5b8 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.2.0 \ No newline at end of file +0.2.1 \ No newline at end of file From c80812476b334785d9bbbda2e863e8dd2ab77aca Mon Sep 17 00:00:00 2001 From: v4n <105587619+v4n00@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:36:27 +0200 Subject: [PATCH 2/4] docs: updated --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 2bd3204..ff9a7af 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ h2mm - `install` - Install a mod with files - `uninstall` - Uninstall a mod by name - `list` - List all installed mods +- `enable` - Enable a mod by name +- `disable` - Disable a mod by name - `export ` - Export installed mods to a zip file - `import ` - Import mods from a zip file - `reset` - Reset all installed mods @@ -127,6 +129,7 @@ Feel free to contribute to this project by creating a pull request or opening an - [x] Check for mod updates - [x] Enable/disable mods +- [ ] Install mods in batches - [ ] Easier way to change mod presets - [ ] Find a way to make use of `manifest.json` and simplify installing variants - [x] [DEV] Change to `.tar.gz` for exporting and importing From f9c047078d031275fe117e9e32675f11d7096b3d Mon Sep 17 00:00:00 2001 From: v4n <105587619+v4n00@users.noreply.github.com> Date: Fri, 17 Jan 2025 10:06:13 +0200 Subject: [PATCH 3/4] docs: update, install timeout --- README.md | 20 +++++++++++++++----- install.sh | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ff9a7af..3bb0dc2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Helldivers 2 Mod Manager CLI +Helldivers 2 Mod Manager CLI is a command line interface for managing Helldivers 2 mods. Since there is no Linux mod manager available and I like being a nerd by using CLI tools instead of GUIs, this project was born. + - [Helldivers 2 Mod Manager CLI](#helldivers-2-mod-manager-cli) - [Installation](#installation) - [Usage](#usage) @@ -9,6 +11,7 @@ - [Uninstall a mod](#uninstall-a-mod) - [Enable/disable mods](#enabledisable-mods) - [List installed mods](#list-installed-mods) + - [Compatibility](#compatibility) - [Advanced usage](#advanced-usage) - [Shortcuts](#shortcuts) - [Exporting and importing](#exporting-and-importing) @@ -17,8 +20,6 @@ - [Contributing](#contributing) - [Planned features](#planned-features) -Helldivers 2 Mod Manager CLI is a command line interface for managing Helldivers 2 mods. Since there is no mod manager GUI for Helldivers 2 on Linux yet, this small script aims to provide a simple way to manage mods on Linux. - ## Installation To install/update Helldivers 2 Mod Manager CLI run the following command in your terminal: @@ -44,8 +45,8 @@ h2mm - `list` - List all installed mods - `enable` - Enable a mod by name - `disable` - Disable a mod by name -- `export ` - Export installed mods to a zip file -- `import ` - Import mods from a zip file +- `export` - Export installed mods to a zip file +- `import` - Import mods from a zip file - `reset` - Reset all installed mods - `help` - Display the help message @@ -69,7 +70,6 @@ h2mm uninstall "Example mod" h2mm uninstall -i 1 # uninstall mod with index 1 ``` - #### Enable/disable mods ```bash @@ -85,6 +85,16 @@ h2mm disable -i 1 # disable mod with index 1 h2mm list ``` +## Compatibility + +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: + +- Linux :white_check_mark: +- Steam Deck - Untested :grey_question: +- WSL - Untested, should work :grey_question: + ## Advanced usage ### Shortcuts diff --git a/install.sh b/install.sh index bdf2e41..9cfee0e 100755 --- a/install.sh +++ b/install.sh @@ -61,8 +61,8 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then # find hd2 path search_dir="${HOME}" target_dir="Steam/steamapps/common/Helldivers\ 2/data" - echo "Searching for the Helldivers 2 data directory..." >&2 - game_dir=$(find "$search_dir" -type d -path "*/$target_dir" 2>/dev/null | head -n 1) + echo "Searching for the Helldivers 2 data directory... (20 seconds timeout)" >&2 + game_dir=$(timeout 20 find "$search_dir" -type d -path "*/$target_dir" 2>/dev/null | head -n 1) if [[ -z "$game_dir" ]]; then echo "Could not find the Helldivers 2 data directory automatically." >&2 read -p "Please enter the path to the Helldivers 2 data directory: " game_dir From 911a9b86ffe8dd3812fffa0e612c895b675eed48 Mon Sep 17 00:00:00 2001 From: v4n <105587619+v4n00@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:41:18 +0200 Subject: [PATCH 4/4] compatibility: easier for WSL, read now accepts autocompletion --- README.md | 8 ++-- h2mm | 113 ++++++++++++++++++++++++++--------------------------- install.sh | 29 +++++++------- version | 2 +- 4 files changed, 76 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 3bb0dc2..190749b 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Helldivers 2 Mod Manager CLI is a command line interface for managing Helldivers To install/update Helldivers 2 Mod Manager CLI run the following command in your terminal: ```bash -sh -c "$(curl -fsSL https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh)" +bash -c "$(curl -fsSL https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh)" ``` Running this script will require sudo permissions. **DO NOT TRUST** random scripts from the internet. If you want to review the script before running it, check out the mod repository for yourself. @@ -92,8 +92,10 @@ The script is developed and tested on Arch Linux, but it should work on other Li Status of other platforms: - Linux :white_check_mark: -- Steam Deck - Untested :grey_question: -- WSL - Untested, should work :grey_question: +- Steam Deck - untested (should work) :grey_question: +- WSL :white_check_mark: + +> The script works on WSL, but you need to specify the path to the Helldivers 2 mods directory manually, to find your Windows partition head to `/mnt/` and from there go to your Helldivers 2 data directory, on a typical install it should be on `/mnt/c/Program\ Files\ \(x86\)/Steam/steamapps/common/Helldivers\ 2/data`. You also need to have `unzip` installed, which can be done by running `sudo apt install unzip`. ## Advanced usage diff --git a/h2mm b/h2mm index a2d884e..5d4e560 100755 --- a/h2mm +++ b/h2mm @@ -1,6 +1,6 @@ #!/bin/bash -VERSION="0.2.1" +VERSION="0.2.2" # --- Globals --- @@ -73,8 +73,7 @@ function find_game_directory() { if [[ -z "$game_dir" ]]; then echo "Could not find the Helldivers 2 data directory automatically." >&2 - read -p "Please enter the path to the Helldivers 2 data directory: " game_dir - game_dir=$(eval echo "$game_dir") + IFS= read -ep "Please enter the path to the Helldivers 2 data directory: " game_dir if [[ ! -d "$game_dir" ]]; then echo -e "${RED}Error${NC}: Provided path is not a valid directory." >&2 exit 1 @@ -212,7 +211,7 @@ function display_import_help() { function check_for_updates() { if [[ -f "$LAST_CHECKED_UPDATE_FILE" ]]; then last_update=$(cat "$LAST_CHECKED_UPDATE_FILE") - if [[ $(date +%Y-%m-%d) -gt $(date +%Y-%m-%d -d "$last_update + 7 days") ]]; then + if [[ $(date +%Y-%m-%d) -gt $(date +%Y-%m-%d -d "$last_update + 3 days") ]]; then return fi else @@ -295,38 +294,38 @@ function mod_disable() { } function mod_enable() { - local mod_name="" - local mod_index="" + local mod_name="" + local mod_index="" - [[ $# -eq 0 ]] && { display_enable_help; exit 0; } + [[ $# -eq 0 ]] && { display_enable_help; exit 0; } - # parse arguments - while [[ $# -gt 0 ]]; do - case "$1" in - -i) - mod_index="$2"; shift 2 - ;; - --help|-h) - display_enable_help; exit 0 - ;; - *) - mod_name="$1"; shift 1 - ;; - esac - done + # parse arguments + while [[ $# -gt 0 ]]; do + case "$1" in + -i) + mod_index="$2"; shift 2 + ;; + --help|-h) + display_enable_help; exit 0 + ;; + *) + mod_name="$1"; shift 1 + ;; + esac + done - [[ -z "$mod_name" && -z "$mod_index" ]] && { echo -e "${RED}Error${NC}: Mod name or index is required to enable." >&2; exit 1; } + [[ -z "$mod_name" && -z "$mod_index" ]] && { echo -e "${RED}Error${NC}: Mod name or index is required to enable." >&2; exit 1; } - # find mod files + # find mod files get_mod_name_and_index "$mod_name" "$mod_index" [[ "$status" == "ENABLED" ]] && { echo -e "${RED}Error${NC}: Mod $mod_name is already enabled." >&2; exit 1; } - files=$(get_files_by_entry_from_db "$entry") + files=$(get_files_by_entry_from_db "$entry") - # enable each mod file by removing disabled_ from the start of the filename - for file in $files; do - disabled_file="disabled_$file" + # enable each mod file by removing disabled_ from the start of the filename + for file in $files; do + disabled_file="disabled_$file" # check if the files exists [[ -f "$MODS_DIR/$disabled_file" ]] || { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; } @@ -336,17 +335,17 @@ function mod_enable() { # check if the file was moved successfully [[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not enable mod file $disabled_file." >&2; exit 1; } echo -e "Enabled ${ORANGE}$disabled_file${NC} (changed to ${GREEN}\$MODS_DIR/$file${NC})." >&2 - done + done - # update the database - sed -i "/^$mod_index,/s/DISABLED/ENABLED/" "$DB_FILE" + # update the database + sed -i "/^$mod_index,/s/DISABLED/ENABLED/" "$DB_FILE" - if [[ $? -eq 0 ]]; then - echo -e "Mod $mod_name ${GREEN}enabled${NC} successfully." >&2 - else - echo -e "${RED}Error${NC}: Failed to enable mod." >&2 - exit 1 - fi + if [[ $? -eq 0 ]]; then + echo -e "Mod $mod_name ${GREEN}enabled${NC} successfully." >&2 + else + echo -e "${RED}Error${NC}: Failed to enable mod." >&2 + exit 1 + fi } function mod_reset() { @@ -377,23 +376,23 @@ function mod_install() { # parse arguments while [[ $# -gt 0 ]]; do case "$1" in - -n) - mod_name="$2"; shift 2 - ;; - --help|-h) - display_install_help; exit 0 - ;; - *) - if [[ -f "$1" && "$1" == *.zip ]]; then - mod_zip="$1" - elif [[ -d "$1" ]]; then - mod_dir="$1" - else - mod_files+=("$1") - fi - shift - ;; - esac + -n) + mod_name="$2"; shift 2 + ;; + --help|-h) + display_install_help; exit 0 + ;; + *) + if [[ -f "$1" && "$1" == *.zip ]]; then + mod_zip="$1" + elif [[ -d "$1" ]]; then + mod_dir="$1" + else + mod_files+=("$1") + fi + shift + ;; + esac done # zip file containing mod files @@ -569,9 +568,9 @@ function mod_list() { echo "Installed mods:" >&2 awk -v GREEN="$GREEN" -v RED="$RED" -v NC="$NC" -F, '{ - color = ($2 == "DISABLED") ? RED : GREEN; - if (length($4) > 150) $4 = substr($4, 1, 147) "..."; - printf "%2s. [%s%s%s] %s (%s)\n", $1, color, $2, NC, $3, $4}' "$DB_FILE" + color = ($2 == "DISABLED") ? RED : GREEN; + if (length($4) > 150) $4 = substr($4, 1, 147) "..."; + printf "%2s. [%s%s%s] %s (%s)\n", $1, color, $2, NC, $3, $4}' "$DB_FILE" } function mod_export() { @@ -581,7 +580,7 @@ function mod_export() { fi 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 OUT_DIR=$(mktemp -d) MODS_EXPORT_DIR="$OUT_DIR/Helldivers 2 Mods" diff --git a/install.sh b/install.sh index 9cfee0e..6eefbfa 100755 --- a/install.sh +++ b/install.sh @@ -34,7 +34,7 @@ breaking_changes_patches=( ["2"]='sed -i "s/^\([0-9]\+\),/\1,ENABLED,/" "$1/mods.csv"' ) -# Script +# Handle breaking changes if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then installed_version=$($SCRIPT_NAME --version) @@ -62,17 +62,16 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then search_dir="${HOME}" target_dir="Steam/steamapps/common/Helldivers\ 2/data" echo "Searching for the Helldivers 2 data directory... (20 seconds timeout)" >&2 + game_dir=$(timeout 20 find "$search_dir" -type d -path "*/$target_dir" 2>/dev/null | head -n 1) if [[ -z "$game_dir" ]]; then - echo "Could not find the Helldivers 2 data directory automatically." >&2 - read -p "Please enter the path to the Helldivers 2 data directory: " game_dir - game_dir=$(eval echo "$game_dir") - - if [[ ! -d "$game_dir" ]]; then - echo -e "${RED}Error${NC}: Provided path is not a valid directory." >&2 - exit 1 - fi - fi + echo "Could not find the Helldivers 2 data directory automatically." >&2 + IFS= read -ep "Please enter the path to the Helldivers 2 data directory: " game_dir + if [[ ! -d "$game_dir" ]]; then + echo -e "${RED}Error${NC}: Provided path is not a valid directory." >&2 + exit 1 + fi + fi [[ ! -f "$game_dir/mods.csv" ]] && { echo -e "${RED}Error:${NC} mods.csv not found in $game_dir."; exit 1; } @@ -87,11 +86,11 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then [[ -n "${breaking_changes_patches[$i]}" ]] && eval $(echo "${breaking_changes_patches[$i]}" | sed "s:\$1:$game_dir:") 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): " - read -r response + read -er response [[ "$response" != "y" && "$response" != "Y" && -n "$response" ]] && { echo "Exiting. Uninstall the script first the retry the install script."; exit 1; } else - echo -e "Breaking changes patch for version $i applied ${GREEN}successfully${NC}." + echo -e "Breaking changes patch for version ${ORANGE}$i${NC} applied ${GREEN}successfully${NC}." fi done fi @@ -100,12 +99,12 @@ fi # Install -read -p "Install the script to $DESTINATION_PATH or specify another path (must be included in \$PATH)? (Y/path): " response +IFS= read -ep "Install the script to $DESTINATION_PATH or specify another path (must be included in \$PATH)? (Y/path): " response if [[ "$response" != "y" && "$response" != "Y" && -n "$response" ]]; then - DESTINATION_PATH=$(eval echo "$response") + DESTINATION_PATH="$response" if [[ ! -d "$DESTINATION_PATH" ]]; then - echo -e "${RED}Error:${NC} Path $DESTINATION_PATH does not exist. Exiting..." + echo -e "${RED}Error:${NC} Path $DESTINATION_PATH does not exist." exit 1 fi fi diff --git a/version b/version index 7dff5b8..f477849 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.2.1 \ No newline at end of file +0.2.2 \ No newline at end of file