fix: console output, formatting

This commit is contained in:
v4n
2025-02-21 12:46:46 +02:00
parent 0485b56df5
commit 7b8b2fda8f
2 changed files with 58 additions and 67 deletions
+23 -19
View File
@@ -109,7 +109,8 @@ function find_game_directory() {
if [[ -z "$game_dir" ]]; then
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
echo -ne "Please enter the path to the Helldivers 2 data directory:" >&2
IFS= read -e game_dir
game_dir="$(realpath "${game_dir/#\~/$HOME}")"
[[ ! -d "$game_dir" ]] && { echo -e "${RED}Error${NC}: Provided path is not a valid directory." >&2; exit 1; }
@@ -159,21 +160,21 @@ function display_help() {
echo "Helldivers 2 Mod Manager v${VERSION}"
echo "Usage: h2mm [command] [options]"
echo "Commands:"
echo " install Install a mod by the file provided (directory, zip, patch)."
echo " uninstall Uninstall a mod by name (or index)."
echo " list List all installed mods."
echo " enable Enable a mod by name (or index)."
echo " disable Disable a mod by name (or index)."
echo " export Export installed mods to a zip file."
echo " import Import mods from a zip file."
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 " update Update h2mm to the latest version."
echo " i, install Install a mod by the file provided (directory, zip, patch)."
echo " u, uninstall Uninstall a mod by name (or index)."
echo " l, list List all installed mods."
echo " e, enable Enable a mod by name (or index)."
echo " d, disable Disable a mod by name (or index)."
echo " ex, export Export installed mods to a zip file."
echo " im, import Import mods from a zip file."
echo " mc, modpack-create Create a modpack from the currently installed mods."
echo " ms, modpack-switch Switch to a modpack by name (or index)."
echo " ml, modpack-list List all installed modpacks."
echo " mc, modpack-delete Delete a modpack by name (or index)."
echo " mo, modpack-overwrite Overwrite a modpack by name (or index)."
echo " mr, modpack-reset Reset all installed modpacks."
echo " up, update Update h2mm to the latest version."
echo " r, reset Reset all installed mods."
echo " help Display this help message."
echo "For more information on usage, use h2mm [command] --help."
echo "Basic Usage:"
@@ -564,7 +565,7 @@ function mod_reset() {
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): "
echo -ne "Are you sure you want to ${RED}reset${NC} all installed mods? (Y/n): " >&2
read -r confirm
if [[ "$confirm" == "y" || "$confirm" == "Y" || "$confirm" = "" ]]; then
rm -f "$MODS_DIR"/*.patch_*
@@ -799,7 +800,7 @@ function mod_export() {
[[ $(wc -l < "$DB_FILE") -le 1 ]] && { echo "No modpacks saved."; exit 1; }
if [[ $modpack_export == false ]]; then
echo -ne "Archive file will be saved to ${save_dir}/${archive_name}. Make? (Y/n): "
echo -ne "Archive file will be saved to ${save_dir}/${archive_name}. Make? (Y/n): " >&2
read -r confirm
fi
if [[ silent == true || "$confirm" == "y" || "$confirm" == "Y" || "$confirm" = "" ]]; then
@@ -936,7 +937,10 @@ function modpack_reset() {
[[ "$1" == "--force" ]] && force=true
[[ force == false ]] && read -p "Are you sure you want to reset all installed modpacks? (Y/n): " confirm
if [[ force == false ]]; then
echo -ne "Are you sure you want to ${RED}reset${NC} all installed modpacks? (Y/n): " >&2
read confirm
fi
if [[ force == true || "$confirm" == "y" || "$confirm" == "Y" || "$confirm" = "" ]]; then
rm -f "$MODPACKS_FOLDER"/*.tar.gz
rm -f "$MODPACKS_DB_FILE"
+33 -46
View File
@@ -10,22 +10,17 @@ DESTINATION_PATH="/usr/local/bin"
SCRIPT_NAME="h2mm"
REPO_URL="https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master"
if [ "$(id -u)" -eq 0 ]; then
echo "Run me as normal user, not as root."
exit 1
fi
# --- Main ---
# Warning
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 "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 "https://github.com/v4n00/h2mm-cli"
echo -e "!!! ${RED}WARNING${NC} !!!"
echo
echo -e "!!! ${RED}WARNING${NC} !!!" >&2
echo -e "This script will install Helldivers 2 Mod Manager CLI for Linux to $DESTINATION_PATH/$SCRIPT_NAME." >&2
echo -e "Running this script will require sudo permissions. ${RED}DO NOT TRUST${NC} random scripts from the internet." >&2
echo -e "If you want to review the script before running it, check out the mod repository for yourself:" >&2
echo -e "https://github.com/v4n00/h2mm-cli" >&2
echo -e "!!! ${RED}WARNING${NC} !!!" >&2
echo >&2
# Check if update
@@ -45,9 +40,9 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
latest_version=$(curl -sS "$REPO_URL"/version)
if [[ "$latest_version" == "$installed_version" ]]; then
echo -e "You are reinstalling version ${GREEN}$installed_version${NC}."
echo -e "You are reinstalling version ${GREEN}$installed_version${NC}." >&2
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}." >&2
fi
# split version numbers
@@ -57,9 +52,9 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
IFS='.' read -r _1 latest_major _2 <<< "$latest_version"
if [[ $latest_major -gt $installed_major ]]; then
echo -e "${ORANGE}Warning:${NC} Major version upgrade detected."
echo "${ORANGE}Info${NC}: Check out the changelogs here -> https://github.com/v4n00/h2mm-cli/releases"
echo "The script will proceed to upgrade ${SCRIPT_NAME} to avoid breaking changes."
echo -e "${ORANGE}Warning:${NC} Major version upgrade detected." >&2
echo -e "${ORANGE}Info${NC}: Check out the changelogs here -> https://github.com/v4n00/h2mm-cli/releases" >&2
echo -e "The script will proceed to upgrade ${SCRIPT_NAME} to avoid breaking changes." >&2
# find hd2 path
search_dir="${HOME}"
@@ -69,33 +64,30 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
game_dir=$(timeout 20 find "$search_dir" -type d -path "*/$target_dir" 2>/dev/null | head -n 1)
if [[ -z "$game_dir" ]]; then
echo "Could not find the Helldivers 2 data directory automatically." >&2
IFS= read -ep "Please enter the path to the Helldivers 2 data directory: " game_dir
echo -ne "Please enter the path to the Helldivers 2 data directory: " >&2
IFS= read -e game_dir
if [[ ! -d "$game_dir" ]]; then
echo -e "${RED}Error${NC}: Provided path is not a valid directory." >&2
exit 1
fi
fi
[[ ! -f "$game_dir/mods.csv" ]] && { echo -e "${RED}Error:${NC} mods.csv not found in $game_dir."; exit 1; }
# make backup of mods in case something goes wrong
echo "${ORANGE}V${NC} It is advised to make a backup before proceeding."
h2mm export
[[ ! -f "$game_dir/mods.csv" ]] && { echo -e "${RED}Error:${NC} mods.csv not found in $game_dir." >&2; exit 1; }
# iterate from installed major number to latest major number
for ((i = installed_major + 1; i <= latest_major; i++)); do
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."
echo "No breaking changes for version $i." >&2
fi
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): " >&2
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." >&2; exit 1; }
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}." >&2
fi
done
fi
@@ -105,7 +97,9 @@ fi
# Install
# if steam deck, set destination path to ~/.local/bin
IFS= read -ep "Are you installing on a Steam Deck? (y/N): " response_sd
echo -ne "Are you installing on a Steam Deck? (y/N): " >&2
IFS= read -e response_sd
if [[ "$response_sd" == "y" || "$response_sd" == "Y" ]]; then
# steam deck
DESTINATION_PATH="$HOME/.local/bin"
@@ -114,39 +108,32 @@ if [[ "$response_sd" == "y" || "$response_sd" == "Y" ]]; then
# check if ~/.local/bin is in PATH
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
# add ~/.local/bin to PATH
echo -e "${ORANGE}Warning:${NC} Installing the script on a Steam Deck means adding $DESTINATION_PATH to your \$PATH."
echo -e "${ORANGE}Warning:${NC} If you're using a different shell, you may need to add it manually."
echo -e "${ORANGE}Warning:${NC} Installing the script on a Steam Deck means adding $DESTINATION_PATH to your \$PATH." >&2
echo -e "${ORANGE}Warning:${NC} If you're using a different shell than bash, you may need to add it manually." >&2
IFS= read -ep "Do you want to add $DESTINATION_PATH to your \$PATH in ~/.bashrc? (Y/n): " response
echo -ne "Do you want to add $DESTINATION_PATH to your \$PATH in ~/.bashrc? (Y/n): " >&2
IFS= read -e response
if [[ "$response" == "y" || "$response" = "Y" || -z "$response" ]]; then
echo "export PATH=\"\$HOME/.local/bin:\$PATH\"" >> "$HOME/.bashrc"
echo -e "${GREEN}Success:${NC} Added $DESTINATION_PATH to your \$PATH in ~/.bashrc."
echo -e "${GREEN}Success:${NC} Added $DESTINATION_PATH to your \$PATH in ~/.bashrc." >&2
fi
fi
else
# not steam deck
# set another path if needed
IFS= read -ep "Install the script to $DESTINATION_PATH or specify another path (must be included in \$PATH)? (Y/path): " response
echo -ne "Install the script to $DESTINATION_PATH or specify another path (must be included in \$PATH)? (Y/path): " >&2
IFS= read -e response
if [[ "$response" != "y" && "$response" != "Y" && -n "$response" ]]; then
DESTINATION_PATH="$response"
[[ ! -d "$DESTINATION_PATH" ]] && { echo -e "${RED}Error:${NC} Path $DESTINATION_PATH does not exist."; exit 1; }
[[ ! -d "$DESTINATION_PATH" ]] && { echo -e "${RED}Error:${NC} Path $DESTINATION_PATH does not exist." >&2; exit 1; }
fi
fi
echo "Installing $SCRIPT_NAME to $DESTINATION_PATH."
if [ -r "$DESTINATION_PATH" ]; then
curl "$REPO_URL"/h2mm --output "$DESTINATION_PATH/$SCRIPT_NAME"
chmod +x "$DESTINATION_PATH/$SCRIPT_NAME"
else
echo -e "Installing $SCRIPT_NAME to $DESTINATION_PATH." >&2
sudo curl "$REPO_URL"/h2mm --output "$DESTINATION_PATH/$SCRIPT_NAME"
sudo chmod +x "$DESTINATION_PATH/$SCRIPT_NAME"
fi
[[ ! -x "$(command -v $SCRIPT_NAME)" ]] && { echo -e "${RED}Error:${NC} Installation failed. Mod manager was not found in \$PATH." >&2; exit 1; }
if [[ ! -x "$(command -v $SCRIPT_NAME)" ]]; then
echo -e "${RED}Error:${NC} Installation failed. Mod manager was not found in PATH."
exit 1
fi
echo "Helldivers 2 Mod Manager CLI installed successfully to $DESTINATION_PATH/$SCRIPT_NAME. Use it by running '$SCRIPT_NAME'."
echo "Helldivers 2 Mod Manager CLI installed successfully to $DESTINATION_PATH/$SCRIPT_NAME. Use it by running '$SCRIPT_NAME'." >&2