mirror of
https://github.com/nadrad/h-m-m.git
synced 2024-06-13 04:42:13 +02:00
Merge pull request #26 from llagerlof/main
Install script converted from bash to sh
This commit is contained in:
commit
7ebfd19392
70
install.sh
70
install.sh
|
@ -1,8 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
HMM_PATH="$(dirname $0)/h-m-m"
|
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"
|
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"
|
DESTINATION_DIR=/usr/local/bin
|
||||||
|
|
||||||
# Test if /usr/local/bin exists. If not fallback to /usr/bin
|
# Test if /usr/local/bin exists. If not fallback to /usr/bin
|
||||||
if [ ! -d "$DESTINATION_DIR" ]; then
|
if [ ! -d "$DESTINATION_DIR" ]; then
|
||||||
|
@ -11,67 +11,61 @@ fi
|
||||||
|
|
||||||
# If h-m-m doesn't exist in the same directory as this script, tries to download from github repository
|
# 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 [ ! -f "$HMM_PATH" ]; then
|
||||||
|
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
|
||||||
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
|
|
||||||
|
|
||||||
HMM_PATH="/tmp/h-m-m"
|
HMM_PATH="/tmp/h-m-m"
|
||||||
else
|
else
|
||||||
echo -e "ERROR: Online repository not available or Internet is down\n"
|
printf "ERROR: Could not download h-m-m\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
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
|
# Test if php is on PATH
|
||||||
if ! command -v php &> /dev/null ;then
|
if ! command -v php > /dev/null 2>&1;then
|
||||||
echo -e "ERROR: php executable not found on PATH. Installation cancelled.\n";
|
printf "ERROR: php executable not found on PATH. Installation cancelled.\n";
|
||||||
echo -e $MINIMUM_REQUIREMENTS
|
printf "%s\n" "$MINIMUM_REQUIREMENTS"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Test if xclip, xsel or wl-clipboard are on PATH
|
# 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
|
if ! command -v xclip > /dev/null 2>&1 && ! command -v xsel > /dev/null 2>&1 && ! command -v wl-clipboard > /dev/null 2>&1 ;then
|
||||||
echo -e "ERROR: xclip, xsel or wl-clipboard must exist on PATH. Installation cancelled.\n";
|
printf "ERROR: xclip, xsel or wl-clipboard must exist on PATH. Installation cancelled.\n";
|
||||||
echo -e $MINIMUM_REQUIREMENTS
|
printf "%s\n" "$MINIMUM_REQUIREMENTS"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ask for user confirmation to install the script
|
# 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"
|
printf "This script will install h-m-m on %s and make it executable.\n" "$DESTINATION_DIR"
|
||||||
echo -e "Proceed (y/N)?"
|
printf "Proceed (y/N)?"
|
||||||
|
|
||||||
read a </dev/tty
|
read -r a </dev/tty
|
||||||
|
|
||||||
if [[ ! "$a" =~ ^(y|Y) ]] ;then
|
printf "\n"
|
||||||
echo -e "Installation cancelled."
|
|
||||||
|
if ! printf "%s" "$a" | grep -q "^[yY]"; then
|
||||||
|
printf "Installation cancelled.\n"
|
||||||
exit 125
|
exit 125
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ask for user confirmation to overwrite if the script is already installed
|
# Ask for user confirmation to overwrite if the script is already installed
|
||||||
if test -f "$DESTINATION_DIR/h-m-m"; then
|
if test -f "$DESTINATION_DIR/h-m-m"; then
|
||||||
echo -e "The file $DESTINATION_DIR/h-m-m already exist.\n"
|
printf "The file %s/h-m-m already exist.\n" "$DESTINATION_DIR"
|
||||||
echo -e "Overwrite (y/N)?"
|
printf "Overwrite (y/N)?"
|
||||||
|
|
||||||
read a </dev/tty
|
read -r a </dev/tty
|
||||||
|
|
||||||
if [[ ! "$a" =~ ^(y|Y) ]] ;then
|
printf "\n"
|
||||||
echo -e "Installation cancelled."
|
|
||||||
|
if ! printf "%s" "$a" | grep -q "^[yY]"; then
|
||||||
|
printf "Installation cancelled.\n"
|
||||||
exit 125
|
exit 125
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Copy the script
|
# Copy the script
|
||||||
sudo cp $HMM_PATH $DESTINATION_DIR/h-m-m
|
if ! sudo cp "$HMM_PATH" "$DESTINATION_DIR/h-m-m"; then
|
||||||
|
printf "ERROR: Could not copy h-m-m to %s\n" "$DESTINATION_DIR"
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo -e "ERROR: Could not copy h-m-m to $DESTINATION_DIR\n"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -81,9 +75,9 @@ rm -f /tmp/h-m-m
|
||||||
# Make the copied file executable
|
# Make the copied file executable
|
||||||
sudo chmod +x $DESTINATION_DIR/h-m-m
|
sudo chmod +x $DESTINATION_DIR/h-m-m
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if ! sudo chmod +x $DESTINATION_DIR/h-m-m; then
|
||||||
echo -e "ERROR: Could not make the script $DESTINATION_DIR/h-m-m executable.\n"
|
printf "ERROR: Could not make the script %s/h-m-m executable.\n" "$DESTINATION_DIR"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\nSUCCESS! h-m-m installed.\n"
|
printf "\nSUCCESS! h-m-m installed.\n"
|
||||||
|
|
|
@ -154,7 +154,7 @@ In Arch Linux, you can use the `h-m-m-git` AUR package to install it.
|
||||||
You can run the following command to install h-m-m:
|
You can run the following command to install h-m-m:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
wget -q -O - 'https://raw.githubusercontent.com/nadrad/h-m-m/main/install.sh' | bash
|
wget -q -O - 'https://raw.githubusercontent.com/nadrad/h-m-m/main/install.sh' | sh
|
||||||
```
|
```
|
||||||
|
|
||||||
This command downloads and runs the install.sh script, which it turn downloads h-m-m, copies it to `/usr/local/bin`, checks the dependencies, and makes it executable.
|
This command downloads and runs the install.sh script, which it turn downloads h-m-m, copies it to `/usr/local/bin`, checks the dependencies, and makes it executable.
|
||||||
|
|
Loading…
Reference in a new issue