forked from ali5ter/vcloud-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·202 lines (189 loc) · 4.92 KB
/
install
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
#
# @file install
# ☆ Install for assembling and installing vcloud-client
#
#
# Document root
#
SRC=www
#
# Installed target dir
#
TARGET=vcloud-js-sdk-test
#
# A timestamp
#
TIMESTAMP=$(date +"%F-%H%M%S")
#
# Cell target directory
#
OB_TARGET=/opt/vmware/vcloud-director/system/com/vmware/vcloud/ui-vcloud-webapp/1.0.0
#
# Cell war file name
#
WAR=ui-vcloud-webapp-1.0.0.war
#
# Back up war file name
#
BACKUP=${WAR}.$TIMESTAMP.bak
#
# Source Tree target directory
#
ST_TARGET=ui/ssui/ui-vcloud-webapp/target/ui-vcloud-webapp-1.0.0
#
# Source Tree base directory
#
ST_BASE=${VCLOUD_SRC_ROOT:-'.'}
#
# Default vCloud JS SDK src directory
#
SDK_SRC=${VCLOUD_JS_SDK_ROOT:-'../vcloud-js-sdk'};
#
# Watch poll time (seconds)
#
WATCH_POLL=1
function _failWith {
echo 'failed'; echo $1; echo
exit 0
}
function _mkdir {
[ -d $1 ] && rm -fR $1
mkdir -p $1 2>/dev/null
}
function _setSdkSrcDir {
echo -n "Where is your vcloud-js-sdk src tree? [$SDK_SRC] "
read srcDir
[ ! -z "$srcDir" ] && SDK_SRC=$srcDir;
echo
}
function _copySdk {
echo -n 'Copying vCloud JS SDK... '
[ ! -d $SDK_SRC ] && _failWith "Unable to find a SDK src tree directory at $SDK_SRC"
cp $SDK_SRC/vcloud-js-sdk*.js $SRC/js/lib/
echo 'done'
echo
}
function _installIntoOfficialBuild {
echo -n 'Installing into your vCD cell...'
type -P unzip >/dev/null 2>&1 || _failWith "Unable to find the unzip utility."
type -P zip >/dev/null 2>&1 || _failWith "Unable to find the zip utility."
[ ! -d $OB_TARGET ] && _failWith "Unable to find the war file in $OB_TARGET"
cd $OB_TARGET
local fusr=$(ls -l $WAR | awk '{ print $3 }')
local fgrp=$(ls -l $WAR | awk '{ print $4 }')
cp $WAR ../$BACKUP
chown ${fusr}:${fgrp} ../$BACKUP
unzip $WAR >/dev/null 2>&1
rm -f $WAR
echo -n '...'
cp -r $SL_SRC .
echo -n '...'
zip -urg ../$WAR * >/dev/null 2>&1
echo -n '...'
rm -fR ./*
mv ../$WAR .
chmod 640 $WAR
chown ${fusr}:${fgrp} $WAR
cd - >/dev/null
echo ' done'
echo
}
function _setVcdSrcDir {
echo -n "Where is your vCD src tree? [$ST_BASE] "
read srcDir
[ ! -z "$srcDir" ] && ST_BASE=$srcDir
echo
}
function _installIntoP4Source {
echo -n 'Installing into your src tree... '
local target=$ST_BASE/$ST_TARGET
[ ! -d $target ] && _failWith "Unable to find a src tree directory at $target"
local dir=$target/$TARGET
_mkdir $dir
cp -r $SRC/* $dir/
echo 'done'
echo
}
function _watchAndInstall {
local changes=''
local target=${1:-'cell'}
echo 'Watching for any changes. Quit using [cntl-C].'
echo
while true; do
changes=$(find $SRC -mtime ${WATCH_POLL}s)
[[ ! -z "$changes" ]] && {
echo '['$(date +"%F-%H%M%S")"] These following things changed:"
echo "$changes"
if [ "$target" == "cell" ]; then
_installIntoOfficialBuild
else
_installIntoP4Source
fi
}
sleep $WATCH_POLL;
done
}
function _help {
local helpText="
Install script for vcloud-client.
By default, this script will install into a vCD cell.
Usage: make <option>
-cs, --copy-sdk copy the SDK lib from a local vCloud JS SDK src tree
and place into doc root
-id, --install-dev install doc root into a vCD src tree
-ic, --install-cell install doc root into a vCD cell (default)
-wd, --watch-dev install to vCD src tree when anything in the doc root changes
-w, --watch install to vCD cell when anything in the doc root changes
"
echo "$helpText"
}
case "$1" in
--help|-h)
_help
;;
#
# Copy SDK lib from local SDK src tree and place them into this src tree
#
--copy-sdk|-cs)
_setSdkSrcDir
_copySdk
;;
#
# Watch doc root and install any changes into vCD src tree
#
--watch-dev|-wd)
_setVcdSrcDir
_watchAndInstall 'dev'
;;
#
# Copy doc root into correct position in vCD src tree
#
--install-dev|-id)
_setVcdSrcDir
_installIntoP4Source
echo "Installed successfully at $ST_TARGET"
echo "Go to http://[your_cell_host_and_port]/cloud/$TARGET/index.html"
echo
;;
#
# Watch doc root and install on any changes into vCD cell
#
--watch|-w)
_watchAndInstall 'cell'
;;
#
# Copy doc root into correct position of a running vCD cell
#
--install-cell|-ic|*)
_installIntoOfficialBuild
echo "Installed successfully. Please restart the cell to complete the \
installation, e.g. 'service vmware-vcd restart'."
echo "Then go to http://[your_cell_host_and_port]/cloud/$TARGET/index.html"
echo
echo "NOTE: To back-out this change, run the following command:"
echo " mv ${OB_TARGET%/*}/$BACKUP $OB_TARGET/$WAR"
echo "and restart the cell."
echo
;;
esac