habitat icon indicating copy to clipboard operation
habitat copied to clipboard

Add hab license check command

Open themightychris opened this issue 4 years ago • 5 comments

I want to eat the output of a few Habitat commands in an automation process, relying on the user to have already accepted the license through any means hab supports. Since they won’t see the output of my hab calls, I’d like to check license status first and print useful info on how to accept in the current context.

How about a check subcommand under the existing hab license command that returns an exit status of 0 or 1 that could be used like this:

if hab license check; then
  echo "Everything look good! Doing some hab stuff quietly..."
  hab pkg install foo/bar >/dev/null 2>&1
else
  echo "You need to accept the Chef Habitat license, check out https://docs.chef.io/chef_license_accept.html#habitat"
fi

themightychris avatar Sep 24 '19 04:09 themightychris

There's still no good way to automate this. Any attempt to run a command in an environment that license acceptance isn't getting through to results in commands hung waiting for STDIN that you wouldn't expect to. We need a way for reusable automations to fail fast and clearly when getting license acceptance into their environment is broken.

Here's my best workaround so far:

if ! [ -x "$(command -v hab)" ]; then
    echo "Please install Chef Habitat: https://www.habitat.sh/docs/install-habitat/"
    exit 1
fi

set +e
hab_version="$(hab --version < /dev/null)"
if [ $? -ne 0 ]; then
    echo
    echo "   Failed to read hab version, you may need to accept the Chef Habitat"
    echo "   license. Please run \`hab setup\` or configure HAB_LICENSE in the environment"
    exit 1
fi
set -e

# ...check $hab_version

themightychris avatar Jun 30 '20 17:06 themightychris

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

stale[bot] avatar Jul 25 '21 23:07 stale[bot]

still need a reliable way to script this

themightychris avatar Jul 26 '21 12:07 themightychris

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

stale[bot] avatar Jul 31 '22 10:07 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

stale[bot] avatar Aug 12 '23 18:08 stale[bot]