How do I "replay" the "Caveats" section from a homebrew recipe - macos

When installing a homebrew recipe, you occasionally will get some useful information in the "Caveats" section that you may want to tuck under your hat. Is there any way to replay or access this information once it has been displayed at install or is it lost forever unless you copy paste somewhere?
e.g.
==> Caveats
To have launchd start mongodb at login:
ln -s /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents/
Then to load mongodb now:
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
mongod
I might want to be able to see this again and/or know where that plist is if I want it later.
tl;dr How do I see the above snippet again after I've installed something from homebrew?

brew info mongodb will display it. If you make the changes suggested by the Caveats however, there may be other Caveats presented which will be more applicable to your actual situation.

I created a brew external command for that: https://github.com/rafaelgarrido/homebrew-caveats
$ brew caveats zsh
==> zsh: Caveats
Add the following to your zshrc to access the online help:
unalias run-help
autoload run-help
HELPDIR=/usr/local/share/zsh/helpfiles
You can also pass multiple formulas:
$ brew caveats rabbitmq mongodb
==> rabbitmq: Caveats
Management Plugin enabled by default at http://localhost:15672
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
To have launchd start rabbitmq at login:
ln -sfv /usr/local/opt/rabbitmq/*.plist ~/Library/LaunchAgents
Then to load rabbitmq now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist
Or, if you don't want/need launchctl, you can just run:
rabbitmq-server
==> mongodb: Caveats
To have launchd start mongodb at login:
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then to load mongodb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
mongod --config /usr/local/etc/mongod.conf
Pretty handy when you need to check some configs!

To see all caveats of the currently installed formulas you can use the following command
brew info $(brew list)
You can also filter the output with awk to only get the caveats sections. (I am an awk newbie suggestions or edits are welcome)
brew info $(brew list) | awk '/^==> Caveats$/,/^[a-z][a-zA-Z0-9_+-]+: stable |^==> (Dependencies|Options)$/'

Another possibility is to use sed
brew info $(brew list) | sed '/==> Caveats/,/==>/!d;//d'
And to have a formatted output (bash)
for cmd in $(brew list); do
if brew info $cmd | grep -q Caveats; then
echo "$cmd\n";
brew info $cmd | sed '/==> Caveats/,/==>/!d;//d';
printf '%40s\n' | tr ' ' -;
fi;
done;

For those of you who have the awesome jq tool:
# For brews
$ brew info --json $(brew list) | jq -r '.[] | select(.caveats != null) | "\n\nName: \(.name)\nCaveats: \(.caveats)"'
# For casks
$ brew cask --json=v1 info $(brew cask list) | jq -r '.[] | select(.caveats != null) | "\n\nName: \(.name)\nCaveats: \(.caveats)"'
jq is a command-line JSON processor.

Updating and combining a few above anwers, here's a bash/zsh loop that can be pasted into the terminal to get all caveats for all installed brew formulae.
for x in $(brew list --formula); do
cavs=$(brew info "$x" | sed '/==> Caveats/,/==>/!d;//d')
if [ ! -z "$cavs" ]; then
echo "$x"
echo "---"
echo "$cavs"
echo ""
fi
done

Related

Installing RVM and gems on OSX from a single shell script

I am attempting to install RVM and a few gems from a single bash script that I use to bootstrap a new development box. My goal is to have a single script I can run on a clean install of OSX to install any and everything I use for development.
After installing RVM, I am sourcing the $HOME/.rvm/scripts/rvm script, however in the next line, when I attempt to install a specific version of ruby, it says rvm is not found. Here is my script.
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable --autolibs=homebrew
source "$HOME/.rvm/scripts/rvm"
rvm install 2.1.1
rvm use 2.1.1
gem install jekyll
gem install tmuxinator
gem install scss-lint
I can't understand why this isn't working, because if I run each command individually in the terminal, everything works great.
Any ideas on a 1 script solution to install RVM, a specific version of Ruby, and a few gems?
If you look in .bashrc after RVM they have:
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
What I would do overall for cleanliness
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable --autolibs=homebrew
if [[ -s "$HOME/.rvm/scripts/rvm" ]]; then
. "$HOME/.rvm/scripts/rvm"
else
echo "$HOME/.rvm/scripts/rvm" could not be found.
exit 1
fi
export PATH="$PATH:$HOME/.rvm/bin"
rvm use 2.1.1 --default --install
for i in jekyll tmuxinator scss-lint; do gem install $i; done
You may need to add "source ~/.rvm/scripts/rvm" to your ~/.bash_profile file.
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bashrc
To install rvm:
rm -rf ~/.rvm
curl -L https://get.rvm.io | bash -s stable
In your script type:
type_rvm=$(type rvm | head -n 1)
echo "type rmv: $type_rvm"
You could try export rvm:
export PATH=$PATH:/opt/rvm/bin:/opt/rvm/sbin
I found a solution after reading through another stack overflow post.
A comment to one of the answers suggested makeing sure the script runs with bash and not sh. That was my problem. After changing the top line of my script (which wasn't included in my example) from #!/bin/sh to #!/usr/bin/env bash, everything worked as expected.

Find the install location of brew on OS X

I'm creating a BASH scrip which requires a couple of applications to be installed. ffmpeg and sox
To ensure they are in place when my script runs I first check for the installation of Homebrew with :
#!/bin/bash
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
fi
Then I check that sox and ffmpeg are installed with :
echo "---- checking for sox ----"
which -s sox || /usr/local/bin/brew install sox
echo "---- checking for ffmpeg ----"
which -s ffmpeg || /usr/local/bin/brew install ffmpeg
The problem I am facing is when Homebrew is installed but in a non-standard location.
I have to use the full path to Homebrew because this script is being run within Playtypus.
So the question is : How can I reliably get the installed path of Homebrew in a BASH script?
Answering my own question...
You can test the output of which brew and deal with things accordingly. To gracefully deal with the case where Homebrew is not installed you can use if which brew 2> /dev/null which redirects stderr to /dev/null.
brew --prefix is also useful here as it give the path to where Homebrew installed applications are symlinked to, rather than their actual install path.
A script which works and shows this working :
#!/bin/bash
if which brew 2> /dev/null; then
brewLocation=`which brew`
appLocation=`brew --prefix`
echo "Homebrew is installed in $brewLocation"
echo "Homebrew apps are run from $appLocation"
else
echo "Can't find Homebrew"
echo "To install it open a Terminal window and type :"
echo /usr/bin/ruby -e \"\$\(curl\ \-fsSL\ https\:\/\/raw\.github\.com\/Homebrew\/homebrew\/go\/install\)\"
fi
Thanks to Allendar for the pointers.
Just to add to this, Homebrew's --prefix mode has been enhanced here in the far-flung future of 2020 (or maybe it was always this way), so that it now takes a package name as an argument. Meaning locating those "keg-only" packages which aren't linked into standard paths is as easy as:
$ brew --prefix ffmpeg
/usr/local/opt/ffmpeg

In login shell but rvm is not a function

$ shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
Login shell
$ type rvm | head -n 1
rvm is a function
-bash: type: write error: Broken pipe
However:
$ rvm --default use 1.9.2
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.
I removed ~/.rvm/ and tried installing again using curl -L https://get.rvm.io | bash -s stable --auto but that doesn't help.
It's a remote Ubuntu 13.04, that I have ssh'd into, authenticating with keys. Any advice?
I was sourcing the ~/.rvm/bin/rvm script twice. In the process of uninstalling and reinstalling, it once happened to not modify ~/.bash_profile. I then did this manually. A second uninstall/re-install dance then produced a ~/.bash_profile of:
source ~/.bashrc
# (lines added by me)
if [ -f /ubuntu/.rvm/bin/rvm ]; then
source '/ubuntu/.rvm/bin/rvm' > /dev/null
fi
# (lines added by RVM installer using: curl -L https://get.rvm.io | bash -s stable --auto-dotfiles)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

rvm: command not found MAC OX

Really, I don't know what happened. Excuse me if this question is so NOOB, but I can't find the solution for this problem.
-bash: rvm: command not found
I tried this
curl -L https://get.rvm.io | bash -s -- --version latest
but still nothing I need to see the ruby version for use the simplecov because it not works with older version from 1.9
It might because the terminal not having rvm shell configuration loaded.
Try following from your terminal:
$ source ~/.rvm/scripts/rvm
then
$ type rvm | head -n 1
If the output is:
rvm is a function
You may need to add "source ~/.rvm/scripts/rvm" to your ~/.bash_profile file
you need to read all the texts that are displayed when you install RVM:
rm -rf ~/.rvm
curl -L https://get.rvm.io | bash -s stable
after you run sudo curl -L https://get.rvm.io | bash -s stable --ruby
you need to close the terminal ,then open again!
This worked for me:
rm -rf ~/.rvm
curl -L https://get.rvm.io | bash -s stable
source /etc/profile worked for me.
For a long-term solution, you should add this to your ~/.profile file:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
to simply load rvm into a single terminal, use
source "$HOME/.rvm/scripts/rvm"
supposedly this call is more cross-platform:
. "$HOME/.rvm/scripts/rvm"
As suggested by #mpapis, Do this first
$ rm -rf ~/.rvm
$ curl -L https://get.rvm.io | bash -s stable
Then, as suggested by #peterpengnz, do this and you should be fine with RVM cmd issues
$ source ~/.rvm/scripts/rvm
Close and restart terminal after installing RVM — gets me EVERY TIME.
To start using RVM, you'll need to enter source /Users/yourusername/.rvm/scripts/rvm into your terminal (of course, insert your real username in place of yourusername).
Close and reopen your terminal. Sometimes, the changes made during the installation of rvm are not immediately picked up by your terminal, so reopening it should resolve the problem.

RVM installation fails

I followed the instructions from the RVM homepage (https://rvm.beginrescueend.com/rvm/install/)
I typed the following:
sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
the script executed and didn't seem to give any errors.
the same without sudo gave an error:
Warning: Failed to create the file
Warning: /usr/share/ruby-rvm/archives/wayneeseguin-rvm-stable.tgz: Permission
Warning: denied
0 792k 0 3908 0 0 2257 0 0:05:59 0:00:01 0:05:58 2257
curl: (23) Failed writing body (0 != 3908)
Could not download 'https://github.com/wayneeseguin/rvm/tarball/stable'.
curl returned status '23'.
I also put this in my ~/.bashrc
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
what I get is:
~$ type rvm | head -1
bash: type: rvm: not found
~$ source "/usr/local/rvm/scripts/rvm"
bash: /usr/local/rvm/scripts/rvm: No such file or directory
~$ source "$HOME/.rvm/scripts/rvm"
bash: /home/anonym/.rvm/scripts/rvm: No such file or directory
How can this be fixed?
PS
I'm using Ubuntu 11.10
Sudo problems. This worked for me to install rvm. Just do:
curl -L https://get.rvm.io | sudo bash -s stable --ruby
nano ~/.bashrc
at the bottom of the file add these line
unset rvm_path
unset GEM_HOME
Then run
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.1.3
rvm use 2.1.3 --default
ruby -v
Can you try this:
$ curl -s raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable
or
$ curl -s raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | sudo bash -s stable
depending on your permissions. That should help. It helped me! :)
I'm sure there's a more elegant way to fix this, but I ran into the same issue and was kinda in a hurry, so I went for a quick and dirty workaround:
$ curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer > foo.sh
$ chmod 755 foo.sh
Then edit line 162, and add -k to the curl command:
$ vim foo.sh
162 if curl -Lk https://github.com/${_repo}/rvm/tarball/${_branch} -o ${rvm_archives_path}/${_repo}-rvm-${_branch}.tgz
Then run the script:
$ ./foo.sh --branch stable
Like I said, not ideal, but it got me where I needed to be quickly.
If anyone has this problem in the future in ubuntu I was getting this error because of an old package that still had config stuff hanging around.
Try running
sudo apt-get --purge remove ruby-rvm
That should take care of the permission error and let you install RVM as a normal user under $HOME/.rvm
Put this in your .bashrc instead (without echo)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
And restart your terminal.
You might have RVM installed under the wrong user. RVM won't let you install if it's installed under another user.
You can uninstall it from the other user with rvm implode.
Log over to the other user and RVM will install correctly!
https://rvm.io/rvm/security#ipv6-issues
You can forbid gpg's internal dirmngr from using IPv6 by add the following line to ~/.gnupg/dirmngr.conf:

Resources