diff --git a/install.sh b/install.sh index 89a409e..5f08870 100644 --- a/install.sh +++ b/install.sh @@ -1,8 +1,8 @@ -#!/bin/bash +#!/bin/sh -HMM_PATH="$(dirname $0)/h-m-m" -MINIMUM_REQUIREMENTS="MINIMUM REQUIREMENTS: PHP 7+ and one of these three must exist on PATH: xclip, xsel or wl-clipboard\n" -DESTINATION_DIR="/usr/local/bin" +HMM_PATH=$(dirname "$0")/h-m-m +MINIMUM_REQUIREMENTS="MINIMUM REQUIREMENTS: PHP 7+ and one of these three must exist on PATH: xclip, xsel or wl-clipboard." +DESTINATION_DIR=/usr/local/bin # Test if /usr/local/bin exists. If not fallback to /usr/bin if [ ! -d "$DESTINATION_DIR" ]; then @@ -11,67 +11,57 @@ fi # If h-m-m doesn't exist in the same directory as this script, tries to download from github repository if [ ! -f "$HMM_PATH" ]; then - - if [[ $(curl --write-out '%{http_code}' --silent https://raw.githubusercontent.com/nadrad/h-m-m/main/h-m-m --output /dev/null) == 200 ]]; then - curl --silent https://raw.githubusercontent.com/nadrad/h-m-m/main/h-m-m --output /tmp/h-m-m - - if [ $? -ne 0 ]; then - echo -e "ERROR: Could not download h-m-m\n" - exit 1 - fi - + if [ "$(curl --write-out '%{http_code}' --silent https://raw.githubusercontent.com/nadrad/h-m-m/main/h-m-m --output /tmp/h-m-m)" = "200" ]; then HMM_PATH="/tmp/h-m-m" else - echo -e "ERROR: Online repository not available or Internet is down\n" + printf "ERROR: Could not download h-m-m\n" exit 1 fi fi -echo -e "\n> Installer for h-m-m\n" +printf "\n> Installer for h-m-m\n\n" # Test if php is on PATH -if ! command -v php &> /dev/null ;then - echo -e "ERROR: php executable not found on PATH. Installation cancelled.\n"; - echo -e $MINIMUM_REQUIREMENTS +if ! command -v php > /dev/null 2>&1;then + printf "ERROR: php executable not found on PATH. Installation cancelled.\n"; + printf "%s\n" "$MINIMUM_REQUIREMENTS" exit 1 fi # Test if xclip, xsel or wl-clipboard are on PATH -if ! command -v xclip &> /dev/null && ! command -v xsel &> /dev/null && ! command -v wl-clipboard &> /dev/null ;then - echo -e "ERROR: xclip, xsel or wl-clipboard must exist on PATH. Installation cancelled.\n"; - echo -e $MINIMUM_REQUIREMENTS +if ! command -v xclip > /dev/null 2>&1 && ! command -v xsel > /dev/null 2>&1 && ! command -v wl-clipboard > /dev/null 2>&1 ;then + printf "ERROR: xclip, xsel or wl-clipboard must exist on PATH. Installation cancelled.\n"; + printf "%s\n" "$MINIMUM_REQUIREMENTS" exit 1 fi # Ask for user confirmation to install the script -echo -e "This script will install h-m-m on $DESTINATION_DIR and make it executable.\n" -echo -e "Proceed (y/N)?" +printf "This script will install h-m-m on %s and make it executable.\n" "$DESTINATION_DIR" +printf "Proceed (y/N)?" -read a