From 08065942893ce718332d561ef1a1e78784044b01 Mon Sep 17 00:00:00 2001 From: v4n <105587619+v4n00@users.noreply.github.com> Date: Wed, 15 Jan 2025 19:52:18 +0200 Subject: [PATCH] feat: better install script, eval paths --- README.md | 2 ++ h2mm | 1 + install.sh | 28 ++++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cf5e800..4e25e3b 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ To install/update Helldivers 2 Mod Manager CLI run the following command in your sh -c "$(curl -fsSL https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh)" ``` +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. + ## 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. diff --git a/h2mm b/h2mm index 5e99fa3..0748e23 100755 --- a/h2mm +++ b/h2mm @@ -46,6 +46,7 @@ function find_game_directory() { 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 echo -e "${RED}Error${NC}: Provided path is not a valid directory." >&2 exit 1 diff --git a/install.sh b/install.sh index f6d32e5..b82f531 100755 --- a/install.sh +++ b/install.sh @@ -1,20 +1,40 @@ #!/bin/bash set -e +RED='\033[0;31m' +NC='\033[0m' + +DESTINATION_PATH="/usr/local/bin" +SCRIPT_NAME="h2mm" + 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 -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 -echo "Installing $SCRIPT_NAME..." +read -p "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 + DESTINATION_PATH=$(eval echo "$response") + if [[ ! -d "$DESTINATION_PATH" ]]; then + echo -e "${RED}Error:${NC} Path $DESTINATION_PATH does not exist. Exiting..." + exit 1 + fi +fi + +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 chmod +x "$DESTINATION_PATH/$SCRIPT_NAME" if [[ ! -x "$(command -v $SCRIPT_NAME)" ]]; then - echo "Installation failed." + echo -e "${RED}Error:${NC} Installation failed." exit 1 fi