forked from stmansour/rentroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·155 lines (143 loc) · 4.74 KB
/
update.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
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
#!/bin/bash
#############################################################################
# readConfig
# Description:
# Read the config.json file from the directory containing this script
# to set some of the key values needed to access the artifactory repo.
#
# Upon returning, URLBASE will end with the character "/".
#
# Params:
# none
#
# Returns:
# sets variables: APIKEY, REPOUSER, and URLBASE
#
#############################################################################
readConfig() {
RELDIR=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
CONF="${RELDIR}/config.json"
REPOUSER=$(grep RepoUser ${CONF} | awk '{print $2;}' | sed -e 's/[,"]//g')
APIKEY=$(grep RepoPass ${CONF} | awk '{print $2;}' | sed -e 's/[,"]//g')
URLBASE=$(grep RepoURL ${CONF} | awk '{print $2;}' | sed -e 's/[,"]//g')
# add a trailing / if it does not have one...
if [ "${URLBASE: -1}" != "/" ]; then
URLBASE="${URLBASE}/"
fi
echo "RELDIR = ${RELDIR}"
echo "REPOUSER = ${REPOUSER}"
echo "APIKEY = ${APIKEY}"
echo "URLBASE = ${URLBASE}"
}
#############################################################################
# configure
# Description:
# The only configuration needed is the jfrog cli environment. Just
# make sure we have it in the path. If it is not present, then
# get it.
#
# Params:
# none
#
# Returns:
# nothing
#
#############################################################################
configure() {
#---------------------------------------------------------
# the user's bin directory is not created by default...
#---------------------------------------------------------
if [ ! -d ~ec2-user/bin ]; then
mkdir ~ec2-user/bin
fi
#---------------------------------------------------------
# now make sure that we have jfrog...
#---------------------------------------------------------
if [ ! -f ~ec2-user/bin/jfrog ]; then
curl -s -u "${REPOUSER}:${APIKEY}" ${URLBASE}accord/tools/jfrog > ~ec2-user/bin/jfrog
chown ec2-user:ec2-user ~ec2-user/bin/jfrog
chmod +x ~ec2-user/bin/jfrog
fi
if [ ! -d ~ec2-user/.jfrog ]; then
curl -s -u "${REPOUSER}:${APIKEY}" ${URLBASE}accord/tools/jfrogconf.tar > ~ec2-user/jfrogconf.tar
pushd ~ec2-user
tar xvf jfrogconf.tar
rm jfrogconf.tar
chown ec2-user:ec2-user ~ec2-user/bin/jfrog
popd
fi
if [ ! -d ~root/.jfrog ]; then
curl -s -u "${REPOUSER}:${APIKEY}" ${URLBASE}accord/tools/jfrogconf.tar > ~root/jfrogconf.tar
pushd ~root
tar xvf jfrogconf.tar
rm jfrogconf.tar
popd
fi
}
#############################################################################
# GetLatestProductRelease
# Description:
# The only configuration needed is the jfrog cli environment. Just
# make sure we have it in the path. If it is not present, then
# get it.
#
# Params:
# ${1} = base name of product (rentroll, phonebook, mojo, ...)
#
# Returns:
# nothing
#
#############################################################################
GetLatestRepoRelease() {
f=$(~ec2-user/bin/jfrog rt s "accord/air/release/*" | grep ${1} | awk '{print $2}' | sed 's/"//g')
if [ "x${f}" = "x" ]; then
echo "There are no product releases for ${f}"
exit 1
fi
cd ${RELDIR}/..
d=$(pwd)
t=$(basename ${f})
curl -s -u "${REPOUSER}:${APIKEY}" ${URLBASE}${f} > ${t}
}
#----------------------------------------------
# ensure that we're in the rentroll directory...
#----------------------------------------------
dir=${PWD##*/}
if [ ${dir} != "rentroll" ]; then
echo "This script must execute in the rentroll directory."
exit 1
fi
user=$(whoami)
if [ ${user} != "root" ]; then
echo "This script must execute as root. Try sudo !!"
exit 1
fi
readConfig
configure
echo -n "Shutting down rentroll server."; $(./activate.sh stop) >/dev/null 2>&1
echo -n "."
echo -n "."; cd ${RELDIR}/..
echo -n "."; rm -f rentroll*.tar
echo
echo -n "Retrieving latest released Rentroll..."
GetLatestRepoRelease "rentroll"
echo "Installing.."
echo -n "."; cd ${RELDIR}/..
#echo -n "."; rm -f rentroll*.tar
echo -n "."; gunzip -f rentroll*.tar.gz
echo -n "."; tar xf rentroll*.tar
echo -n "."; chown -R ec2-user:ec2-user rentroll
echo -n "."; rm -f rentroll*.tar*
echo -n "."; cd ${RELDIR}
echo
echo -n "Installation complete. Launching..."
echo -n "."; ./activate.sh start
echo -n "."; sleep 2
echo -n "."; status=$(./activate.sh ready)
echo -n "."; ./installman.sh >installman.log 2>&1 # a task to perform while activation is running
echo
if [ "${status}" = "OK" ]; then
echo "Activation successful"
else
echo "Problems activating rentroll. Status = ${status}"
fi