forked from craigwatson/puppet-vmwaretools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload.sh.erb
49 lines (39 loc) · 1.46 KB
/
download.sh.erb
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
#! /bin/bash
# Published under the Apache License v2.0
# Copyright (c) Craig Watson
function check_exec {
if [ ! -x $1 ]; then
echo "$1 not found"
exit 1
fi
}
function clean_download {
if [ ${CLEAN_FAILED_DOWNLOAD} -eq 1 ]; then
if [ -f "${DOWNLOAD_LOCATION}" ]; then
echo "Removing downloaded archive." >&2
rm "${DOWNLOAD_LOCATION}"
fi
fi
}
DOWNLOAD_URL="<%= scope['::vmwaretools::archive_url'] %>/VMwareTools-<%= scope['::vmwaretools::version'] %>.tar.gz"
DOWNLOAD_LOCATION="<%= scope['::vmwaretools::working_dir'] %>/VMwareTools-<%= scope['::vmwaretools::version'] %>.tar.gz"
GOOD_CHECKSUM="<%= scope['::vmwaretools::archive_md5'] %>"
CLEAN_FAILED_DOWNLOAD=<%= scope['::vmwaretools::params::clean_failed'] %>
check_exec "/usr/bin/curl"
check_exec "/usr/bin/md5sum"
check_exec "<%= scope['::vmwaretools::params::awk_path'] %>"
/usr/bin/curl -s "${DOWNLOAD_URL}" -o "${DOWNLOAD_LOCATION}"<% if scope['::vmwaretools::curl_proxy'] -%> -x <%= scope['::vmwaretools::curl_proxy'] %><% end %>
if [ $? -gt 0 ]; then
echo "Download failed from url ${DOWNLOAD_URL}" >&2
clean_download
exit 1
fi
chmod 600 ${DOWNLOAD_LOCATION}
DOWNLOADED_CHECKSUM=$(/usr/bin/md5sum "${DOWNLOAD_LOCATION}" | <%= scope['::vmwaretools::params::awk_path'] %> '{ print $1 }')
if [ "${DOWNLOADED_CHECKSUM}" != "${GOOD_CHECKSUM}" ]; then
echo "Checksum mismatch. Got ${DOWNLOADED_CHECKSUM}, should have been ${GOOD_CHECKSUM}." >&2
clean_download
exit 1
else
exit 0
fi