This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
proxy_setup.sh
64 lines (56 loc) · 2.31 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
57
58
59
60
61
62
63
64
# 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 CURL='curl'
if [ -n "$http_proxy" ]; then
echo "Using a proxy at $http_proxy"
# Set https_proxy to http_proxy if not otherwise defined.
export https_proxy=${https_proxy:-$http_proxy}
if [ -z "$no_proxy" ]; then
export no_proxy="localhost"
else
export no_proxy="$no_proxy,localhost"
fi
if domainname | grep -q '(none)'; then
DOMAIN=""
else
DOMAIN="$(domainname),"
fi
local_ips=$(ip addr list |grep 'inet '|sed -e 's/.* inet //' -e 's#/.*#,#' | sed ':a;N;$!ba;s/\n//g')
export no_proxy="$(sed 's/ //g' <<< $local_ips)$(hostname),$(hostname -f),$DOMAIN10.0.100.,10.0.100.*,$no_proxy"
export NO_PROXY="$no_proxy"
echo "Force Ruby ecosystem to use system SSL certificates"
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
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
}