mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-27 09:12:44 +00:00
MFC r320599:
Fix Vagrant image upload after recent API changes. - Update ATLAS_UPLOAD_URL to avoid various regular expressions from failing to match due to redirections. - Use ATLAS_UPLOAD_URL throughout the script. - Adjust several regular expression patterns. Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
2e518d178d
commit
3516147666
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/stable/10/; revision=320697
@ -27,7 +27,7 @@
|
||||
#
|
||||
|
||||
ATLAS_API_URL=''
|
||||
ATLAS_UPLOAD_URL='https://binstore.hashicorp.com'
|
||||
ATLAS_UPLOAD_URL='https://app.vagrantup.com'
|
||||
DESCRIPTION="FreeBSD Snapshot Build"
|
||||
|
||||
usage() {
|
||||
@ -76,7 +76,7 @@ main () {
|
||||
fi
|
||||
|
||||
# Check to see if the box exists or create it
|
||||
BOXRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}?access_token=${KEY}")
|
||||
BOXRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}?access_token=${KEY}")
|
||||
if [ $? != 0 ]; then
|
||||
echo "Failed to connect to the API"
|
||||
exit 2;
|
||||
@ -84,26 +84,26 @@ main () {
|
||||
echo $BOXRESULT | grep "\"name\":\"${BOX}\"" > /dev/null
|
||||
if [ $? != 0 ]; then
|
||||
echo "Creating box: ${BOX}"
|
||||
/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/boxes -X POST -d "box[name]=${BOX}" -d "access_token=${KEY}" > /dev/null
|
||||
/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[is_private]=false" -d "access_token=${KEY}" > /dev/null
|
||||
/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[description]='${DESCRIPTION}'" -d "access_token=${KEY}" > /dev/null
|
||||
/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/boxes -X POST -d "box[name]=${BOX}" -d "access_token=${KEY}" > /dev/null
|
||||
/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[is_private]=false" -d "access_token=${KEY}" > /dev/null
|
||||
/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[description]='${DESCRIPTION}'" -d "access_token=${KEY}" > /dev/null
|
||||
else
|
||||
echo "Box already exists"
|
||||
fi
|
||||
|
||||
# Check to see if the version exists or create it
|
||||
VERSIONRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}")
|
||||
VERSIONRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}")
|
||||
if [ $? != 0 ]; then
|
||||
echo "Failed to connect to the API"
|
||||
exit 2;
|
||||
fi
|
||||
echo $VERSIONRESULT | grep "\"version\":\"${VERSION}\"" > /dev/null
|
||||
echo $VERSIONRESULT | grep "version/${VERSION}" > /dev/null
|
||||
if [ $? != 0 ]; then
|
||||
echo "Creating version: ${VERSION}"
|
||||
/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/versions -X POST -d "version[version]=${VERSION}" -d "access_token=${KEY}" > /dev/null
|
||||
/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION} -X PUT -d "version[description]=${DESCRIPTION}" -d "access_token=${KEY}" > /dev/null
|
||||
VERSIONRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}")
|
||||
echo $VERSIONRESULT | grep "\"version\":\"${VERSION}\"" > /dev/null
|
||||
/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/versions -X POST -d "version[version]=${VERSION}" -d "access_token=${KEY}" > /dev/null
|
||||
/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION} -X PUT -d "version[description]=${DESCRIPTION}" -d "access_token=${KEY}" > /dev/null
|
||||
VERSIONRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}")
|
||||
echo $VERSIONRESULT | grep "version/${VERSION}" > /dev/null
|
||||
if [ $? != 0 ]; then
|
||||
echo "Failed to create version"
|
||||
exit 2
|
||||
@ -113,37 +113,37 @@ main () {
|
||||
fi
|
||||
|
||||
# Check to see if the provider exists or create it
|
||||
PROVIDERRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}")
|
||||
PROVIDERRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}")
|
||||
if [ $? != 0 ]; then
|
||||
echo "Failed to connect to the API"
|
||||
exit 2;
|
||||
fi
|
||||
echo $PROVIDERRESULT | grep "\"name\":\"${PROVIDER}\"" > /dev/null
|
||||
echo $PROVIDERRESULT | grep "provider/${PROVIDER}" > /dev/null
|
||||
if [ $? != 0 ]; then
|
||||
echo "Creating provider: ${PROVIDER}"
|
||||
/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/providers -X POST -d "provider[name]=${PROVIDER}" -d "access_token=${KEY}" > /dev/null
|
||||
/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/providers -X POST -d "provider[name]=${PROVIDER}" -d "access_token=${KEY}" > /dev/null
|
||||
else
|
||||
echo "Provider already exists"
|
||||
fi
|
||||
|
||||
# Request an upload token
|
||||
TOKENRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}/upload?access_token=${KEY}")
|
||||
TOKENRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}/upload?access_token=${KEY}")
|
||||
if [ $? != 0 ]; then
|
||||
echo "Failed to get the token from the API"
|
||||
exit 2;
|
||||
fi
|
||||
echo ${TOKENRESULT} | grep -E "\"(token|upload_path)\":" > /dev/null
|
||||
echo ${TOKENRESULT} | grep -E "upload_path" > /dev/null
|
||||
if [ $? != 0 ]; then
|
||||
echo "No token found from the API"
|
||||
exit 2
|
||||
else
|
||||
TOKEN=$(echo $TOKENRESULT | sed -e 's/.*token":"//' -e 's/.*upload_path":"//' -e 's/}$//g' -e 's/"//g')
|
||||
echo "Uploading to Atlas"
|
||||
UPLOADRESULT=$(/usr/local/bin/curl -s -X PUT --upload-file ${FILE} ${TOKEN})
|
||||
UPLOADRESULT=$(/usr/local/bin/curl -s -X PUT --upload-file ${FILE} "${TOKEN}")
|
||||
|
||||
# Validate the Upload
|
||||
echo "Validating"
|
||||
VALIDRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}")
|
||||
VALIDRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}")
|
||||
HOSTED_TOKEN=$(echo $VALIDRESULT | sed -e 's/.*"hosted"://' -e 's/,.*$//')
|
||||
if [ ! -z ${TOKEN} -a "${HOSTED_TOKEN}" != "true" ]; then
|
||||
echo "Upload failed, try again."
|
||||
@ -152,7 +152,7 @@ main () {
|
||||
|
||||
# Release the version
|
||||
echo "Releasing ${VERSION} of ${BOX} in Atlas"
|
||||
/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/release -X PUT -d "access_token=${KEY}" > /dev/null
|
||||
/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/release -X PUT -d "access_token=${KEY}" > /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user