From 09ce96483757aa78361b4c6dc9acbdafb5fa505a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kn=C3=B6rig?= Date: Wed, 28 Aug 2024 16:27:02 +0300 Subject: [PATCH] Clarify default install directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The install script seems to suggest `/usr/local/bin` as the default install directory. However, pressing `RETURN` will actually set the install dir to an empty string. The error message is not helpful as it then reads `The directory does not exist.` (note the additional space). This fix makes the script behave as expected: pressing `RETURN` accepts the default suggestion. Signed-off-by: André Knörig --- tools/install.sh | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index 0bdf37fe7e..13f7733938 100644 --- a/tools/install.sh +++ b/tools/install.sh @@ -42,6 +42,22 @@ # SOFTWARE. set -e +set_install_dir() { + # Set install directory + DEFAULT_INSTALL_DIR="/usr/local/bin" + if [ -z "${INSTALL_DIR}" ]; then + read -p "Install location? [$DEFAULT_INSTALL_DIR]: " INSTALL_DIR + INSTALL_DIR=${INSTALL_DIR:-$DEFAULT_INSTALL_DIR} + fi + if [ ! -d "$INSTALL_DIR" ]; then + echo "The directory $INSTALL_DIR does not exist. Please create it and re-run this script." + # Ask user to manually create directory rather than making it for them, + # so they don't just type in "y" again and accidentally install at ./y + exit 1 + fi + # Expand abbreviations in INSTALL_DIR + INSTALL_DIR=$(cd "$INSTALL_DIR"; pwd) +} command_exists() { command -v "$@" >/dev/null 2>&1 @@ -150,18 +166,7 @@ main() { esac fi - # Set install directory - if [ -z "${INSTALL_DIR}" ]; then - read -p "Install location? [/usr/local/bin]: " INSTALL_DIR - fi - if [ ! -d "$INSTALL_DIR" ]; then - echo "The directory $INSTALL_DIR does not exist. Please create it and re-run this script." - # Ask user to manually create directory rather than making it for them, - # so they don't just type in "y" again and accidentally install at ./y - exit 1 - fi - # Expand abbreviations in INSTALL_DIR - INSTALL_DIR=$(cd "$INSTALL_DIR"; pwd) + set_install_dir # Check if `cog` command already exists if command_exists cog; then