-
Notifications
You must be signed in to change notification settings - Fork 1
/
download_gpdb.sh
executable file
·181 lines (138 loc) · 5.57 KB
/
download_gpdb.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
.#!/bin/bash
set -e
set -u
set -x
export DOWNLOAD_FOLDER_PREFIX="DOWNLOAD_"
###############################################################################################
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
###############################################################################################
downloadGPDBSelected(){
pivnet accept-eula -r $PRODUCT_RELEASE -p pivotal-gpdb
files='files.txt'
productfiles="pivnet_productfiles.txt"
if [ -f $files ]; then
# Control will enter here if $PRODUCT_RELEASE directory exists.
rm -f $files
touch -a $files
fi
if [ -f $productfiles ]; then
# Control will enter here if $PRODUCT_RELEASE directory exists.
rm -f $productfiles
touch -a $productfiles
fi
pivnet file-groups -p pivotal-gpdb --format=json -r $PRODUCT_RELEASE | jq . >> $productfiles
# Add selected files by defining the filter names
jq -rc ' .[] | select(.name=="Greenplum Spark Connector") | .product_files[] | {key: .aws_object_key , href: ._links.download.href } ' $productfiles >> $files
jq -rc ' .[] | select(.name=="Greenplum Database Server") | .product_files[] | {key: .aws_object_key , href: ._links.download.href } ' $productfiles >> $files
# Download files
pushd `pwd`
cd $DOWNLOAD_FOLDER_PREFIX$PRODUCT_RELEASE
jq -s '.[] | .key + "," + .href' ../$files |
while read -r line; do
line=$(echo "$line" | sed s'/.$//')
NAME=$(echo "$line" | cut -d',' -f1)
HREF=$(echo "$line" | cut -d',' -f2)
FILEPATH=$(echo $NAME | sed -ne "s/^\"product_files\///p" | sed -ne "s/^Pivotal-Greenplum\///p")
wget --post-data="" --header="Authorization: Token $API_TOKEN" "$HREF" -O "$FILEPATH" --show-progress
done
# go back to the original directory
popd
}
###############################################################################################
downloadAllGPDB(){
files='files.out'
productfiles="pivnet_productfiles.out"
if [ -f $files ]; then
# Control will enter here if $PRODUCT_RELEASE directory exists.
rm -f $files
touch -a $files
fi
if [ -f $productfiles ]; then
# Control will enter here if $PRODUCT_RELEASE directory exists.
rm -f $productfiles
touch -a $productfiles
fi
pivnet file-groups -p pivotal-gpdb --format=json -r $PRODUCT_RELEASE accept-eula | jq . >> $productfiles
jq -rc '.[] | .product_files[] | {key: .aws_object_key , href: ._links.download.href } ' $productfiles >> $files
# Download files
pushd `pwd`
cd $DOWNLOAD_FOLDER_PREFIX$PRODUCT_RELEASE
jq -s '.[] | .key + "," + .href' ../$files |
while read -r line; do
line=$(echo "$line" | sed s'/.$//')
NAME=$(echo "$line" | cut -d',' -f1)
HREF=$(echo "$line" | cut -d',' -f2)
FILEPATH=$(echo $NAME | sed -ne "s/^\"product_files\///p" | sed -ne "s/^Pivotal-Greenplum\///p")
ACCEPTANCEPATH=$(echo $HREF | sed -e "s/product_files.*/eula_acceptance/g")
# Create acceptance request - https://network.pivotal.io/docs/file_download_api#public/docs/api/v2/release_eula_acceptance.md
wget --post-data="" --header="Authorization: Token $API_TOKEN" "$ACCEPTANCEPATH" --show-progress
# Download file
wget --post-data="" --header="Authorization: Token $API_TOKEN" "$HREF" -O "$FILEPATH" --show-progress
done
# go back to the original directory
popd
}
###############################################################################################
# Use this parameter to download a particular release.
#PRODUCT_RELEASE="4.3.25.0"
# Change the variable below to download a particular version
PRODUCT_RELEASE="5.13.0"
DEBUG=false
if [ $# -eq 0 ]
then
echo "No arguments supplied"
echo "$0 %pivnet-api-token% %product-release"
# Default configuration file if it exists
if [ -f ~/.pivnetrc ]; then
echo "The ~/.pivnetrc file exists"
# Ex
# profiles:
#- name: default
# api_token: sdfafsdw343242
# host: https://network.pivotal.io
# read yaml file
eval $(parse_yaml ~/.pivnetrc "config_")
# access yaml content
echo $config_profiles_api_token
export API_TOKEN=$config_profiles_api_token
fi
elif [ $# -eq 1 ]
then
export API_TOKEN=$1
else
export API_TOKEN=$1
export PRODUCT_RELEASE=$2
fi
: ${PRODUCT_RELEASE?"Need to set PRODUCT_RELEASE"}
: ${API_TOKEN?"Need to set API_TOKEN"}
pivnet login --api-token=$API_TOKEN
if [ -d "$DOWNLOAD_FOLDER_PREFIX$PRODUCT_RELEASE" ]; then
# Control will enter here if $PRODUCT_RELEASE directory exists.
echo "$DOWNLOAD_FOLDER_PREFIX$PRODUCT_RELEASE directory exists"
else
echo "Create download directory: $DOWNLOAD_FOLDER_PREFIX$PRODUCT_RELEASE"
mkdir $DOWNLOAD_FOLDER_PREFIX$PRODUCT_RELEASE
fi
# List of product files
#pivnet product-files -p pivotal-gpdb -r 5.0.0 --format json | python -m json.tool
#pivnet product-files -p pivotal-gpdb -r 5.0.0 --format json | jq '.'
#pivnet r -p pivotal-gpdb -r 5.0.0 --format json | jq '{"id": .id, "release_date": .release_date, "release_type": .release_type}'
#pivnet file-groups -p pivotal-gpdb -r "5.0.0" --format json | python -m json.tool
#downloadGPDBSelected
downloadAllGPDB
rm -f *.out
###############################################################################################