habitat
habitat copied to clipboard
Add hab license check command
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
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
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.
still need a reliable way to script this
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.
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.