From b6e92e29184e00a9f091abb9cd12e82254233a12 Mon Sep 17 00:00:00 2001 From: v4n <105587619+v4n00@users.noreply.github.com> Date: Sat, 22 Mar 2025 20:23:21 +0200 Subject: [PATCH] feat: install rar mods (#34) --- README.md | 10 +++++++++- h2mm | 18 ++++++++++++++---- install.sh | 11 +++++++++-- version | 2 +- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 029d2a9..7ad35b0 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,13 @@ This script is complete, the version will always [remain at 0.x.x](https://0ver. ## Installation +Pre-requisites: + +- You must have the `unzip` package installed for zip archives; +- You might want to have the `unarchiver` package installed for rar archives. + +> The `unzip` package comes pre-installed on most Linux distributions. If you do not know how to install packages, search for your Linux distro and package manager. + To install Helldivers 2 Mod Manager CLI run the following command in your terminal: ```bash @@ -19,7 +26,8 @@ If for some reason, the installation command doesn't work you can: 1. Go to 1. Right click -> Save page as... -1. Go to your downloads folders `cd ~/Downloads` +1. Open your terminal +1. Go to your downloads folders with `cd ~/Downloads` 1. Give the script execution permissions `chmod +x install.sh` 1. Run the script `./install.sh` diff --git a/h2mm b/h2mm index 2507b75..da36906 100755 --- a/h2mm +++ b/h2mm @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION="0.4.1" +VERSION="0.4.2" # --- Globals --- @@ -672,6 +672,7 @@ function mod_install() { local mod_dir=() local mod_files=() local mod_zip=() + local is_rar=false # parse arguments while [[ $# -gt 0 ]]; do @@ -681,8 +682,9 @@ function mod_install() { mod_name="$2"; shift 2 ;; *) - if [[ -f "$1" && "$1" == *.zip ]]; then + if [[ -f "$1" && ( "$1" == *.zip || "$1" == *.rar ) ]]; then mod_zip+=("$1") + [[ "$1" == *.rar ]] && is_rar=true elif [[ -d "$1" ]]; then mod_dir+=("$1") else @@ -714,7 +716,11 @@ function mod_install() { # if zip, extract the zip file and pass it to mod dirs if [[ -n "$mod_zip" ]]; then - command -v unzip &> /dev/null || { log ERROR "unzip package is not installed."; exit 1; } + if [[ $is_rar == true ]]; then + command -v unar &> /dev/null || { log ERROR "Rar archive could not be extracted because package \"unarchiver\" is not installed."; exit 1; } + else + command -v unzip &> /dev/null || { log ERROR "Zip archive could not be extracted because package \"unzip\" is not installed."; exit 1; } + fi [[ ! -f "$mod_zip" ]] && { log ERROR "Zip file $mod_zip does not exist."; exit 1; } @@ -725,7 +731,11 @@ function mod_install() { # mod_dir as a temporary directory mod_dir+=$(mktemp -d) - unzip -qq "$mod_zip" -d "$mod_dir" + if [[ $is_rar == true ]]; then + unar -q "$mod_zip" -o "$mod_dir" + else + unzip -qq "$mod_zip" -d "$mod_dir" + fi fi # if there's more than 1 directory, call recursively diff --git a/install.sh b/install.sh index 47c75f0..625e9f5 100755 --- a/install.sh +++ b/install.sh @@ -179,5 +179,12 @@ sudo chmod +x "$DESTINATION_PATH/$SCRIPT_NAME" log INFO "" [[ ! -x "$(command -v $SCRIPT_NAME)" ]] && { log ERROR "Installation failed. Mod manager was not found in \$PATH." ; exit 1; } -log INFO "Helldivers 2 Mod Manager CLI ${GREEN}successfully${NC} installed: $DESTINATION_PATH/$SCRIPT_NAME." -log INFO "Use it by running '$SCRIPT_NAME'. Made with love <3 by v4n and contributors." + +log INFO "Helldivers 2 Mod Manager CLI ${GREEN}successfully${NC} installed." +log INFO "${GREEN}IMPORTANT${NC}: To install mods, you need to have installed:" +log INFO " -> \"unzip\" package for .zip archives" +log INFO " -> \"unarchiver\" package for .rar archives" +log INFO "If you do not know how to install these packages, please search for your linux distro on how to install packages." +log INFO "" +log INFO "Use the mod manager by running '$SCRIPT_NAME' in your terminal." +log INFO "Made with love <3 by v4n and contributors." diff --git a/version b/version index 267577d..2b7c5ae 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.4.1 +0.4.2