diff --git a/brewlog.sh b/brewlog.sh index 49be191..fac60f5 100644 --- a/brewlog.sh +++ b/brewlog.sh @@ -59,29 +59,36 @@ if [ ! -f "$LOGFILE" ] ; then touch "$LOGFILE" fi -if [ $# -eq 0 ]; then +if [ "$#" -eq 0 ]; then HELP + exit 0; fi if [ "$1" == "--help" ]; then HELP + exit 0; elif [ "$1" == "--brew-help" ]; then brew help + exit 0; elif [ "$1" == "version" ]; then VERSION + exit 0; elif [ "$1" == "tail" ]; then if [ "$2" == "-n" ]; then # tail with specified number of lines tail -n "$3" "$LOGFILE" + exit 0; else # tail with 15 lines (default -n for tail is 10, I wanted more) tail -n 15 "$LOGFILE" + exit 0; fi 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; else echo "$LOGFILE doesn't exist" exit 1 @@ -90,4 +97,5 @@ else echo "brew $* :: $(date)" | tee -a "$LOGFILE" # logs both STDOUT and STDERR to $LOGFILE $(which brew) "$@" 2>&1 | tee -a "$LOGFILE" + exit 0; fi \ No newline at end of file diff --git a/install.sh b/install.sh index 1ff6a92..1ad0f17 100644 --- a/install.sh +++ b/install.sh @@ -1,17 +1,26 @@ #!/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 else - sudo -s - 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 - exit - sudo -k - else - echo "cannot write to /usr/local/bin". - exit 1; - fi -fi + 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 + if [[ "$choice" =~ ^(yes|y)$ ]] + then + sudo mv brewlog.sh /usr/local/bin/brewlog + sudo chmod +x /usr/local/bin/brewlog + sudo -k + else + echo "cannot install /usr/local/bin/brewlog without sudo rights" + exit 1; + fi + if [ "$flag" -eq "1" ]; then + shopt -s nocasematch + fi +fi \ No newline at end of file