Tuesday, July 11, 2017

The ‘Yes’ command


Recently I was working on a personal project involving GitHub and Travis CI. This short post is about my experience of hacking some of the options with Travis CI. To start with, Travis CI is giving free access to all public repositories on GitHub to run continuous integration. I used this to setup CI build for my Mac Dev Setup project. Once again, the initial work of Travis build definition has been done by Jeff Geerling. I am extending his goodwork to incorporate my changes.

One of the best part of Travis CI is the option to chose as Mac OS to run the CI build. You can refer to link for more details. I started off with the xcode7.3 version of the image. This is the default image at the time of writing this blog. The build was working fine with this version of them image. So I thought of upgrading the next image version of OSX with label xcode8. This build was successful without any changes.

Problem with Homebrew uninstallation

I thought that it was quite easy to just change the image version and the builds would work without any problem. Unfortunately not. I skipped the xcodee8.1 & xcode8.2 versions and tried to jump to xcode8.3 directly. The build failed with timeout. Looking at the build log, I can find out that the build was waiting for the confirmation on removal of Homebrew package and was expecting an input to the prompt in the form of y/N. Look at line number 391 in the below screenshot.

So I thought of downgrading the image version to 8.2. It was still the same. Hmm. Something had changed between the 8 version and the others. So I reverted back to the least version after 8 which was 8.1. As part of the initial setup, I was uninstalling the Homebrew package and from 8.1 image version, the installer expects a confirmation. Not sure why it doesn’t do it in the earlier versions.

I was running a script by downloading it and running a Ruby command as
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall"

Ruby does not provide an option to pass default as ‘Y’ to any of the prompts. Atleast I did not find such option using my google search skills. I started looking for ways to silently invoke the command and pass ‘Y’ as the default answer to the prompt.

‘Yes' command to the rescue

There were multiple solutions available online. But I liked the one provided by a command strangly named as yes. It can provide input as y or n to any prompt. The pipelining of commands and utilities in Unix / Linux based system helped here to pipe the yes command with the ruby script which I was using. The final command looks like
yes | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall"

Note that default is Y for the yes command. If you wish to answer n, you can change the syntax to yes n :). It is quite ironic to use yes command and reply as no. But thats how the author of this command desired it. They could have create a complimentary no command which would respond with n. I even did a google search to check if there is such command. Unforunately it does not exist.

With the help of wonderful yes comand my build is running fine now. I don’t know if there is any better way of supplying an answer to the prompt on Travis CI. If you know lt me know via comments.

How Travis CI saved my time?

Background Some time back I created an Ansible playbook to install software and setup my Mac Book Pro . I put the code for this on GitHub . ...