From 96456cef6eb3bf6f9e452b4c634a261eeebca2b0 Mon Sep 17 00:00:00 2001 From: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue, 4 Aug 2020 13:56:47 +0300 Subject: [PATCH] brewlog is installed in the same place as homebrew commit 34f328de594f4df5e4f40ec1c2f5f148a2abb650 Author: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue Aug 4 13:55:02 2020 +0300 Update install.sh Fix checking if the installation location is writable or not To ensure that "brewlog" is in the same path as "brew" commit 6296379a5525eb623b2347536c215c6405b2188a Author: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue Aug 4 13:50:33 2020 +0300 change order of checking shopt nocasematch commit 6889284f6b1f0b3cfd0c58bf608e39eda64a250e Author: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue Aug 4 13:48:20 2020 +0300 Installs in the same place as homebrew commit f67e85057547da42b5ea21e3b3c9997ec17a3b41 Author: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue Aug 4 13:37:25 2020 +0300 Trying to install to the same place as homebrew --- install.sh | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/install.sh b/install.sh index 1ad0f17..81bf3b6 100644 --- a/install.sh +++ b/install.sh @@ -1,26 +1,38 @@ #!/bin/bash -if [ -w /usr/local/bin ]; then - curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/brewlog.sh' > /usr/local/bin/brewlog - chmod +x /usr/local/bin/brewlog +BREWLOCATION=$(command -v brew) +if [ "$?" -ne "0" ]; then + echo "Homebrew/Linux brew installation not detected in your PATH." + exit 1 +else + BREWLOCATION=$(dirname "$BREWLOCATION") + echo "Determined installation location: $BREWLOCATION/brewlog" +fi + +if [ -w $BREWLOCATION ]; then + curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/brewlog.sh' > $BREWLOCATION/brewlog + chmod +x $BREWLOCATION/brewlog + printf " +brewlog has been installed as $(command -v brewlog). +You can start with brewlog --help %s\n" else - curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/brewlog.sh' >| brewlog.sh - echo "user $(whoami) cannot write to /usr/local/bin." - read -r -p "use sudo (y/N): " choice shopt -q nocasematch; if [ "$?" -eq "1" ]; then shopt -s nocasematch flag=1 fi + curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/brewlog.sh' >| brewlog.sh + echo "user $(whoami) cannot write to $BREWLOCATION" + read -r -p "use sudo (y/N): " choice if [[ "$choice" =~ ^(yes|y)$ ]] then - sudo mv brewlog.sh /usr/local/bin/brewlog - sudo chmod +x /usr/local/bin/brewlog + sudo mv brewlog.sh $BREWLOCATION/brewlog + sudo chmod +x $BREWLOCATION/brewlog sudo -k else - echo "cannot install /usr/local/bin/brewlog without sudo rights" + echo "cannot install $BREWLOCATION/brewlog without sudo rights" exit 1; fi if [ "$flag" -eq "1" ]; then shopt -s nocasematch fi -fi \ No newline at end of file +fi