-
Notifications
You must be signed in to change notification settings - Fork 28
/
upload_boxes.sh
executable file
·146 lines (130 loc) · 5.68 KB
/
upload_boxes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#! /usr/bin/env bash
# Manages Vagrant Cloud boxes/versions/providers
# set -e
# set -x
# BOX_INFO="box_info.json"
# PRIVATE_VARS="../../../private_vars.json"
# VAGRANT_CLOUD_TOKEN=$(jq -r .vagrant_cloud_token $PRIVATE_VARS)
# BOX_TAG=$(jq -r .box_tag $BOX_INFO)
# BOX_NAME=$(echo $BOX_TAG | awk -F/ '{ print $2 }')
# BOX_SHORT_DESCR=$(jq -r .short_description $BOX_INFO)
# USERNAME=$(echo $BOX_TAG | awk -F/ '{ print $1 }')
# for BOX in $(ls *.box)
# do
# BOX_FULL_NAME=$(echo $BOX | awk -F. '{ print $1 }')
# PROVIDER_NAME=$(echo $BOX_FULL_NAME | awk -F- '{ print $5 }')
# VERSION=$(echo $BOX_FULL_NAME | awk -F- '{ print $6 }')
# Moved to utils.py
# Check if box exists
# BOX_CHECK=$(curl -s \
# --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
# https://app.vagrantup.com/api/v1/box/$BOX_TAG)
# BOX_CHECK_ERRORS=$(echo $BOX_CHECK | jq .errors)
# if [[ $BOX_CHECK_ERRORS != null ]]; then
# # Create box if it does not exist
# echo -e "\n$BOX_TAG not found...Creating."
# CREATE_BOX=$(curl -s \
# --header "Content-Type: application/json" \
# --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
# https://app.vagrantup.com/api/v1/boxes \
# --data '
# {
# "box": {
# "username": "'"$USERNAME"'",
# "name": "'"$BOX_NAME"'",
# "is_private": false,
# "short_description": "'"$BOX_SHORT_DESCR"'",
# "description": "'"$BOX_SHORT_DESCR"'"
# }
# }
# ')
# else
# # Update box
# echo -e "box: $BOX_TAG already exists...Skipping creation."
# echo -e "box: $BOX_TAG updating box info."
# UPDATE_BOX=$(curl -s \
# --header "Content-Type: application/json" \
# --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
# https://app.vagrantup.com/api/v1/box/$BOX_TAG \
# --request PUT \
# --data '
# {
# "box": {
# "name": "'"$BOX_NAME"'",
# "short_description": "'"$BOX_SHORT_DESCR"'",
# "description": "'"$BOX_SHORT_DESCR"'",
# "is_private": false
# }
# }
# ')
# fi
# # Check if version already exists
# VERSION_CHECK=$(curl -s \
# --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
# https://app.vagrantup.com/api/v1/box/$BOX_TAG/version/$VERSION)
# VERSION_CHECK_ERRORS=$(echo $VERSION_CHECK | jq -r .errors)
# if [[ "${VERSION_CHECK_ERRORS[*]}" = *"Resource not found!"* ]]; then
# # Create a new version
# echo -e "\nCreating version $VERSION for $BOX_TAG"
# curl -s \
# --header "Content-Type: application/json" \
# --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
# https://app.vagrantup.com/api/v1/box/$BOX_TAG/versions \
# --data '
# {
# "version": {
# "version": "'"$VERSION"'"
# }
# }
# '
# else
# echo "box: $BOX_TAG version: $VERSION already exists...Skipping version."
# fi
# if [ ! -z "$VERSION_CHECK_ERRORS" ]; then
# # Check for existing providers for version
# PROVIDER_CHECK=$(curl -s \
# --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
# https://app.vagrantup.com/api/v1/box/$BOX_TAG/version/$VERSION)
# PROVIDERS=$(echo $PROVIDER_CHECK | jq .providers)
# PROVIDERS_FOUND=()
# for PROVIDER in "${PROVIDERS[@]}"
# do
# PROVIDER_INFO=$(echo $PROVIDER | jq .[])
# PROVIDER_INFO_NAME=$(echo $PROVIDER_INFO | jq -r .name)
# PROVIDERS_FOUND+=($PROVIDER_INFO_NAME)
# done
# if [[ "${PROVIDERS_FOUND[*]}" = *"$PROVIDER_NAME"* ]]; then
# echo -e "box: $BOX_TAG version: $VERSION provider: $PROVIDER_NAME already exists...Skipping provider."
# else
# # Create a new provider
# echo -e "\nCreating box: $BOX_TAG version: $VERSION provider: $PROVIDER_NAME"
# curl -s \
# --header "Content-Type: application/json" \
# --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
# https://app.vagrantup.com/api/v1/box/$BOX_TAG/version/$VERSION/providers \
# --data '
# {
# "provider": {
# "name": "'"$PROVIDER_NAME"'"
# }
# }
# '
# # Prepare the provider for upload/get an upload URL
# echo -e "\nPreparing upload for box: $BOX_TAG version: $VERSION provider: $PROVIDER_NAME"
# RESPONSE=$(curl -s \
# --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
# https://app.vagrantup.com/api/v1/box/$BOX_TAG/version/$VERSION/provider/$PROVIDER_NAME/upload)
# # Extract the upload URL from the response (requires the jq command)
# UPLOAD_PATH=$(echo $RESPONSE | jq -r .upload_path)
# # Perform the upload
# echo -e "\nUploading box: $BOX_TAG version: $VERSION provider: $PROVIDER_NAME"
# curl -s -X PUT --progress-bar --upload-file $BOX $UPLOAD_PATH | tee /dev/null
# # Release the version
# echo -e "\nReleasing box: $BOX_TAG version: $VERSION provider: $PROVIDER_NAME"
# curl -s \
# --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
# https://app.vagrantup.com/api/v1/box/$BOX_TAG/version/$VERSION/release \
# --request PUT
# fi
# fi
# done