Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 55f382a8e5 | |||
| c1785b5323 | |||
| 115e8acac3 | |||
| 8b06d76c31 | |||
| fc7ccc2f7c | |||
| f763d96797 | |||
| 83260e9961 | |||
| 36fc676ce0 | |||
| 911a9b86ff | |||
| f9c047078d | |||
| c80812476b | |||
| 740b0edd98 | |||
| cc91661663 |
@@ -1,135 +1,155 @@
|
|||||||
# Helldivers 2 Mod Manager CLI
|
# Helldivers 2 Mod Manager CLI
|
||||||
|
|
||||||
- [Helldivers 2 Mod Manager CLI](#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.
|
||||||
- [Installation](#installation)
|
|
||||||
- [Usage](#usage)
|
This script is complete, the version will always [remain at 0.x.x](https://0ver.org/)
|
||||||
- [Available commands](#available-commands)
|
|
||||||
- [Basic usage](#basic-usage)
|
## Installation and updating
|
||||||
- [Install a mod](#install-a-mod)
|
|
||||||
- [Uninstall a mod](#uninstall-a-mod)
|
To install/update Helldivers 2 Mod Manager CLI run the following command in your terminal:
|
||||||
- [Enable/disable mods](#enabledisable-mods)
|
|
||||||
- [List installed mods](#list-installed-mods)
|
```bash
|
||||||
- [Advanced usage](#advanced-usage)
|
bash -c "$(curl -fsSL https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh)"
|
||||||
- [Shortcuts](#shortcuts)
|
```
|
||||||
- [Exporting and importing](#exporting-and-importing)
|
|
||||||
- [Resetting all installed mods](#resetting-all-installed-mods)
|
> [!CAUTION]
|
||||||
- [Database location and details](#database-location-and-details)
|
> 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.
|
||||||
- [Contributing](#contributing)
|
|
||||||
- [Planned features](#planned-features)
|
If for some reason, the installation command doesn't work you can:
|
||||||
|
1. Go to https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh
|
||||||
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.
|
1. Right click -> Save page as...
|
||||||
|
1. Go to your downloads folders `cd ~/Downloads`
|
||||||
## Installation
|
1. Give the script execution permissions `chmod +x install.sh`
|
||||||
|
1. Run the script `./install.sh`
|
||||||
To install/update Helldivers 2 Mod Manager CLI run the following command in your terminal:
|
|
||||||
|
## Usage
|
||||||
```bash
|
|
||||||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh)"
|
The script gets added to `/usr/local/bin/h2mm` and can be used by running `h2mm` in your shell, which will show the help message explaining how to use the script.
|
||||||
```
|
|
||||||
|
```bash
|
||||||
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.
|
h2mm
|
||||||
|
```
|
||||||
## Usage
|
|
||||||
|
### Available commands
|
||||||
The script gets added to `/usr/local/bin/h2mm` and can be used by running `h2mm` in your shell, which will show the help message explaining how to use the script.
|
|
||||||
|
- `install` - Install a mod by the file provided (directory, zip, patch).
|
||||||
```bash
|
- `uninstall` - Uninstall a mod by name (or index).
|
||||||
h2mm
|
- `list` - List all installed mods.
|
||||||
```
|
- `enable` - Enable a mod by name (or index).
|
||||||
|
- `disable` - Disable a mod by name (or index).
|
||||||
### Available commands
|
- `export` - Export installed mods to a zip file.
|
||||||
|
- `import` - Import mods from a zip file.
|
||||||
- `install` - Install a mod with files
|
- `modpack-create` - Create a modpack from the currently installed mods.
|
||||||
- `uninstall` - Uninstall a mod by name
|
- `modpack-switch` - Switch to a modpack by name (or index).
|
||||||
- `list` - List all installed mods
|
- `modpack-list` - List all installed modpacks.
|
||||||
- `export <zip_name>` - Export installed mods to a zip file
|
- `modpack-delete` - Delete a modpack by name (or index).
|
||||||
- `import <zip_name>` - Import mods from a zip file
|
- `modpack-overwrite` - Overwrite a modpack by name (or index).
|
||||||
- `reset` - Reset all installed mods
|
- `modpack-reset` - Reset all installed modpacks.
|
||||||
- `help` - Display the help message
|
- `reset` - Reset all installed mods.
|
||||||
|
- `help` - Display this help message.
|
||||||
### Basic usage
|
|
||||||
|
### Basic usage
|
||||||
#### Install a mod
|
|
||||||
|
#### Install mod(s)
|
||||||
```bash
|
|
||||||
h2mm install /path/to/mod.zip
|
```bash
|
||||||
h2mm install /path/to/mod/files
|
h2mm install /path/to/mod.zip
|
||||||
h2mm install -n "Example mod" mod.patch_0 mod.patch_0.stream # -n is mandatory when using files
|
h2mm install /path/to/mod/files
|
||||||
h2mm install -n "Example mod" mod* # using a wildcard to include all 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* # using a wildcard to include all files
|
||||||
> Currently, if the mod has more than 1 variant, you need to install the one you want by unarchiving it separately.
|
```
|
||||||
|
|
||||||
#### Uninstall a mod
|
> [!NOTE]
|
||||||
|
> If the mod has more than 1 variant, you need to install the one you want by unarchiving it separately and providing the directory.
|
||||||
```bash
|
|
||||||
h2mm uninstall "Example mod"
|
#### Uninstall a mod
|
||||||
h2mm uninstall -i 1 # uninstall mod with index 1
|
|
||||||
```
|
```bash
|
||||||
|
h2mm uninstall "Example mod"
|
||||||
|
h2mm uninstall -i 1 # uninstall mod with index 1
|
||||||
#### Enable/disable mods
|
```
|
||||||
|
|
||||||
```bash
|
#### Enable/disable mods
|
||||||
h2mm enable "Example mod"
|
|
||||||
h2mm enable -i 1 # enable mod with index 1
|
```bash
|
||||||
h2mm disable "Example mod"
|
h2mm enable "Example mod"
|
||||||
h2mm disable -i 1 # disable mod with index 1
|
h2mm enable -i 1 # enable mod with index 1
|
||||||
```
|
h2mm disable "Example mod"
|
||||||
|
h2mm disable -i 1 # disable mod with index 1
|
||||||
#### List installed mods
|
```
|
||||||
|
|
||||||
```bash
|
#### List installed mods
|
||||||
h2mm list
|
|
||||||
```
|
```bash
|
||||||
|
h2mm list
|
||||||
## Advanced usage
|
```
|
||||||
|
|
||||||
### Shortcuts
|
## Compatibility
|
||||||
|
|
||||||
You can use the short form of commands to save some time. The shortcuts are:
|
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.
|
||||||
|
|
||||||
- `i` for `install`
|
Status of platforms:
|
||||||
- `u` for `uninstall`
|
|
||||||
- `e` for `enable`
|
- Linux :white_check_mark:
|
||||||
- `d` for `disable`
|
- Steam Deck - untested (should work) :grey_question:
|
||||||
- `l` for `list`
|
- Windows - WSL :white_check_mark:
|
||||||
- `ex` for `export`
|
|
||||||
- `im` for `import`
|
> 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`.
|
||||||
- `r` for `reset`
|
|
||||||
|
## Advanced usage
|
||||||
### Exporting and importing
|
|
||||||
|
### Shortcuts
|
||||||
You can export all installed mods to a zip file and import mods from the same file. This can be useful for sharing mods with others or for backing up your mods. The zip file will be saved in the current directory.
|
|
||||||
|
You can use the short form of commands to save some time. The shortcuts are:
|
||||||
```bash
|
|
||||||
h2mm export modpack1.zip
|
- `i` for `install`
|
||||||
h2mm import modpack2.zip
|
- `u` for `uninstall`
|
||||||
```
|
- `e` for `enable`
|
||||||
|
- `d` for `disable`
|
||||||
### Resetting all installed mods
|
- `l` for `list`
|
||||||
|
- `ex` for `export`
|
||||||
You can reset all installed mods by running the following command. This will remove all installed mods and the database, in case things go wild.
|
- `im` for `import`
|
||||||
|
- `mc` for `modpack-create`
|
||||||
```bash
|
- `ms` for `modpack-switch`
|
||||||
h2mm reset
|
- `ml` for `modpack-list`
|
||||||
```
|
- `md` for `modpack-delete`
|
||||||
|
- `mo` for `modpack-overwrite`
|
||||||
### Database location and details
|
- `mr` for `modpack-reset`
|
||||||
|
- `r` for `reset`
|
||||||
The database is stored in the `Helldivers 2` install directory, under the `data` folder with the name `mods.csv`, where the mods are also installed. The database is a simple CSV file which you can use to manually manage mods if needed, you can mostly use it to rename or reorder mods.
|
|
||||||
|
### Modpacks support
|
||||||
## Contributing
|
|
||||||
|
You can set up modpacks by using the `modpack-*` commands. This allows you to quickly change between a set of mods. For more information, check the help message.
|
||||||
Feel free to contribute to this project by creating a pull request or opening an issue.
|
|
||||||
|
```bash
|
||||||
## Planned features
|
h2mm modpack-create "Modpack 1"
|
||||||
|
# install, enable, disable other mods...
|
||||||
- [x] Check for mod updates
|
h2mm modpack-create "Modpack 2"
|
||||||
- [x] Enable/disable mods
|
h2mm modpack-switch "Modpack 1"
|
||||||
- [ ] 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
|
### Exporting and importing
|
||||||
- [x] [DEV] Provide fixes for breaking updates
|
|
||||||
- [ ] [DEV] Optimize code - throw errors in 1 line
|
You can export all installed mods to a zip file and import mods from the same file. This can be useful for sharing mods with others or for backing up your mods. The archive file (`.tar.gz`) will be saved in the current directory.
|
||||||
- [ ] [DEV] Rewrite some code to be more readable
|
|
||||||
|
```bash
|
||||||
|
h2mm export modpack1.zip
|
||||||
|
h2mm import modpack2.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
### Resetting all installed mods
|
||||||
|
|
||||||
|
You can reset all installed mods by running the following command. This will remove all installed mods and the database, in case things go wild.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
h2mm reset
|
||||||
|
```
|
||||||
|
|
||||||
|
### Database location and details
|
||||||
|
|
||||||
|
The database is stored in the `Helldivers 2` install directory, under the `data` folder with the name `mods.csv`, where the mods are also installed. The database is a simple CSV file which you can use to manually manage mods if needed, you can mostly use it to rename or reorder mods.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Feel free to contribute to this project by creating a pull request or opening an issue.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
VERSION="0.2.0"
|
VERSION="0.3.0"
|
||||||
|
|
||||||
# --- Globals ---
|
# --- Globals ---
|
||||||
|
|
||||||
@@ -12,6 +12,8 @@ NC='\033[0m'
|
|||||||
H2PATH="${HOME}/.config/h2mm/h2path"
|
H2PATH="${HOME}/.config/h2mm/h2path"
|
||||||
MODS_DIR=""
|
MODS_DIR=""
|
||||||
DB_FILE=""
|
DB_FILE=""
|
||||||
|
MODPACKS_FOLDER=""
|
||||||
|
MODPACKS_DB_FILE=""
|
||||||
|
|
||||||
LAST_CHECKED_UPDATE_FILE="${HOME}/.config/h2mm/last_update"
|
LAST_CHECKED_UPDATE_FILE="${HOME}/.config/h2mm/last_update"
|
||||||
VERSION_URL="https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/version"
|
VERSION_URL="https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/version"
|
||||||
@@ -19,20 +21,37 @@ REPO_URL="https://github.com/v4n00/h2mm-cli"
|
|||||||
|
|
||||||
# --- Utility Functions ---
|
# --- Utility Functions ---
|
||||||
|
|
||||||
|
function get_version_major() {
|
||||||
|
echo "$1" | awk -F. '{print $2}'
|
||||||
|
}
|
||||||
|
|
||||||
|
BREAKING_CHANGES_DB_FILE_PATCHES=(
|
||||||
|
["2"]='sed -i "s/^\([0-9]\+\),/\1,ENABLED,/" $1'
|
||||||
|
["3"]='sed -i "1 i\\3" "$1"'
|
||||||
|
)
|
||||||
|
|
||||||
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 disable_all_modpacks() {
|
||||||
|
sed -i 's/ENABLED/DISABLED/' "$MODPACKS_DB_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_mod_name_and_index() {
|
function get_mod_name_and_index() {
|
||||||
@@ -40,7 +59,7 @@ function get_mod_name_and_index() {
|
|||||||
entry=$(grep "^${mod_index}," "$DB_FILE")
|
entry=$(grep "^${mod_index}," "$DB_FILE")
|
||||||
mod_name=$(echo "$entry" | awk -F, '{print $3}')
|
mod_name=$(echo "$entry" | awk -F, '{print $3}')
|
||||||
elif [[ -n "$mod_name" ]]; then # if mod name exists
|
elif [[ -n "$mod_name" ]]; then # if mod name exists
|
||||||
entry=$(grep -i ",$mod_name," "$DB_FILE")
|
entry=$(grep ",$mod_name," "$DB_FILE")
|
||||||
mod_index=$(echo "$entry" | awk -F, '{print $1}' | head -1)
|
mod_index=$(echo "$entry" | awk -F, '{print $1}' | head -1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -52,6 +71,21 @@ function get_mod_name_and_index() {
|
|||||||
status=$(echo "$entry" | awk -F, '{print $2}')
|
status=$(echo "$entry" | awk -F, '{print $2}')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_modpack_name_and_index() {
|
||||||
|
if [[ -n "$modpack_index" ]]; then # if modpack index exists
|
||||||
|
entry=$(grep "^${modpack_index}," "$MODPACKS_DB_FILE")
|
||||||
|
modpack_name=$(echo "$entry" | awk -F, '{print $3}')
|
||||||
|
elif [[ -n "$modpack_name" ]]; then # if modpack name exists
|
||||||
|
entry=$(grep ",$modpack_name$" "$MODPACKS_DB_FILE")
|
||||||
|
modpack_index=$(echo "$entry" | awk -F, '{print $1}' | head -1)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$entry" || -z "$modpack_index" || -z "$modpack_name" ]]; then
|
||||||
|
echo -e "${RED}Error${NC}: Modpack not found." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function find_game_directory() {
|
function find_game_directory() {
|
||||||
local search_dir="${HOME}"
|
local search_dir="${HOME}"
|
||||||
local target_dir="Steam/steamapps/common/Helldivers\ 2/data"
|
local target_dir="Steam/steamapps/common/Helldivers\ 2/data"
|
||||||
@@ -73,8 +107,7 @@ function find_game_directory() {
|
|||||||
|
|
||||||
if [[ -z "$game_dir" ]]; then
|
if [[ -z "$game_dir" ]]; then
|
||||||
echo "Could not find the Helldivers 2 data directory automatically." >&2
|
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
|
IFS= read -ep "Please enter the path to the Helldivers 2 data directory: " game_dir
|
||||||
game_dir=$(eval echo "$game_dir")
|
|
||||||
if [[ ! -d "$game_dir" ]]; then
|
if [[ ! -d "$game_dir" ]]; then
|
||||||
echo -e "${RED}Error${NC}: Provided path is not a valid directory." >&2
|
echo -e "${RED}Error${NC}: Provided path is not a valid directory." >&2
|
||||||
exit 1
|
exit 1
|
||||||
@@ -100,12 +133,23 @@ function initialize_directories() {
|
|||||||
|
|
||||||
if [[ ! -f "$DB_FILE" ]]; then
|
if [[ ! -f "$DB_FILE" ]]; then
|
||||||
touch "$DB_FILE"
|
touch "$DB_FILE"
|
||||||
if [[ $? -eq 0 ]]; then
|
|
||||||
echo -e "Database file ${GREEN}created${NC}: $DB_FILE"
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not create database file." >&2; exit 1; }
|
||||||
else
|
echo "$VERSION" | awk -F. '{print $2}' > "$DB_FILE"
|
||||||
echo -e "${RED}Error${NC}: Could not create database file." >&2
|
echo -e "Database file ${GREEN}created${NC}: $DB_FILE" &>2
|
||||||
exit 1
|
fi
|
||||||
fi
|
}
|
||||||
|
|
||||||
|
function initialize_modpack_directories() {
|
||||||
|
MODPACKS_FOLDER="$MODS_DIR/modpacks"
|
||||||
|
MODPACKS_DB_FILE="$MODPACKS_FOLDER/modpacks.csv"
|
||||||
|
|
||||||
|
if [[ ! -d "$MODPACKS_FOLDER" || ! -f "$MODPACKS_DB_FILE" ]]; then
|
||||||
|
mkdir -p "$MODPACKS_FOLDER" && touch "$MODPACKS_DB_FILE"
|
||||||
|
|
||||||
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not create modpacks folder/file." >&2; exit 1; }
|
||||||
|
echo "$VERSION" | awk -F. '{print $2}' > "$MODPACKS_DB_FILE"
|
||||||
|
echo -e "Modpacks folder and file ${GREEN}created${NC}: $MODPACKS_FOLDER" &>2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,17 +159,25 @@ function display_help() {
|
|||||||
echo "Helldivers 2 Mod Manager v${VERSION}"
|
echo "Helldivers 2 Mod Manager v${VERSION}"
|
||||||
echo "Usage: h2mm [command] [options]"
|
echo "Usage: h2mm [command] [options]"
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " install Install a mod with files (short form: h2mm i)."
|
echo " install Install a mod by the file provided (directory, zip, patch)."
|
||||||
echo " uninstall Uninstall a mod by name (short form: h2mm u)."
|
echo " uninstall Uninstall a mod by name (or index)."
|
||||||
echo " list List all installed mods (short form: h2mm l)."
|
echo " list List all installed mods."
|
||||||
echo " export <zip_name> Export installed mods to a zip file (short form: h2mm ex)."
|
echo " enable Enable a mod by name (or index)."
|
||||||
echo " import <zip_name> Import mods from a zip file (short form: h2mm im)."
|
echo " disable Disable a mod by name (or index)."
|
||||||
echo " reset Reset all installed mods (short form: h2mm rr)."
|
echo " export Export installed mods to a zip file."
|
||||||
echo " help Display this help message (short form: h2mm h)."
|
echo " import Import mods from a zip file."
|
||||||
echo "For more information on usage, use h2mm [command] --help, available for install and uninstall."
|
echo " modpack-create Create a modpack from the currently installed mods."
|
||||||
|
echo " modpack-switch Switch to a modpack by name (or index)."
|
||||||
|
echo " modpack-list List all installed modpacks."
|
||||||
|
echo " modpack-delete Delete a modpack by name (or index)."
|
||||||
|
echo " modpack-overwrite Overwrite a modpack by name (or index)."
|
||||||
|
echo " modpack-reset Reset all installed modpacks."
|
||||||
|
echo " reset Reset all installed mods."
|
||||||
|
echo " help Display this help message."
|
||||||
|
echo "For more information on usage, use h2mm [command] --help."
|
||||||
echo "Basic Usage:"
|
echo "Basic Usage:"
|
||||||
echo " h2mm install -z /path/to/mod.zip"
|
echo " h2mm install /path/to/mod.zip"
|
||||||
echo " h2mm install -d /path/to/mod/files"
|
echo " h2mm install /path/to/mod/files"
|
||||||
echo " h2mm uninstall \"Example mod\""
|
echo " h2mm uninstall \"Example mod\""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,11 +187,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."
|
||||||
@@ -194,13 +247,59 @@ function display_reset_help() {
|
|||||||
function display_export_help() {
|
function display_export_help() {
|
||||||
echo "Usage: h2mm export"
|
echo "Usage: h2mm export"
|
||||||
echo "Short form: h2mm ex"
|
echo "Short form: h2mm ex"
|
||||||
echo "Export installed mods and database to a zip file."
|
echo "Export installed mods and database to a zip file (in h2mm format, archive with csv)."
|
||||||
}
|
}
|
||||||
|
|
||||||
function display_import_help() {
|
function display_import_help() {
|
||||||
echo "Usage: h2mm import"
|
echo "Usage: h2mm import"
|
||||||
echo "Short form: h2mm im"
|
echo "Short form: h2mm im"
|
||||||
echo "Import mods and database from a zip file (coming from h2mm)."
|
echo "Import mods and database from an archive file (coming from h2mm)."
|
||||||
|
}
|
||||||
|
|
||||||
|
function display_modpack_list_help() {
|
||||||
|
echo "Usage: h2mm modpack-list"
|
||||||
|
echo "Short form: h2mm ml"
|
||||||
|
echo "List all installed modpacks."
|
||||||
|
echo "Database of modpacks is stored in Steam/steamapps/common/Helldivers\ 2/data/modpacks/modpacks.csv"
|
||||||
|
echo "You can rename, delete, or edit this file to manage modpacks manually."
|
||||||
|
}
|
||||||
|
|
||||||
|
function display_modpack_create_help() {
|
||||||
|
echo "Usage: h2mm modpack-create \"<modpack_name>\""
|
||||||
|
echo "Short form: h2mm mc"
|
||||||
|
echo "Create a modpack from the currently installed mods."
|
||||||
|
}
|
||||||
|
|
||||||
|
function display_modpack_switch_help() {
|
||||||
|
echo "Usage: h2mm modpack-switch [options] \"<modpack_name>\""
|
||||||
|
echo "Short form: h2mm ms"
|
||||||
|
echo "Options:"
|
||||||
|
echo " -i <index> Index of the modpack to switch to."
|
||||||
|
echo "Switch to a modpack by name or index."
|
||||||
|
}
|
||||||
|
|
||||||
|
function display_modpack_reset_help() {
|
||||||
|
echo "Usage: h2mm modpack-reset"
|
||||||
|
echo "Short form: h2mm mr"
|
||||||
|
echo "Reset all installed modpacks."
|
||||||
|
echo "Deletes all installed modpacks and the database file."
|
||||||
|
echo "Database of modpacks is stored in Steam/steamapps/common/Helldivers\ 2/data/modpacks/modpacks.csv, along with the modpacks."
|
||||||
|
}
|
||||||
|
|
||||||
|
function display_modpack_delete_help() {
|
||||||
|
echo "Usage: h2mm modpack-delete [options] \"<modpack_name>\""
|
||||||
|
echo "Short form: h2mm md"
|
||||||
|
echo "Options:"
|
||||||
|
echo " -i <index> Index of the modpack to delete."
|
||||||
|
echo "Delete a modpack by name or index."
|
||||||
|
}
|
||||||
|
|
||||||
|
function display_modpack_overwrite_help() {
|
||||||
|
echo "Usage: h2mm modpack-overwrite [options] \"<modpack_name>\""
|
||||||
|
echo "Short form: h2mm mo"
|
||||||
|
echo "Options:"
|
||||||
|
echo " -i <index> Index of the modpack to overwrite."
|
||||||
|
echo "Overwrite a modpack (the mods that it uses) by name or index."
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Main Functions ---
|
# --- Main Functions ---
|
||||||
@@ -210,7 +309,7 @@ function display_import_help() {
|
|||||||
function check_for_updates() {
|
function check_for_updates() {
|
||||||
if [[ -f "$LAST_CHECKED_UPDATE_FILE" ]]; then
|
if [[ -f "$LAST_CHECKED_UPDATE_FILE" ]]; then
|
||||||
last_update=$(cat "$LAST_CHECKED_UPDATE_FILE")
|
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
|
return
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -293,38 +392,38 @@ function mod_disable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mod_enable() {
|
function mod_enable() {
|
||||||
local mod_name=""
|
local mod_name=""
|
||||||
local mod_index=""
|
local mod_index=""
|
||||||
|
|
||||||
[[ $# -eq 0 ]] && { display_enable_help; exit 0; }
|
[[ $# -eq 0 ]] && { display_enable_help; exit 0; }
|
||||||
|
|
||||||
# parse arguments
|
# parse arguments
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-i)
|
-i)
|
||||||
mod_index="$2"; shift 2
|
mod_index="$2"; shift 2
|
||||||
;;
|
;;
|
||||||
--help|-h)
|
--help|-h)
|
||||||
display_enable_help; exit 0
|
display_enable_help; exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
mod_name="$1"; shift 1
|
mod_name="$1"; shift 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
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"
|
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; }
|
[[ "$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
|
# enable each mod file by removing disabled_ from the start of the filename
|
||||||
for file in $files; do
|
for file in $files; do
|
||||||
disabled_file="disabled_$file"
|
disabled_file="disabled_$file"
|
||||||
|
|
||||||
# check if the files exists
|
# check if the files exists
|
||||||
[[ -f "$MODS_DIR/$disabled_file" ]] || { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; }
|
[[ -f "$MODS_DIR/$disabled_file" ]] || { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; }
|
||||||
@@ -334,17 +433,21 @@ function mod_enable() {
|
|||||||
# check if the file was moved successfully
|
# check if the file was moved successfully
|
||||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not enable mod file $disabled_file." >&2; exit 1; }
|
[[ $? -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
|
echo -e "Enabled ${ORANGE}$disabled_file${NC} (changed to ${GREEN}\$MODS_DIR/$file${NC})." >&2
|
||||||
done
|
done
|
||||||
|
|
||||||
# update the database
|
# update the database
|
||||||
sed -i "/^$mod_index,/s/DISABLED/ENABLED/" "$DB_FILE"
|
sed -i "/^$mod_index,/s/DISABLED/ENABLED/" "$DB_FILE"
|
||||||
|
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
echo -e "Mod $mod_name ${GREEN}enabled${NC} successfully." >&2
|
echo -e "Mod $mod_name ${GREEN}enabled${NC} successfully." >&2
|
||||||
else
|
else
|
||||||
echo -e "${RED}Error${NC}: Failed to enable mod." >&2
|
echo -e "${RED}Error${NC}: Failed to enable mod." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function modpack_reset() {
|
||||||
|
:
|
||||||
}
|
}
|
||||||
|
|
||||||
function mod_reset() {
|
function mod_reset() {
|
||||||
@@ -353,12 +456,18 @@ function mod_reset() {
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -p "Are you sure you want to reset all installed mods? (Y/n): " confirm
|
local without_modpacks=false
|
||||||
|
[[ "$1" == "--without-modpacks" ]] && without_modpacks=true
|
||||||
|
|
||||||
|
echo -ne "Are you sure you want to ${RED}reset${NC} all installed mods? (Y/n): "
|
||||||
|
read -r confirm
|
||||||
if [[ "$confirm" == "y" || "$confirm" == "Y" || "$confirm" = "" ]]; then
|
if [[ "$confirm" == "y" || "$confirm" == "Y" || "$confirm" = "" ]]; then
|
||||||
rm -f "$MODS_DIR"/*.patch_*
|
rm -f "$MODS_DIR"/*.patch_*
|
||||||
rm -f "$DB_FILE"
|
rm -f "$DB_FILE"
|
||||||
rm -f "$H2PATH"
|
rm -f "$H2PATH"
|
||||||
echo "Mods and database file deleted."
|
echo "Mods and related database file deleted."
|
||||||
|
|
||||||
|
[[ $without_modpacks == false ]] && modpack_reset --force
|
||||||
else
|
else
|
||||||
echo "Reset cancelled." >&2
|
echo "Reset cancelled." >&2
|
||||||
exit 1
|
exit 1
|
||||||
@@ -367,54 +476,83 @@ 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; }
|
||||||
|
|
||||||
# parse arguments
|
# parse arguments
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-n)
|
-n)
|
||||||
mod_name="$2"; shift 2
|
mod_name="$2"; shift 2
|
||||||
;;
|
;;
|
||||||
--help|-h)
|
--help|-h)
|
||||||
display_install_help; exit 0
|
display_install_help; exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
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
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
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
|
||||||
@@ -423,14 +561,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
|
||||||
@@ -443,15 +576,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}"
|
||||||
@@ -468,9 +603,12 @@ function mod_install() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
# add entry to database
|
# add entry to database
|
||||||
next_id=$(awk -F, 'END {print $1 + 1}' "$DB_FILE")
|
next_id=$(awk -F, 'NR > 1 {last_id = $1} END {print last_id + 1}' "$DB_FILE")
|
||||||
echo "$next_id,ENABLED,$mod_name,${target_files[*]}" >> "$DB_FILE"
|
echo "$next_id,ENABLED,$mod_name,${target_files[*]}" >> "$DB_FILE"
|
||||||
echo -e "Mod $mod_name ($base_name) ${GREEN}installed${NC} successfully." >&2
|
echo -e "Mod $mod_name ($base_name) ${GREEN}installed${NC} successfully." >&2
|
||||||
|
|
||||||
|
# disable any modpack
|
||||||
|
disable_all_modpacks
|
||||||
}
|
}
|
||||||
|
|
||||||
function mod_uninstall() {
|
function mod_uninstall() {
|
||||||
@@ -494,170 +632,351 @@ 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
|
||||||
|
|
||||||
# remove entry from database
|
# remove entry from database
|
||||||
sed -i "/^$mod_index/d" "$DB_FILE"
|
sed -i "/^$mod_index,/d" "$DB_FILE"
|
||||||
|
|
||||||
echo -e "Mod $mod_name ${ORANGE}uninstalled${NC} successfully." >&2
|
echo -e "Mod $mod_name ${ORANGE}uninstalled${NC} successfully." >&2
|
||||||
|
|
||||||
|
# disable any modpack
|
||||||
|
disable_all_modpacks
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
[[ $(wc -l < "$DB_FILE") -le 1 ]] && { 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, '{
|
|
||||||
color = ($2 == "DISABLED") ? RED : GREEN;
|
awk -v GREEN="$GREEN" -v RED="$RED" -v NC="$NC" -F, 'NR > 1 {
|
||||||
if (length($3) > 150) $3 = substr($3, 1, 147) "...";
|
color = ($2 == "DISABLED") ? RED : GREEN;
|
||||||
printf "%2s. [%s%s%s] %s (%s)\n", $1, color, $2, NC, $3, $4}' "$DB_FILE"
|
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() {
|
function mod_export() {
|
||||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
[[ "$1" == "--help" || "$1" == "-h" ]] && { display_export_help; exit 0; }
|
||||||
display_export_help
|
|
||||||
exit 0
|
local save_dir=$(pwd)
|
||||||
|
local archive_name="Helldivers_2_Mods_$(date +%Y-%m-%d_%H-%M-%S)"
|
||||||
|
local modpack_export=false
|
||||||
|
local force=false
|
||||||
|
|
||||||
|
if [[ "$1" == "--modpack" ]]; then
|
||||||
|
modpack_export=true
|
||||||
|
save_dir="$2"
|
||||||
|
archive_name="$3"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -ne "Archive file will be saved in the current directory ($(pwd)). Continue? (Y/n): "
|
[[ $(wc -l < "$DB_FILE") -le 1 ]] && { echo "No modpacks saved."; exit 1; }
|
||||||
read -r confirm
|
|
||||||
if [[ "$confirm" == "y" || "$confirm" == "Y" || "$confirm" = "" ]]; then
|
if [[ silent == false ]]; then
|
||||||
|
echo -ne "Archive file will be saved to ${save_dir}/${archive_name}. Make? (Y/n): "
|
||||||
|
read -r confirm
|
||||||
|
fi
|
||||||
|
if [[ silent == true || "$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
|
|
||||||
|
|
||||||
current_path=$(pwd)
|
# zip up the mods with the current date and time in the name
|
||||||
archive_name="Helldivers_2_Mods_$(date +%Y-%m-%d_%H-%M-%S).tar.gz"
|
[[ -f "$save_dir/${archive_name}.tar.gz" ]] && { echo -e "${RED}Error${NC}: File $save_dir/${archive_name}.tar.gz already exists." >&2; exit 1; }
|
||||||
tar -czf "$current_path/$archive_name" -C "$OUT_DIR" "Helldivers 2 Mods"
|
tar -czf "$save_dir/${archive_name}.tar.gz" -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
|
[[ "$modpack_export" == false ]] && echo -e "Mods ${GREEN}exported${NC} to $save_dir/${archive_name}.tar.gz." >&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
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -f "$1" ]]; then
|
local modpack_export=false
|
||||||
echo -e "${RED}Error${NC}: File $1 does not exist." >&2
|
[[ "$1" == "--modpack" ]] && { modpack_export=true; shift 1; }
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "Importing mods will ${RED}reset${NC} your mods." >&2
|
[[ ! -f "$1" ]] && { echo -e "${RED}Error${NC}: File $1 does not exist." >&2; exit 1; }
|
||||||
mod_reset
|
|
||||||
if [[ $? -eq 1 ]]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# reset mods before importing
|
||||||
|
[[ modpack_export == false ]] && echo -e "Importing mods will ${RED}reset${NC} your mods." >&2
|
||||||
|
mod_reset --without-modpacks
|
||||||
|
|
||||||
|
# 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 archive 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 archive is invalid." >&2; exit 1; }
|
||||||
echo -e "${RED}Error${NC}: Could not import mods. Possibly because the zip file is invalid." >&2
|
|
||||||
exit 1
|
# copy mods
|
||||||
|
cp "$MODS_EXPORT_DIR"/* "$MODS_DIR"
|
||||||
|
|
||||||
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Failed to import mods." >&2; exit 1; }
|
||||||
|
|
||||||
|
# handle breaking chanegs
|
||||||
|
# version 0.2.x has no version number in the database file, so if there's no version number, add it
|
||||||
|
if [[ $(head -n 1 "$DB_FILE") =~ "[0-9]+," ]]; then
|
||||||
|
mods_db_current_version=$(head -n 1 "$DB_FILE")
|
||||||
|
else
|
||||||
|
mods_db_current_version="2"
|
||||||
|
fi
|
||||||
|
mods_db_new_version=$(get_version_major $VERSION)
|
||||||
|
|
||||||
|
for ((i = mods_db_current_version + 1; i <= mods_db_new_version; i++)); do
|
||||||
|
eval $(echo "${BREAKING_CHANGES_DB_FILE_PATCHES[$i]}" | sed "s:\$1:$DB_FILE:")
|
||||||
|
|
||||||
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Failed to apply breaking changes patch $i." >&2; exit 1; }
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "Mods imported ${GREEN}successfully${NC}." >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Modpacks management ---
|
||||||
|
|
||||||
|
function modpack_list() {
|
||||||
|
[[ "$1" == "--help" || "$1" == "-h" ]] && { display_modpack_list_help; exit 0; }
|
||||||
|
|
||||||
|
[[ $(wc -l < "$MODPACKS_DB_FILE") -le 1 ]] && { echo "No modpacks saved."; return; }
|
||||||
|
|
||||||
|
echo "Saved modpacks:" >&2
|
||||||
|
|
||||||
|
awk -v GREEN="$GREEN" -v RED="$RED" -v NC="$NC" -F, 'NR > 1{
|
||||||
|
color = ($2 == "DISABLED") ? RED : GREEN;
|
||||||
|
printf "%2s. [%s%s%s] %s\n", $1, color, $2, NC, $3}' "$MODPACKS_DB_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
function modpack_create() {
|
||||||
|
local modpack_name=""
|
||||||
|
|
||||||
|
[[ $# -eq 0 ]] && { display_modpack_create_help; exit 0; }
|
||||||
|
|
||||||
|
# if no mods are installed, exit
|
||||||
|
[[ $(wc -l < "$DB_FILE") -le 1 ]] && { echo -e "${RED}Error${NC}: No mods installed." >&2; exit 1; }
|
||||||
|
|
||||||
|
# use built-in export function
|
||||||
|
modpack_name="$1"
|
||||||
|
mod_export --modpack "$MODPACKS_FOLDER" "$modpack_name"
|
||||||
|
|
||||||
|
echo -e "Modpack ${GREEN}created${NC}: \$MODPACKS_FOLDER/$modpack_name.tar.gz" >&2
|
||||||
|
|
||||||
|
# add entry to database
|
||||||
|
next_id=$(awk -F, 'NR > 1 {last_id = $1} END {print last_id + 1}' "$MODPACKS_DB_FILE")
|
||||||
|
sed -i "s/ENABLED/DISABLED/" "$MODPACKS_DB_FILE"
|
||||||
|
echo "$next_id,ENABLED,$modpack_name" >> "$MODPACKS_DB_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
function modpack_switch() {
|
||||||
|
local modpack_name=""
|
||||||
|
local modpack_index=""
|
||||||
|
|
||||||
|
[[ $# -eq 0 ]] && { display_modpack_switch_help; exit 0; }
|
||||||
|
|
||||||
|
# parse arguments
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-i)
|
||||||
|
modpack_index="$2"; shift 2
|
||||||
|
;;
|
||||||
|
--help|-h)
|
||||||
|
display_modpack_switch_help; exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
modpack_name="$1"; shift 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ -z "$modpack_name" && -z "$modpack_index" ]] && { echo -e "${RED}Error${NC}: Modpack name or index is required to switch." >&2; exit 1; }
|
||||||
|
|
||||||
|
# find modpack files
|
||||||
|
get_modpack_name_and_index "$modpack_name" "$modpack_index"
|
||||||
|
|
||||||
|
echo -e "Switching modpacks mods will ${RED}reset${NC} your mods." >&2
|
||||||
|
mod_import --modpack "$MODPACKS_FOLDER/$modpack_name.tar.gz"
|
||||||
|
|
||||||
|
echo -e "Modpack ${GREEN}switched${NC}: \$MODPACKS_FOLDER/$modpack_name.tar.gz" >&2
|
||||||
|
|
||||||
|
# save status to db
|
||||||
|
sed -i "s/ENABLED/DISABLED/" "$MODPACKS_DB_FILE"
|
||||||
|
sed -i "/^$modpack_index,/s/DISABLED/ENABLED/" "$MODPACKS_DB_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
function modpack_reset() {
|
||||||
|
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||||
|
display_modpack_reset_help
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# copy mods verbosely
|
local force=false
|
||||||
cp -v "$MODS_EXPORT_DIR"/* "$MODS_DIR"
|
|
||||||
if [[ $? -eq 0 ]]; then
|
[[ "$1" == "--force" ]] && force=true
|
||||||
echo -e "Mods imported ${GREEN}successfully${NC}." >&2
|
|
||||||
|
[[ force == false ]] && read -p "Are you sure you want to reset all installed modpacks? (Y/n): " confirm
|
||||||
|
if [[ force == true || "$confirm" == "y" || "$confirm" == "Y" || "$confirm" = "" ]]; then
|
||||||
|
rm -f "$MODPACKS_FOLDER"/*.tar.gz
|
||||||
|
rm -f "$MODPACKS_DB_FILE"
|
||||||
|
rmdir "$MODPACKS_FOLDER"
|
||||||
|
echo "Modpacks and related database file deleted."
|
||||||
else
|
else
|
||||||
echo -e "${RED}Error${NC}: Failed to import mods." >&2
|
echo "Reset cancelled." >&2
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function modpack_delete() {
|
||||||
|
local modpack_name=""
|
||||||
|
local modpack_index=""
|
||||||
|
|
||||||
|
[[ $# -eq 0 ]] && { display_modpack_delete_help; exit 0; }
|
||||||
|
|
||||||
|
# parse arguments
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-i)
|
||||||
|
modpack_index="$2"; shift 2
|
||||||
|
;;
|
||||||
|
--help|-h)
|
||||||
|
display_modpack_delete_help; exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
modpack_name="$1"; shift 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ -z "$modpack_name" && -z "$modpack_index" ]] && { echo -e "${RED}Error${NC}: Modpack name or index is required to delete." >&2; exit 1; }
|
||||||
|
|
||||||
|
get_modpack_name_and_index "$modpack_name" "$modpack_index"
|
||||||
|
|
||||||
|
rm -f "$MODPACKS_FOLDER/$modpack_name.tar.gz"
|
||||||
|
|
||||||
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not delete modpack." >&2; exit 1; }
|
||||||
|
echo -e "Modpack ${GREEN}deleted${NC}: \$MODPACKS_FOLDER/$modpack_name.tar.gz" >&2
|
||||||
|
|
||||||
|
# remove entry from database
|
||||||
|
sed -i "/^$modpack_index,/d" "$MODPACKS_DB_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
function modpack_overwrite() {
|
||||||
|
[[ $# -eq 0 ]] && { display_modpack_overwrite_help; exit 0; }
|
||||||
|
|
||||||
|
local modpack_name=""
|
||||||
|
local modpack_index=""
|
||||||
|
|
||||||
|
# parse arguments
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-i)
|
||||||
|
modpack_index="$2"; shift 2
|
||||||
|
;;
|
||||||
|
--help|-h)
|
||||||
|
display_modpack_save_help; exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
modpack_name="$1"; shift 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ -z "$modpack_name" && -z "$modpack_index" ]] && { echo -e "${RED}Error${NC}: Modpack name or index is required to save." >&2; exit 1; }
|
||||||
|
|
||||||
|
get_modpack_name_and_index "$modpack_name" "$modpack_index"
|
||||||
|
|
||||||
|
# if the modpack doesn't exist, exit
|
||||||
|
[[ ! -f "$MODPACKS_FOLDER/$modpack_name.tar.gz" ]] && { echo -e "${RED}Error${NC}: Modpack $modpack_name does not exist." >&2; exit 1; }
|
||||||
|
|
||||||
|
|
||||||
|
rm -f "$MODPACKS_FOLDER/$modpack_name.tar.gz"
|
||||||
|
|
||||||
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not delete modpack." >&2; exit 1; }
|
||||||
|
|
||||||
|
# use built-in export function
|
||||||
|
mod_export --modpack "$MODPACKS_FOLDER" "$modpack_name"
|
||||||
|
|
||||||
|
echo -e "Modpack ${GREEN}saved${NC}: \$MODPACKS_FOLDER/$modpack_name.tar.gz" >&2
|
||||||
|
sed -i "/^$modpack_index,/s/DISABLED/ENABLED/" "$MODPACKS_DB_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
# --- 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
|
||||||
initialize_directories
|
initialize_directories
|
||||||
|
initialize_modpack_directories
|
||||||
check_for_updates
|
check_for_updates
|
||||||
|
|
||||||
case "$command" in
|
case "$command" in
|
||||||
@@ -682,6 +1001,24 @@ function main() {
|
|||||||
import|im)
|
import|im)
|
||||||
mod_import "$@"
|
mod_import "$@"
|
||||||
;;
|
;;
|
||||||
|
modpack-list|ml)
|
||||||
|
modpack_list "$@"
|
||||||
|
;;
|
||||||
|
modpack-create|mc)
|
||||||
|
modpack_create "$@"
|
||||||
|
;;
|
||||||
|
modpack-delete|md)
|
||||||
|
modpack_delete "$@"
|
||||||
|
;;
|
||||||
|
modpack-overwrite|mo)
|
||||||
|
modpack_overwrite "$@"
|
||||||
|
;;
|
||||||
|
modpack-switch|ms)
|
||||||
|
modpack_switch "$@"
|
||||||
|
;;
|
||||||
|
modpack-reset|mr)
|
||||||
|
modpack_reset "$@"
|
||||||
|
;;
|
||||||
reset|r)
|
reset|r)
|
||||||
mod_reset "$@"
|
mod_reset "$@"
|
||||||
;;
|
;;
|
||||||
|
|||||||
+33
-21
@@ -8,6 +8,7 @@ NC='\033[0m'
|
|||||||
|
|
||||||
DESTINATION_PATH="/usr/local/bin"
|
DESTINATION_PATH="/usr/local/bin"
|
||||||
SCRIPT_NAME="h2mm"
|
SCRIPT_NAME="h2mm"
|
||||||
|
REPO_URL="https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master"
|
||||||
|
|
||||||
if [ "$(id -u)" -eq 0 ]; then
|
if [ "$(id -u)" -eq 0 ]; then
|
||||||
echo "Run me as normal user, not as root."
|
echo "Run me as normal user, not as root."
|
||||||
@@ -32,16 +33,17 @@ echo
|
|||||||
|
|
||||||
breaking_changes_patches=(
|
breaking_changes_patches=(
|
||||||
["2"]='sed -i "s/^\([0-9]\+\),/\1,ENABLED,/" "$1/mods.csv"'
|
["2"]='sed -i "s/^\([0-9]\+\),/\1,ENABLED,/" "$1/mods.csv"'
|
||||||
|
["3"]='sed -i "1 i\\3" "$1/mods.csv"'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Script
|
# Handle breaking changes
|
||||||
|
|
||||||
if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
|
if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
|
||||||
installed_version=$($SCRIPT_NAME --version)
|
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
|
# 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"; }
|
[[ ${installed_version:0:1} != "0" ]] && { installed_version="0.1.6"; }
|
||||||
|
|
||||||
latest_version=$(curl -sS https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/version)
|
latest_version=$(curl -sS "$REPO_URL"/version)
|
||||||
if [[ "$latest_version" == "$installed_version" ]]; then
|
if [[ "$latest_version" == "$installed_version" ]]; then
|
||||||
echo -e "You are reinstalling version $installed_version."
|
echo -e "You are reinstalling version $installed_version."
|
||||||
else
|
else
|
||||||
@@ -56,57 +58,67 @@ 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
|
||||||
search_dir="${HOME}"
|
search_dir="${HOME}"
|
||||||
target_dir="Steam/steamapps/common/Helldivers\ 2/data"
|
target_dir="Steam/steamapps/common/Helldivers\ 2/data"
|
||||||
echo "Searching for the Helldivers 2 data directory..." >&2
|
echo "Searching for the Helldivers 2 data directory... (20 seconds timeout)" >&2
|
||||||
game_dir=$(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
|
game_dir=$(timeout 20 find "$search_dir" -type d -path "*/$target_dir" 2>/dev/null | head -n 1)
|
||||||
echo -e "${RED}Error${NC}: Provided path is not a valid directory." >&2
|
if [[ -z "$game_dir" ]]; then
|
||||||
exit 1
|
echo "Could not find the Helldivers 2 data directory automatically." >&2
|
||||||
fi
|
IFS= read -ep "Please enter the path to the Helldivers 2 data directory: " game_dir
|
||||||
fi
|
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; }
|
[[ ! -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
|
# iterate from installed major number to latest major number
|
||||||
for ((i = installed_major + 1; i <= latest_major; i++)); do
|
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 [[ -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 -r response
|
read -er response
|
||||||
|
|
||||||
[[ "$response" != "y" && "$response" != "Y" && -n "$response" ]] && { echo "Exiting. Uninstall the script first the retry the install script."; exit 1; }
|
[[ "$response" != "y" && "$response" != "Y" && -n "$response" ]] && { echo "Exiting. Uninstall the script first the retry the install script."; exit 1; }
|
||||||
else
|
else
|
||||||
echo -e "${GREEN}[X]${NC} Breaking changes patch for version $i applied successfully."
|
echo -e "Breaking changes patch for version ${ORANGE}$i${NC} applied ${GREEN}successfully${NC}."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install
|
# 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
|
if [[ "$response" != "y" && "$response" != "Y" && -n "$response" ]]; then
|
||||||
DESTINATION_PATH=$(eval echo "$response")
|
DESTINATION_PATH="$response"
|
||||||
if [[ ! -d "$DESTINATION_PATH" ]]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Installing $SCRIPT_NAME to $DESTINATION_PATH."
|
echo "Installing $SCRIPT_NAME to $DESTINATION_PATH."
|
||||||
sudo curl https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/h2mm --output "$DESTINATION_PATH/$SCRIPT_NAME"
|
sudo curl "$REPO_URL"/h2mm --output "$DESTINATION_PATH/$SCRIPT_NAME"
|
||||||
sudo chmod +x "$DESTINATION_PATH/$SCRIPT_NAME"
|
sudo chmod +x "$DESTINATION_PATH/$SCRIPT_NAME"
|
||||||
|
|
||||||
if [[ ! -x "$(command -v $SCRIPT_NAME)" ]]; then
|
if [[ ! -x "$(command -v $SCRIPT_NAME)" ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user