forked from MariusCC/chef-bcpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy_setup.sh
56 lines (48 loc) · 2.16 KB
/
proxy_setup.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
# proxy and utility functions
#
# Make sure this file defines CURL in any case
# Only define http_proxy if you will be using a proxy
#
#export PROXY="proxy.example.com:80"
export CURL='curl'
if [ -n "${PROXY-}" ]; then
echo "Using a proxy at $PROXY"
local_ips=$(ip addr list |grep 'inet '|sed -e 's/.* inet //' -e 's#/.*#,#')
export http_proxy=http://${PROXY}
export https_proxy=https://${PROXY}
export no_proxy="$(sed 's/ //g' <<< $local_ips)localhost,$(hostname),$(hostname -f),.$(domainname),10.0.100.,10.0.100.*"
export NO_PROXY="$(sed 's/ //g' <<< $local_ips)localhost,$(hostname),$(hostname -f),.$(domainname),10.0.100.,10.0.100.*"
# to ignore SSL errors
export GIT_SSL_NO_VERIFY=true
export CURL="curl -k -x http://${PROXY}"
fi
#################################################
# load_binary_server_info
# Arguments: $1 - Chef Environment
# Post-Condition: sets $binary_server_url
# $binary_server_host
# Raises: Error if Chef environment not passed in
function load_binary_server_info {
environment="${1:?"Need a Chef environment"}"
bootstrap_server_key='["override_attributes"]["bcpc"]["bootstrap"]["server"]'
binary_server_key='["override_attributes"]["bcpc"]["binary_server_url"]'
load_json_frag="import json; print json.load(file('environments/${environment}.json'))"
# return a full URL (e.g. http://127.0.0.1:8080)
export binary_server_url=$(python -c "${load_json_frag}$binary_server_key" 2>/dev/null || \
(echo -n "http://"; python -c "${load_json_frag}${bootstrap_server_key}+':80'"))
# return only a host (e.g. 127.0.0.1)
export binary_server_host=$(ruby -e "require 'uri'; print URI('$binary_server_url').host")
}
# the bootstrap node may have multiple IP's we
# load_chef_server_ip
# Arguments: None
# Pre-Condition: Chef has been run on bootstrap node
# Post-Conditions: sets $chef_server_ip
# Raises: Error if Knife fails to run
function load_chef_server_ip {
export chef_server_ip=$(knife node show $(knife node list | egrep "^[ ]*$(hostname)($|\..*)") -a 'bcpc.management.ip' | tail -1 | sed 's/.* //')
if [[ -z "$chef_server_ip" ]]; then
echo 'Failed to load $chef_server_ip!' > /dev/stderr
exit 1
fi
}