Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Switch to use the Boxes Metadata API for Chef. #52

Merged
merged 1 commit into from
Apr 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions scripts/chef.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
#!/bin/bash

# Get the Chef package version through their metadata service.
# Fetches the Chef package version and sha from the Boxes API, then installs
# the package.

set -e

boxes_api="https://boxes.io/api/v1"
platform=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
release=$(lsb_release -sr)
version_url="https://www.opscode.com/chef/metadata?v=&prerelease=false&nightlies=false&p=$platform&pv=$release&m=x86_64"
current_version=$(curl -s "$version_url")

version_url=$(echo "$current_version" | awk '/url/{print $2}')
version_sha=$(echo "$current_version" | awk '/sha256/{print $2}')
if [ "$platform" == "debian" ]; then
release=$(echo "$release" | cut -d. -f1)
fi

version_url="$boxes_api/metadata/chef?platform=$platform&platform_version=$release"

echo "Determining current Chef package version..."
if ! current_version=$(curl --silent --fail "${version_url}"); then
>&2 echo "Unable to fetch version information for $platform, $release"
exit 1
fi

version_url=$(echo "$current_version" | python -c \
"import json,sys;obj=json.load(sys.stdin);print obj['url'];")
version_sha=$(echo "$current_version" | python -c \
"import json,sys;obj=json.load(sys.stdin);print obj['sha256'];")

# fetch chef
curl --insecure --location $version_url -o chef.deb
echo "Fetching Chef package..."
curl --silent --fail "$version_url" -o chef.deb

# check the file
echo "$version_sha chef.deb" > '/tmp/chef-checksum'
shasum -a 256 -c '/tmp/chef-checksum'
if [ $? -ne 0 ]; then
echo "Downloaded Chef package failed to checksum."
exit 1
echo "Verifying downloaded Chef package..."
downloaded_sha=$(openssl sha256 -r chef.deb)
if [ "$version_sha *chef.deb" != "$downloaded_sha" ]; then
>&2 echo "Unable to verify downloaded chef.deb"
echo 2
fi

# install
dpkg -i chef.deb
echo "Installing Chef package..."
dpkg --install chef.deb

# cleanup
echo "Tidying up artifacts..."
rm chef.deb
rm /tmp/chef-checksum