fix: enable/disable logic
This commit is contained in:
@@ -1,156 +1,156 @@
|
|||||||
# 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.
|
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.
|
||||||
|
|
||||||
This script is complete, the version will always [remain at 0.x.x](https://0ver.org/)
|
This script is complete, the version will always [remain at 0.x.x](https://0ver.org/)
|
||||||
|
|
||||||
## Installation and updating
|
## Installation and updating
|
||||||
|
|
||||||
To install/update Helldivers 2 Mod Manager CLI run the following command in your terminal:
|
To install/update Helldivers 2 Mod Manager CLI run the following command in your terminal:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash -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)"
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!CAUTION]
|
> [!CAUTION]
|
||||||
> 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.
|
> 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.
|
||||||
|
|
||||||
If for some reason, the installation command doesn't work you can:
|
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>
|
1. Go to <https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh>
|
||||||
1. Right click -> Save page as...
|
1. Right click -> Save page as...
|
||||||
1. Go to your downloads folders `cd ~/Downloads`
|
1. Go to your downloads folders `cd ~/Downloads`
|
||||||
1. Give the script execution permissions `chmod +x install.sh`
|
1. Give the script execution permissions `chmod +x install.sh`
|
||||||
1. Run the script `./install.sh`
|
1. Run the script `./install.sh`
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
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.
|
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
|
```bash
|
||||||
h2mm
|
h2mm
|
||||||
```
|
```
|
||||||
|
|
||||||
### Available commands
|
### Available commands
|
||||||
|
|
||||||
- `install` - Install a mod by the file provided (directory, zip, patch).
|
- `install` - Install a mod by the file provided (directory, zip, patch).
|
||||||
- `uninstall` - Uninstall a mod by name (or index).
|
- `uninstall` - Uninstall a mod by name (or index).
|
||||||
- `list` - List all installed mods.
|
- `list` - List all installed mods.
|
||||||
- `enable` - Enable a mod by name (or index).
|
- `enable` - Enable a mod by name (or index).
|
||||||
- `disable` - Disable a mod by name (or index).
|
- `disable` - Disable a mod by name (or index).
|
||||||
- `export` - Export installed mods to a zip file.
|
- `export` - Export installed mods to a zip file.
|
||||||
- `import` - Import mods from a zip file.
|
- `import` - Import mods from a zip file.
|
||||||
- `modpack-create` - Create a modpack from the currently installed mods.
|
- `modpack-create` - Create a modpack from the currently installed mods.
|
||||||
- `modpack-switch` - Switch to a modpack by name (or index).
|
- `modpack-switch` - Switch to a modpack by name (or index).
|
||||||
- `modpack-list` - List all installed modpacks.
|
- `modpack-list` - List all installed modpacks.
|
||||||
- `modpack-delete` - Delete a modpack by name (or index).
|
- `modpack-delete` - Delete a modpack by name (or index).
|
||||||
- `modpack-overwrite` - Overwrite a modpack by name (or index).
|
- `modpack-overwrite` - Overwrite a modpack by name (or index).
|
||||||
- `modpack-reset` - Reset all installed modpacks.
|
- `modpack-reset` - Reset all installed modpacks.
|
||||||
- `reset` - Reset all installed mods.
|
- `reset` - Reset all installed mods.
|
||||||
- `help` - Display this help message.
|
- `help` - Display this help message.
|
||||||
|
|
||||||
### Basic usage
|
### Basic usage
|
||||||
|
|
||||||
#### Install mod(s)
|
#### 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 /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
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!NOTE]
|
> [!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.
|
> If the mod has more than 1 variant, you need to install the one you want by unarchiving it separately and providing the directory.
|
||||||
|
|
||||||
#### Uninstall a mod
|
#### Uninstall a mod
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
h2mm uninstall "Example mod"
|
h2mm uninstall "Example mod"
|
||||||
h2mm uninstall -i 1 # uninstall mod with index 1
|
h2mm uninstall -i 1 # uninstall mod with index 1
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Enable/disable mods
|
#### Enable/disable mods
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
h2mm enable "Example mod"
|
h2mm enable "Example mod"
|
||||||
h2mm enable -i 1 # enable mod with index 1
|
h2mm enable -i 1 # enable mod with index 1
|
||||||
h2mm disable "Example mod"
|
h2mm disable "Example mod"
|
||||||
h2mm disable -i 1 # disable mod with index 1
|
h2mm disable -i 1 # disable mod with index 1
|
||||||
```
|
```
|
||||||
|
|
||||||
#### List installed mods
|
#### List installed mods
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
h2mm list
|
h2mm list
|
||||||
```
|
```
|
||||||
|
|
||||||
## Compatibility
|
## 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.
|
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 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:
|
||||||
- Windows - WSL :white_check_mark:
|
- Windows - 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`.
|
> 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
|
## Advanced usage
|
||||||
|
|
||||||
### Shortcuts
|
### Shortcuts
|
||||||
|
|
||||||
You can use the short form of commands to save some time. The shortcuts are:
|
You can use the short form of commands to save some time. The shortcuts are:
|
||||||
|
|
||||||
- `i` for `install`
|
- `i` for `install`
|
||||||
- `u` for `uninstall`
|
- `u` for `uninstall`
|
||||||
- `e` for `enable`
|
- `e` for `enable`
|
||||||
- `d` for `disable`
|
- `d` for `disable`
|
||||||
- `l` for `list`
|
- `l` for `list`
|
||||||
- `ex` for `export`
|
- `ex` for `export`
|
||||||
- `im` for `import`
|
- `im` for `import`
|
||||||
- `mc` for `modpack-create`
|
- `mc` for `modpack-create`
|
||||||
- `ms` for `modpack-switch`
|
- `ms` for `modpack-switch`
|
||||||
- `ml` for `modpack-list`
|
- `ml` for `modpack-list`
|
||||||
- `md` for `modpack-delete`
|
- `md` for `modpack-delete`
|
||||||
- `mo` for `modpack-overwrite`
|
- `mo` for `modpack-overwrite`
|
||||||
- `mr` for `modpack-reset`
|
- `mr` for `modpack-reset`
|
||||||
- `r` for `reset`
|
- `r` for `reset`
|
||||||
|
|
||||||
### Modpacks support
|
### Modpacks support
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
h2mm modpack-create "Modpack 1"
|
h2mm modpack-create "Modpack 1"
|
||||||
# install, enable, disable other mods...
|
# install, enable, disable other mods...
|
||||||
h2mm modpack-create "Modpack 2"
|
h2mm modpack-create "Modpack 2"
|
||||||
h2mm modpack-switch "Modpack 1"
|
h2mm modpack-switch "Modpack 1"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Exporting and importing
|
### Exporting and importing
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
h2mm export modpack1.zip
|
h2mm export modpack1.zip
|
||||||
h2mm import modpack2.zip
|
h2mm import modpack2.zip
|
||||||
```
|
```
|
||||||
|
|
||||||
### Resetting all installed mods
|
### 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.
|
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
|
```bash
|
||||||
h2mm reset
|
h2mm reset
|
||||||
```
|
```
|
||||||
|
|
||||||
### Database location and details
|
### 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.
|
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
|
## Contributing
|
||||||
|
|
||||||
Feel free to contribute to this project by creating a pull request or opening an issue.
|
Feel free to contribute to this project by creating a pull request or opening an issue.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
VERSION="0.3.2"
|
VERSION="0.3.3"
|
||||||
|
|
||||||
# --- Globals ---
|
# --- Globals ---
|
||||||
|
|
||||||
@@ -25,11 +25,6 @@ function get_version_major() {
|
|||||||
echo "$1" | awk -F. '{print $2}'
|
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 "$1" | awk -F/ '{print $NF}'
|
echo "$1" | awk -F/ '{print $NF}'
|
||||||
}
|
}
|
||||||
@@ -50,6 +45,14 @@ function disable_all_modpacks() {
|
|||||||
sed -i 's/ENABLED/DISABLED/' "$MODPACKS_DB_FILE"
|
sed -i 's/ENABLED/DISABLED/' "$MODPACKS_DB_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function remove_disabled_prefix() {
|
||||||
|
local _file="$1"
|
||||||
|
while [[ "$_file" == disabled_* ]]; do
|
||||||
|
_file=$(echo "$_file" | sed 's/^disabled_//')
|
||||||
|
done
|
||||||
|
echo "$_file"
|
||||||
|
}
|
||||||
|
|
||||||
function get_mod_name_and_index() {
|
function get_mod_name_and_index() {
|
||||||
if [[ -n "$mod_index" ]]; then # if mod index exists
|
if [[ -n "$mod_index" ]]; then # if mod index exists
|
||||||
entry=$(grep "^${mod_index}," "$DB_FILE")
|
entry=$(grep "^${mod_index}," "$DB_FILE")
|
||||||
@@ -375,7 +378,7 @@ function downgrade_mods() {
|
|||||||
echo -e "Downgraded ${ORANGE}$mod${NC} to ${GREEN}\$MODS_DIR/$new_patch${NC}." >&2
|
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/^$mod$/$new_patch/" "$DB_FILE"
|
sed -i "s/\(\b$mod\b\)/$new_patch/" "$DB_FILE"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
@@ -388,6 +391,9 @@ function upgrade_mods() {
|
|||||||
|
|
||||||
# opposite of downgrade_mods
|
# opposite of downgrade_mods
|
||||||
for file in $files; do
|
for file in $files; do
|
||||||
|
# remove disabled_ prefix if it exists
|
||||||
|
file=$(remove_disabled_prefix "$file")
|
||||||
|
|
||||||
current_version=$(echo "$file" | grep -oP '(?<=patch_)\d+')
|
current_version=$(echo "$file" | grep -oP '(?<=patch_)\d+')
|
||||||
base_name=$(get_basename "$file")
|
base_name=$(get_basename "$file")
|
||||||
|
|
||||||
@@ -415,7 +421,7 @@ function upgrade_mods() {
|
|||||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not upgrade mod file $mod." >&2; exit 1; }
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not upgrade mod file $mod." >&2; exit 1; }
|
||||||
echo -e "Upgraded ${ORANGE}$mod${NC} to ${GREEN}\$MODS_DIR/$new_patch${NC}." >&2
|
echo -e "Upgraded ${ORANGE}$mod${NC} to ${GREEN}\$MODS_DIR/$new_patch${NC}." >&2
|
||||||
|
|
||||||
sed -i "s/^$mod$/$new_patch/" "$DB_FILE"
|
sed -i "s/\(\b$mod\b\)/$new_patch/" "$DB_FILE"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
@@ -460,16 +466,23 @@ function mod_disable() {
|
|||||||
# disable each mod file by adding disabled_ to the start of the filename
|
# disable each mod file by adding disabled_ to the start of the filename
|
||||||
files=$(get_files_by_entry_from_db "$entry")
|
files=$(get_files_by_entry_from_db "$entry")
|
||||||
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
|
disabled_file="disabled_$file"
|
||||||
else
|
while [[ -f "$MODS_DIR/$disabled_file" ]]; do
|
||||||
disabled_file="disabled_$file"
|
disabled_file="disabled_$disabled_file"
|
||||||
mv "$MODS_DIR/$file" "$MODS_DIR/$disabled_file"
|
done
|
||||||
echo -e "Disabled ${ORANGE}$file${NC} (changed to ${GREEN}\$MODS_DIR/$disabled_file${NC})." >&2
|
|
||||||
fi
|
mv "$MODS_DIR/$file" "$MODS_DIR/$disabled_file"
|
||||||
|
|
||||||
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not disable mod file $file." >&2; exit 1; }
|
||||||
|
echo -e "Disabled ${ORANGE}$file${NC} (changed to ${GREEN}\$MODS_DIR/$disabled_file${NC})." >&2
|
||||||
|
|
||||||
|
# save change to db
|
||||||
|
sed -i "/^$mod_index,/ s/\(\b$file\b\)/$disabled_file/" "$DB_FILE"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# downgrade mods with greater version number
|
||||||
downgrade_mods "$files"
|
downgrade_mods "$files"
|
||||||
|
|
||||||
# update the database
|
# update the database
|
||||||
@@ -514,16 +527,19 @@ function mod_enable() {
|
|||||||
|
|
||||||
# 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"
|
enabled_file=$(remove_disabled_prefix "$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/$file" ]] || { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; }
|
||||||
|
|
||||||
mv "$MODS_DIR/$disabled_file" "$MODS_DIR/$file"
|
mv "$MODS_DIR/$file" "$MODS_DIR/$enabled_file"
|
||||||
|
|
||||||
# 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 $file." >&2; exit 1; }
|
||||||
echo -e "Enabled ${ORANGE}$disabled_file${NC} (changed to ${GREEN}\$MODS_DIR/$file${NC})." >&2
|
echo -e "Enabled ${ORANGE}$file${NC} (changed to ${GREEN}\$MODS_DIR/$enabled_file${NC})." >&2
|
||||||
|
|
||||||
|
# save change to db
|
||||||
|
sed -i "/^$mod_index,/ s/\(\b$file\b\)/$enabled_file/" "$DB_FILE"
|
||||||
done
|
done
|
||||||
|
|
||||||
# update the database
|
# update the database
|
||||||
@@ -735,8 +751,8 @@ function mod_uninstall() {
|
|||||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not remove mod file $file." >&2; exit 1; }
|
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not remove mod file $file." >&2; exit 1; }
|
||||||
done
|
done
|
||||||
|
|
||||||
# downgrade mods with greater version number
|
# downgrade mods with greater version number, only if the mod is enabled
|
||||||
downgrade_mods "$files"
|
[[ $disabled == false ]] && downgrade_mods "$files"
|
||||||
|
|
||||||
# remove entry from database
|
# remove entry from database
|
||||||
sed -i "/^$mod_index,/d" "$DB_FILE"
|
sed -i "/^$mod_index,/d" "$DB_FILE"
|
||||||
@@ -830,21 +846,6 @@ function mod_import() {
|
|||||||
|
|
||||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Failed to import mods." >&2; exit 1; }
|
[[ $? -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
|
echo -e "Mods imported ${GREEN}successfully${NC}." >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+133
-127
@@ -1,127 +1,133 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
ORANGE='\033[0;33m'
|
ORANGE='\033[0;33m'
|
||||||
NC='\033[0m'
|
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"
|
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."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Main ---
|
# --- Main ---
|
||||||
|
|
||||||
# Warning
|
# Warning
|
||||||
|
|
||||||
echo -e "!!! ${RED}WARNING${NC} !!!"
|
echo -e "!!! ${RED}WARNING${NC} !!!"
|
||||||
echo -e "This script will install Helldivers 2 Mod Manager CLI for Linux to $DESTINATION_PATH/$SCRIPT_NAME."
|
echo -e "This script will install Helldivers 2 Mod Manager CLI for Linux to $DESTINATION_PATH/$SCRIPT_NAME."
|
||||||
echo -e "Running this script will require sudo permissions. ${RED}DO NOT TRUST${NC} random scripts from the internet."
|
echo -e "Running this script will require sudo permissions. ${RED}DO NOT TRUST${NC} random scripts from the internet."
|
||||||
echo -e "If you want to review the script before running it, check out the mod repository for yourself:"
|
echo -e "If you want to review the script before running it, check out the mod repository for yourself:"
|
||||||
echo -e "https://github.com/v4n00/h2mm-cli"
|
echo -e "https://github.com/v4n00/h2mm-cli"
|
||||||
echo -e "!!! ${RED}WARNING${NC} !!!"
|
echo -e "!!! ${RED}WARNING${NC} !!!"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Check if update
|
# Check if update
|
||||||
|
|
||||||
# Breaking changes hash table
|
# Breaking changes hash table
|
||||||
|
|
||||||
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"'
|
["3"]='sed -i "1 i\\3" "$1/mods.csv"'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Handle breaking changes
|
# 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 "$REPO_URL"/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
|
||||||
echo -e "You are upgrading from ${ORANGE}$installed_version${NC} -> ${GREEN}$latest_version${NC}."
|
echo -e "You are upgrading from ${ORANGE}$installed_version${NC} -> ${GREEN}$latest_version${NC}."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# split version numbers
|
# split version numbers
|
||||||
installed_major=""
|
installed_major=""
|
||||||
latest_major=""
|
latest_major=""
|
||||||
IFS='.' read -r _1 installed_major _2 <<< "$installed_version"
|
IFS='.' read -r _1 installed_major _2 <<< "$installed_version"
|
||||||
IFS='.' read -r _1 latest_major _2 <<< "$latest_version"
|
IFS='.' read -r _1 latest_major _2 <<< "$latest_version"
|
||||||
|
|
||||||
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 "${ORANGE}!${NC} Check out the changelogs here:"
|
echo "${ORANGE}!${NC} Check out the changelogs here:"
|
||||||
echo "${ORANGE}!${NC} https://github.com/v4n00/h2mm-cli/releases"
|
echo "${ORANGE}!${NC} 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... (20 seconds timeout)" >&2
|
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)
|
game_dir=$(timeout 20 find "$search_dir" -type d -path "*/$target_dir" 2>/dev/null | head -n 1)
|
||||||
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
|
||||||
IFS= read -ep "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
|
||||||
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
|
||||||
fi
|
fi
|
||||||
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
|
# make backup of mods in case something goes wrong
|
||||||
echo "${ORANGE}V${NC} It is advised to make a backup before proceeding."
|
echo "${ORANGE}V${NC} It is advised to make a backup before proceeding."
|
||||||
h2mm export
|
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
|
||||||
if [[ -n "${breaking_changes_patches[$i]}" ]]; then
|
if [[ -n "${breaking_changes_patches[$i]}" ]]; then
|
||||||
eval $(echo "${breaking_changes_patches[$i]}" | sed "s:\$1:$game_dir:")
|
eval $(echo "${breaking_changes_patches[$i]}" | sed "s:\$1:$game_dir:")
|
||||||
else
|
else
|
||||||
echo "No breaking changes for version $i."
|
echo "No breaking changes for version $i."
|
||||||
fi
|
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
|
||||||
|
|
||||||
[[ "$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 "Breaking changes patch for version ${ORANGE}$i${NC} applied ${GREEN}successfully${NC}."
|
echo -e "Breaking changes patch for version ${ORANGE}$i${NC} applied ${GREEN}successfully${NC}."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
IFS= read -ep "Install the script to $DESTINATION_PATH or specify another path (must be included in \$PATH)? (Y/path): " response
|
# if installing on steam deck, prompt the user, set flag
|
||||||
|
is_steam_deck=false
|
||||||
if [[ "$response" != "y" && "$response" != "Y" && -n "$response" ]]; then
|
IFS= read -ep "Are you installing on a Steam Deck? (y/N): " response_steam_deck
|
||||||
DESTINATION_PATH="$response"
|
[[ "$is_steam_deck" == "y" || "$is_steam_deck" == "Y" ]] && is_steam_deck=true
|
||||||
if [[ ! -d "$DESTINATION_PATH" ]]; then
|
|
||||||
echo -e "${RED}Error:${NC} Path $DESTINATION_PATH does not exist."
|
# other path if needed
|
||||||
exit 1
|
[[ $is_steam_deck == false ]] && IFS= read -ep "Install the script to $DESTINATION_PATH or specify another path (must be included in \$PATH)? (Y/path): " response
|
||||||
fi
|
|
||||||
fi
|
if [[ "$response" != "y" && "$response" != "Y" && -n "$response" ]]; then
|
||||||
|
DESTINATION_PATH="$response"
|
||||||
echo "Installing $SCRIPT_NAME to $DESTINATION_PATH."
|
if [[ ! -d "$DESTINATION_PATH" ]]; then
|
||||||
sudo curl "$REPO_URL"/h2mm --output "$DESTINATION_PATH/$SCRIPT_NAME"
|
echo -e "${RED}Error:${NC} Path $DESTINATION_PATH does not exist."
|
||||||
sudo chmod +x "$DESTINATION_PATH/$SCRIPT_NAME"
|
exit 1
|
||||||
|
fi
|
||||||
if [[ ! -x "$(command -v $SCRIPT_NAME)" ]]; then
|
fi
|
||||||
echo -e "${RED}Error:${NC} Installation failed."
|
|
||||||
exit 1
|
echo "Installing $SCRIPT_NAME to $DESTINATION_PATH."
|
||||||
fi
|
sudo curl "$REPO_URL"/h2mm --output "$DESTINATION_PATH/$SCRIPT_NAME"
|
||||||
|
sudo chmod +x "$DESTINATION_PATH/$SCRIPT_NAME"
|
||||||
echo "Helldivers 2 Mod Manager CLI installed successfully to $DESTINATION_PATH/$SCRIPT_NAME. Use it by running '$SCRIPT_NAME'."
|
|
||||||
|
if [[ ! -x "$(command -v $SCRIPT_NAME)" ]]; then
|
||||||
|
echo -e "${RED}Error:${NC} Installation failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Helldivers 2 Mod Manager CLI installed successfully to $DESTINATION_PATH/$SCRIPT_NAME. Use it by running '$SCRIPT_NAME'."
|
||||||
|
|||||||
Reference in New Issue
Block a user