diff --git a/.gitignore b/.gitignore index 3c28b6a..34327d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -* -!h2mm -!install.sh +* +!h2mm +!install.sh !README.md \ No newline at end of file diff --git a/README.md b/README.md index 7487e66..8ede562 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# h2mm-cli - -install - -```bash -sh -c "$(curl -fsSL https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh)" -``` +# h2mm-cli + +install + +```bash +sh -c "$(curl -fsSL https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh)" +``` diff --git a/h2mm b/h2mm index 7818e0d..f46201e 100755 --- a/h2mm +++ b/h2mm @@ -1,4 +1,5 @@ #!/bin/bash +# Helldivers 2 Mod Manager # --- Globals --- @@ -53,7 +54,14 @@ function find_game_directory() { fi echo "$game_dir" > "$H2PATH" - echo -e "Game directory ${GREEN}saved${NC}: $game_dir" >&2 + + if [[ $? -eq 0 ]]; then + echo -e "Game directory ${GREEN}saved${NC}: $game_dir" >&2 + else + echo -e "${RED}Error${NC}: Could not save game directory." + exit 1 + fi + echo "$game_dir" } @@ -63,7 +71,12 @@ function initialize_directories() { if [[ ! -f "$DB_FILE" ]]; then touch "$DB_FILE" - echo "Database file created at: $DB_FILE" + if [[ $? -eq 0 ]]; then + echo "Database file created at: $DB_FILE" + else + echo -e "${RED}Error${NC}: Could not create database file." + exit 1 + fi fi echo "--- /// MAIN /// ---" >&2 @@ -254,6 +267,7 @@ function mod_install() { fi patch_count["$base_name"]=$count + # if the file has an extension, look for the last patch number and use that extension=$(echo "$file" | sed -E 's/.*patch_[0-9]+//') if [[ -n "$extension" ]]; then target_file="${base_name}.patch_$((patch_count[$base_name] - 1))${extension}" @@ -264,7 +278,12 @@ function mod_install() { target_files+=($target_file) cp "$file" "$MODS_DIR/$target_file" - echo -e "Mod file ${ORANGE}$file${NC} installed at ${GREEN}\$MODS_DIR/$target_file${NC}." + if [[ $? -eq 1 ]]; then + echo -e "Mod file ${ORANGE}$file${NC} installed at ${GREEN}\$MODS_DIR/$target_file${NC}." + else + echo -e "${RED}Error${NC}: Could not install mod file $file." + exit 1 + fi done # add entry to database @@ -339,6 +358,7 @@ function mod_uninstall() { for file in $files; do if [[ ! -f "$MODS_DIR/$file" ]]; then echo -e "${RED}Error${NC}: Mod file $file does not exist." + exit 1 else echo -e "Removing ${ORANGE}\$MODS_DIR/$file${NC}." rm -f "$MODS_DIR/$file" @@ -399,10 +419,15 @@ function mod_export() { current_path=$(pwd) zip_name="Helldivers_2_Mods_$(date +%Y-%m-%d_%H-%M-%S).zip" - cd "$OUT_DIR" && - zip -r "$zip_name" "Helldivers 2 Mods" && - mv "$zip_name" "$current_path" && - echo -e "Mods exported to ${GREEN}$current_path/$zip_name${NC}." + cd "$OUT_DIR" + zip -r "$zip_name" "Helldivers 2 Mods" + mv "$zip_name" "$current_path" + + if [[ $? -eq 0 ]]; then + echo -e "Mods exported to ${GREEN}$current_path/$zip_name${NC}." + else + echo -e "${RED}Error${NC}: Failed to export mods." + fi fi } @@ -438,7 +463,11 @@ function mod_import() { # copy mods verbosely cp -v "$MODS_EXPORT_DIR"/* "$MODS_DIR" - echo -e "Mods imported ${GREEN}successfully${NC}." + if [[ $? -eq 0 ]]; then + echo -e "Mods imported ${GREEN}successfully${NC}." + else + echo -e "${RED}Error${NC}: Failed to import mods." + fi } # --- Main --- @@ -483,4 +512,4 @@ function main() { echo "--- /// END /// ---" } -main "$@" \ No newline at end of file +main "$@" diff --git a/install.sh b/install.sh index 136f55d..486f4db 100755 --- a/install.sh +++ b/install.sh @@ -1,21 +1,21 @@ -#!/bin/bash -set -e - -if [ "$(id -u)" -eq 0 ]; then - echo "Run me as normal user, not as root." - exit 1 -fi - -DESTINATION_PATH="/usr/local/bin" -SCRIPT_NAME="h2mm" - -echo "Installing $SCRIPT_NAME..." -sudo curl https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/h2mm --output "$DESTINATION_PATH/$SCRIPT_NAME" -sudo chmod +x "$DESTINATION_PATH/$SCRIPT_NAME" - -if [[ ! -x "$(command -v $SCRIPT_NAME)" ]]; then - echo "Installation failed." - exit 1 -fi - -echo "Helldivers 2 Mod Manager CLI installed successfully to $DESTINATION_PATH/$SCRIPT_NAME. Use it by running '$SCRIPT_NAME'." +#!/bin/bash +set -e + +if [ "$(id -u)" -eq 0 ]; then + echo "Run me as normal user, not as root." + exit 1 +fi + +DESTINATION_PATH="/usr/local/bin" +SCRIPT_NAME="h2mm" + +echo "Installing $SCRIPT_NAME..." +sudo curl https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/h2mm --output "$DESTINATION_PATH/$SCRIPT_NAME" +sudo chmod +x "$DESTINATION_PATH/$SCRIPT_NAME" + +if [[ ! -x "$(command -v $SCRIPT_NAME)" ]]; then + echo "Installation failed." + exit 1 +fi + +echo "Helldivers 2 Mod Manager CLI installed successfully to $DESTINATION_PATH/$SCRIPT_NAME. Use it by running '$SCRIPT_NAME'."