-
Notifications
You must be signed in to change notification settings - Fork 7
/
.profile
executable file
·131 lines (102 loc) · 3.3 KB
/
.profile
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
##
export MY_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PUBSUBPLUS_CF_DEV=${PUBSUBPLUS_CF_DEV:-$MY_HOME}
export PATH=$PUBSUBPLUS_CF_DEV/bin:$PATH
export WORKSPACE=${WORKSPACE:-$HOME/workspace}
export SYSTEM_DOMAIN=${SYSTEM_DOMAIN:-"bosh-lite.com"}
export CF_ADMIN_PASSWORD=${CF_ADMIN_PASSWORD:-"admin"}
export BUCC_HOME=${BUCC_HOME:-$PUBSUBPLUS_CF_DEV/bucc}
export BUCC_STATE_ROOT=${BUCC_STATE_ROOT:-$WORKSPACE/BOSH_LITE_VM/state}
export BUCC_VARS_FILE=${BUCC_VARS_FILE:-$WORKSPACE/BOSH_LITE_VM/vars.yml}
export BUCC_STATE_STORE=${BUCC_STATE_STORE:-$BUCC_STATE_ROOT/state.json}
export BUCC_VARS_STORE=${BUCC_VARS_STORE:-$BUCC_STATE_ROOT/creds.yml}
export BOSH_ENV_FILE=${BOSH_ENV_FILE:-$WORKSPACE/bosh_env.sh}
export DOT_BOSH_ENV_FILE=${DOT_BOSH_ENV_FILE:-$WORKSPACE/.env}
LOCKFILE=$HOME/.env.lck
if [ -f $BUCC_HOME/bin/bucc ]; then
## Avoids concurrent writes
(
flock -x 200
$BUCC_HOME/bin/bucc env > $DOT_BOSH_ENV_FILE
flock -u 200
) 200>$LOCKFILE
fi
if [ -f $DOT_BOSH_ENV_FILE ]; then
## Avoids reads during writes
exec 200>$LOCKFILE
flock -x 200
source $DOT_BOSH_ENV_FILE
export BOSH_IP=$BOSH_GW_HOST
flock -u 200
fi
if [ -f $WORKSPACE/deployment-vars.yml ]; then
CF_PASSWORD=$(bosh int $WORKSPACE/deployment-vars.yml --path /cf_admin_password 2>/dev/null)
if [ $? -eq '1' ]; then
echo 'Detected Windows Deployment, PCFDev is running separately from BOSH-Lite'
export SYSTEM_DOMAIN='local.pcfdev.io'
export WINDOWS='true'
else
export CF_ADMIN_PASSWORD=$CF_PASSWORD
fi
fi
source $PUBSUBPLUS_CF_DEV/bin/bosh-common.sh
if [ -z $SEEN_BANNER ]; then
echo
echo
cat $PUBSUBPLUS_CF_DEV/.banner
echo
echo
export SEEN_BANNER=1
fi
printf "PUBSUBPLUS_CF_DEV\t\t%s\n" "$PUBSUBPLUS_CF_DEV"
printf "WORKSPACE\t\t\t%s\n" "$WORKSPACE"
## Test PCF Dev access
CF_API_FOUND=$( cf api | grep "api endpoint" | grep http | wc -l )
if [ "$CF_API_FOUND" -eq "0" ]; then
printf "CF \t\t\t\t%s\n" "Access attempt (may take some time)"
ping -q -c 5 -w 10 api.$SYSTEM_DOMAIN > /dev/null
if [ $? -eq "0" ]; then
export CF_ACCESS=0
cf api https://api.$SYSTEM_DOMAIN --skip-ssl-validation > /dev/null
if [ $? -eq 0 ]; then
cf auth admin $CF_ADMIN_PASSWORD > /dev/null
if [ $? -eq 0 ]; then
export CF_ACCESS=1
else
export CF_ACCESS=0
fi
else
export CF_ACCESS=0
fi
else
export CF_ACCESS=0
fi
if [ $CF_ACCESS -eq "1" ]; then
printf "CF \t\t\t\t%s\n" "OK"
else
printf "CF \t\t\t\t%s\n" "WARN: CF is not accessible. Is it installed? running? is routing enabled?"
fi
else
CF_API=$( cf api | grep "api endpoint" | grep http )
printf "CF \t\t\t\t%s\n" "You seem to have CF set to access ( $CF_API )"
if [[ $CF_API == *"local.pcfdev.io"* ]]; then
export WINDOWS='true'
export SYSTEM_DOMAIN='local.pcfdev.io'
fi
export CF_ACCESS=1
fi
## Test BOSH access
export BOSH_ACCESS=0
printf "BOSH \t\t\t\t%s\n" "Access attempt (may take some time)"
ping -q -c 5 -w 10 $BOSH_IP > /dev/null
if [ $? -eq "0" ]; then
targetBosh
else
export BOSH_ACCESS=0
fi
if [ $BOSH_ACCESS -eq "1" ]; then
printf "BOSH \t\t\t\t%s\n" "OK"
else
printf "BOSH \t\t\t\t%s\n" "WARN: BOSH is not accessible. Is it installed ? running? is routing enabled?"
fi
echo