From 00b50313ac52080c681bcb1baf4fdf1c82efdb55 Mon Sep 17 00:00:00 2001 From: robocopAlpha <35454738+robocopAlpha@users.noreply.github.com> Date: Wed, 5 Aug 2020 17:54:39 +0300 Subject: [PATCH] Updates use gzip as fallback if xz is not installed on system Add Paypal donation link --- README.md | 4 +++- brewlog.sh | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dc045f7..dda80f9 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ e.g. OPTIONS: version Show brewlog version - archive Archives the current log file as .xz + archive Archives the current log file as .xz (gzip as fallback if xz not found) tail [-n INT] Show the last "INT" lines from the log file. (default: last 15 lines) @@ -116,7 +116,9 @@ Homebrew/Linuxbrew Function examples: Find out more homebrew commands by running "brew --help". ``` +If you found `brewlog` consider starring this repo. +[![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://paypal.me/robocopAlpha) ### Notice about the command `brew log`: diff --git a/brewlog.sh b/brewlog.sh index b4b9029..33c7627 100644 --- a/brewlog.sh +++ b/brewlog.sh @@ -26,7 +26,7 @@ OPTIONS: --help Show help --brew-help Show brew commands (alias to "brew help") version Show brewlog version info - archive Archives the current log file as .xz + archive Archives the current log file as .xz (gzip as fallback if xz not found) tail [-n INT] Show the last "INT" lines from the log file. (default: last 15 lines) @@ -86,9 +86,17 @@ elif [ "$1" == "tail" ]; then elif [ "$1" == "archive" ]; then if [ -f "$LOGFILE" ] ; then # Archiving logfile i.e. brew.log is removed (will be created on next run) - xz -vf $LOGFILE - mv "${LOGFILE}.xz" "$LOGFILE-$(date +'%Y%m%d').xz" - exit 0; + command -v xz > /dev/null + if [ "$?" -eq "0" ]; then + xz -6vf $LOGFILE + mv "${LOGFILE}.xz" "$LOGFILE-$(date +'%Y%m%d').xz" + exit 0; + else + # if xz is unavailable use gz + gzip -6fv $LOGFILE + mv "${LOGFILE}.gz" "$LOGFILE-$(date +'%Y%m%d').gz" + exit 0; + fi else echo "$LOGFILE doesn't exist" exit 1