From f67e85057547da42b5ea21e3b3c9997ec17a3b41 Mon Sep 17 00:00:00 2001 From: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue, 4 Aug 2020 13:37:25 +0300 Subject: [PATCH 1/6] Trying to install to the same place as homebrew --- install.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 1ad0f17..76b33ab 100644 --- a/install.sh +++ b/install.sh @@ -1,10 +1,19 @@ #!/bin/bash +BREWLOCATION=$(command -v brew) +echo "$BREWLOCATION/brewlog" +if [ "$?" -ne "0" ]; then + echo "Homebrew/Linux brew installation not detected in your PATH." + exit 1 +else + BREWLOCATION= $(dirname "$BREWLOCATION") +fi + 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 + curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/brewlog.sh' > $BREWLOCATION/brewlog + chmod +x $BREWLOCATION/brewlog else curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/brewlog.sh' >| brewlog.sh - echo "user $(whoami) cannot write to /usr/local/bin." + echo "user $(whoami) cannot write to $BREWLOCATION" read -r -p "use sudo (y/N): " choice shopt -q nocasematch; if [ "$?" -eq "1" ]; then @@ -13,11 +22,11 @@ else fi 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 From 6889284f6b1f0b3cfd0c58bf608e39eda64a250e Mon Sep 17 00:00:00 2001 From: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue, 4 Aug 2020 13:48:20 +0300 Subject: [PATCH 2/6] Installs in the same place as homebrew --- install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 76b33ab..52a722e 100644 --- a/install.sh +++ b/install.sh @@ -1,16 +1,19 @@ #!/bin/bash BREWLOCATION=$(command -v brew) -echo "$BREWLOCATION/brewlog" if [ "$?" -ne "0" ]; then echo "Homebrew/Linux brew installation not detected in your PATH." exit 1 else - BREWLOCATION= $(dirname "$BREWLOCATION") + BREWLOCATION=$(dirname "$BREWLOCATION") + echo "Determined installation location: $BREWLOCATION/brewlog" fi if [ -w /usr/local/bin ]; 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 $BREWLOCATION" From 6296379a5525eb623b2347536c215c6405b2188a Mon Sep 17 00:00:00 2001 From: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue, 4 Aug 2020 13:50:33 +0300 Subject: [PATCH 3/6] change order of checking shopt nocasematch --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 52a722e..3a41e48 100644 --- a/install.sh +++ b/install.sh @@ -15,14 +15,14 @@ if [ -w /usr/local/bin ]; then 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 $BREWLOCATION" - 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 $BREWLOCATION/brewlog From 34f328de594f4df5e4f40ec1c2f5f148a2abb650 Mon Sep 17 00:00:00 2001 From: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue, 4 Aug 2020 13:55:02 +0300 Subject: [PATCH 4/6] Update install.sh Fix checking if the installation location is writable or not --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 3a41e48..81bf3b6 100644 --- a/install.sh +++ b/install.sh @@ -8,7 +8,7 @@ else echo "Determined installation location: $BREWLOCATION/brewlog" fi -if [ -w /usr/local/bin ]; then +if [ -w $BREWLOCATION ]; then curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/brewlog.sh' > $BREWLOCATION/brewlog chmod +x $BREWLOCATION/brewlog printf " @@ -35,4 +35,4 @@ else if [ "$flag" -eq "1" ]; then shopt -s nocasematch fi -fi \ No newline at end of file +fi From 89a3b71e24dcf67c98fc9384d0250256bc871ed2 Mon Sep 17 00:00:00 2001 From: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue, 4 Aug 2020 15:50:36 +0300 Subject: [PATCH 5/6] update readme Improve wording. --- README.md | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1815ae9..6cf534b 100644 --- a/README.md +++ b/README.md @@ -7,25 +7,36 @@ ### Why? -I wrote Brewlog to fulfill a shortcoming I felt [homebrew](https://brew.sh/) has had for a long time. I got the basic idea from [a very old issue on homebrew](https://github.com/Homebrew/legacy-homebrew/issues/10430). +I wrote [ `brewlog`](https://github.com/robocopAlpha/brewlog/) to patch a minor but IMHO a significant shortcoming I feel [homebrew](https://brew.sh/) has had for very long time. It is the ability to log what homebrew does. IMO it doesn’t have to be something very sophisticated i.e. integration with system-log, etc.. So, I worked on a basic idea I got from [this particular issue](https://github.com/Homebrew/legacy-homebrew/issues/10430) and developed `brewlog`. + + + +### Why bother with a log file, when brew is so stable? + +`brew` is generally very stable, but occasionally it breaks compatibility when it is upgrading some packages and removes some “obsolete” versions. Generally this is fine, but in certain cases the user wants to retain those packages for compatibility with something else. I recently faced [a problem](https://github.com/brewsci/homebrew-base/issues/29) due to this. While `brewlog` can’t prevent something like this from happening, but it logs `brew` activity so it is much easier to troubleshoot (by identifying what package(s) were added/removed). + + ### What can `brewlog` do ? `brewlog` is simple solution that can: -+ log homebrew/linuxbrew activity (`STDOUT` and `STDERR`) - + as it is a new command, the user still retains the freedom to run `brew [command] [formula]` and not log it to the file -+ tail the log file to display selected number of lines. -+ archive the log file (when user invokes the appropriate command). - + a new log file is created the next time `brewlog` is invoked after archiving. ++ `log` homebrew/linuxbrew activity (`STDOUT` and `STDERR`) to a logfile (default: `~/Logs/brew.log`) + + because brewlog is a a new command (and not an alias), the user still retains the freedom to run `brew [command] [formula]` in case they do not want to log some brew activity. ++ `tail` the `brew.log` file to display selected number of lines. ++ `archive` the brew.log file (user has to explicitly invoke this command to archive). + + The `brew.log` is removed during archiving, a new log file is created on the next run of `brewlog`. -Now you'll be easily able to track the changes made by `brew upgrade`or `brew cleanup`. +Now you're easily able to track the changes made to your system while running `brew upgrade`or `brew cleanup`. ### How to use ```sh +# Review/Modify code +curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/install.sh' +# Install curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/install.sh' | bash # Show help @@ -39,6 +50,8 @@ brewlog info ffmpeg brewlog list --multiple --versions ``` + + ### Detailed usage ``` @@ -69,10 +82,11 @@ Homebrew/Linuxbrew Function examples: -**Note:** +### Notice about the command `brew log`: + Not to be confused with `brew log` which shows the commit history (similar to `git log`). + I'm open to a new name, but for now as I personally don’t use `brew log`, I had no “merge conflicts” in my brain while assigning `brewlog` to achive my desired result of logging brew output :) [*IMHO* `brew history` *might have been a better name for* `brew log`] +© Deepankar Chakroborty, 2020. All rights reserved. \ No newline at end of file From 2da137b2263cf113c4116b6bddb299e086162aba Mon Sep 17 00:00:00 2001 From: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Tue, 4 Aug 2020 16:13:56 +0300 Subject: [PATCH 6/6] improve installation and usage instructions --- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6cf534b..8abf6d8 100644 --- a/README.md +++ b/README.md @@ -33,26 +33,62 @@ Now you're easily able to track the changes made to your system while running `b ### How to use +#### a) Install from binary + +1. Download the latest binary from the releases (should run on *nix with a homebrew installation). +2. `mv brewlog /usr/local/bin/brewlog` or to some other place that is in your `$PATH`. +3. Familiarize yourself by running `brewlog —help`. + +#### b) Install from source + +The script [`install.sh`](https://github.com/robocopAlpha/brewlog/blob/master/install.sh) automatically picks the place to install brewlog by detecting the location where the `brew` binary is placed in your system `$PATH`. + ```sh -# Review/Modify code -curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/install.sh' # Install curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/install.sh' | bash - # Show help brewlog --help +``` -# Running homebrew commands -brewlog install ffmpeg -brewlog info ffmpeg +#### c) Install from source with modifications -# Even complex brew commands work with brewlog -brewlog list --multiple --versions +```sh +# download +curl -OJL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/install.sh' +# Review/Modify code +bat install.sh +nano install.sh +# Install +sh install.sh | bash +# Show help +brewlog --help ``` -### Detailed usage +#### Examples using brewlog + +```sh +# Running homebrew commands +brewlog install ffmpeg +brewlog info ffmpeg +brewlog outdated + +# Tail the log file +brewlog tail +brewlog tail -n 5 + +# archive the current log file +brewlog archive + +# Even complex brew commands work with brewlog +brewlog list --multiple --versions +brew deps ffmpeg | xargs brewlog uninstall ----ignore-dependencies +``` + + + +### `brewlog —help` listing parameters and examples: ``` brewlog - allows you to log your homebrew/linuxbrew operations to a file.