summaryrefslogtreecommitdiffstats
path: root/packaging/idrop-web.list.template
blob: 39a3044bfa4d58a73bde7c194f231c8ad52c4d9f (plain)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
%product iRODS iDrop Web
%copyright Any copyright here.
%vendor Data Intensive Cyberinfrastructure Foundation, Renaissance Computing Institute
%license COPYING
%readme README
%description Web Based Interface for Interacting with the iRODS data grid
%version 1.0.1 100001

# don't think http is actually needed
# %requires httpd 2

%if DEB
%requires tomcat6
%requires openjdk-6-jre
%else
%requires java 6
%endif

%format all

# =-=-=-=-=-=-=-
# variables for configuring the install
# =-=-=-=-=-=-=-
$OS_IDROP_ACCT=idropweb
$OS_IDROP_DIR=idrop-web
$IDROP_HOME_DIR=/var/lib/$OS_IDROP_DIR
$IDROP_EXTRAS=idrop-web-extras

$TOMCAT_STARTED=false

# these tomcat vars used for tomcat install on rpm systems
$TOMCAT_EXTRACT_DIR=/var/lib
$TOMCAT_VER=6
$TOMCAT_VER_DOT=0.35
$TOMCAT_FILE=apache-tomcat-${TOMCAT_VER}.${TOMCAT_VER_DOT}
$TOMCAT_ARC_FILE=${TOMCAT_FILE}.tar.gz
$TOMCAT_HTTP_HOST=http://apache.mirrors.pair.com/tomcat/tomcat-${TOMCAT_VER}/v${TOMCAT_VER}.${TOMCAT_VER_DOT}/bin/
$TOMCAT_TMP_LOC=/tmp/tomcat${TOMCAT_VER}.tar.gz

%if DEB
# these tomcat vars used for tomcat install on debian systems
# hopefully everything will migrate to use these vars when centos
# finally catches up with support for tomcat 6
$OS_TOMCAT_ACCT=tomcat6
$TOMCAT_HOME_DIR=/var/lib/${OS_TOMCAT_ACCT}
$DEB=true
%else
$TOMCAT_HOME_DIR=${TOMCAT_EXTRACT_DIR}/idrop-tomcat-${TOMCAT_VER}.${TOMCAT_VER_DOT}
$OS_TOMCAT_ACCT=idroptc6
$RPM=true
%endif

# =-=-=-=-=-=-=-
# preinstall directives
# =-=-=-=-=-=-=-

# if this is a centos install, use wget to download tomcat 6
# and install manually # also add a service account for tomcat
%if RPM
%preinstall << END_PREINSTALL

#make sure tomcat is not already installed here
if [ -d "${TOMCAT_HOME_DIR}" ]; then
  echo "WARNING :: Tomcat Is Already Installed In: ${TOMCAT_HOME_DIR}"
else
# install tomcat
  echo "INFO :: Getting Apache Tomcat version: ${TOMCAT_VER}.${TOMCAT_VER_DOT} ..."
# download install archive
  wget -O ${TOMCAT_TMP_LOC} ${TOMCAT_HTTP_HOST}${TOMCAT_ARC_FILE}
# unpack into /var/lib
  tar -zxf $TOMCAT_TMP_LOC -C $TOMCAT_EXTRACT_DIR
  mv /var/lib/${TOMCAT_FILE} ${TOMCAT_HOME_DIR}
fi

# create a service account for tomcat
# determine if the service account already exists
USER=$$( grep $OS_TOMCAT_ACCT /etc/passwd )
if [ -n "$$USER" ];
then
  echo "WARNING :: Service Account $OS_TOMCAT_ACCT Already Exists."
else
# create the service account
  echo "INFO :: Creating Service Account: $OS_TOMCAT_ACCT at ${TOMCAT_HOME_DIR}"
  /usr/sbin/useradd -c "Tomcat" -d ${TOMCAT_HOME_DIR} -s "/sbin/nologin" $OS_TOMCAT_ACCT
fi
ACCT=$OS_TOMCAT_ACCT
chown -R $$ACCT:$$ACCT ${TOMCAT_HOME_DIR}

# create a service account for idrop-web 
# determine if the service account already exists
USER=$$( grep $OS_IDROP_ACCT /etc/passwd )
if [ -n "$$USER" ];
then
 echo "WARNING :: Service Account $OS_IDROP_ACCT Already Exists"
else
# create the service account
 echo "INFO :: Creating Service Account: $OS_IDROP_ACCT at ${IDROP_HOME_DIR}"
 /usr/sbin/useradd -m -d ${IDROP_HOME_DIR} $OS_IDROP_ACCT
 chmod 755 ${IDROP_HOME_DIR}
fi
END_PREINSTALL

%elseif DEB
%preinstall << END_PREINSTALL
# create a service account for idrop-web 
# determine if the service account already exists
USER=$$( grep $OS_IDROP_ACCT /etc/passwd )
if [ -n "$$USER" ];
then
 echo "WARNING :: Service Account $OS_IDROP_ACCT Already Exists"
else
# create the service account
 echo "INFO :: Creating Service Account: $OS_IDROP_ACCT at ${IDROP_HOME_DIR}"
 /usr/sbin/useradd -m -d ${IDROP_HOME_DIR} $OS_IDROP_ACCT
 chmod 755 ${IDROP_HOME_DIR}
fi
END_PREINSTALL

%endif

# =-=-=-=-=-=-=-
# post install
# =-=-=-=-=-=-=-

%if RPM
%postinstall << END_POSTINSTALL

# start tomcat
echo "INFO :: Starting Tomcat ..."
su -p -s /bin/sh $OS_TOMCAT_ACCT ${TOMCAT_HOME_DIR}/bin/startup.sh

# wait until the tomcat conf/Catalina/localhost folder is created
# or timeout after about 10 seconds
TRIES=0
while [ "$$TRIES" -lt 100 -a ! -e ${TOMCAT_HOME_DIR}/conf/Catalina/localhost ]; do
  TRIES=$$((TRIES + 1))
  sleep .1
done

# create config file (if it does not exist) for idrop-web in order to allow symbolic linking
echo "INFO :: Configuring iDrop Web for Tomcat ..."
if [ -f ${TOMCAT_HOME_DIR}/conf/Catalina/localhost/${OS_IDROP_DIR}.xml ];
then
 echo "WARNING :: ${TOMCAT_HOME_DIR}/conf/Catalina/localhost/${OS_IDROP_DIR}.xml Already Exists"
else
 echo "<?xml version='1.0' encoding='utf-8'?>
<Context path=\"/idrop-web\" allowLinking=\"true\">

    <WatchedResource>WEB-INF/web.xml</WatchedResource>

</Context>" > ${TOMCAT_HOME_DIR}/conf/Catalina/localhost/${OS_IDROP_DIR}.xml
fi

# create symbolic link to idrop-web
if [ -f ${TOMCAT_HOME_DIR}/webapps/${OS_IDROP_DIR} ];
then
 echo "WARNING :: ${TOMCAT_HOME_DIR}/webapps/${OS_IDROP_DIR} Already Exists"
else
 ln -s ${IDROP_HOME_DIR} ${TOMCAT_HOME_DIR}/webapps/${OS_IDROP_DIR}
fi

# add iptables entry for HTTP and port 8080
echo "INFO :: Modifying Firewall For HTTP Port 8080 access ..."
/sbin/iptables -N idropweb
/sbin/iptables -I INPUT 1 -j idropweb
/sbin/iptables -A idropweb -m state --state NEW -p tcp --dport 80 -j ACCEPT
/sbin/iptables -A idropweb -m tcp -p tcp --dport 8080 -m state --state NEW -j ACCEPT
/sbin/iptables -A idropweb -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/service iptables save

# Done - print info for starting up
echo "INFO :: To Run IDrop Web In Web Browser Type: http://127.0.0.1:8080/idrop-web"
echo "INFO :: To use iDrop-Lite applet or iDrop Swing Desktop application, verify that your browser supports JAVA"
END_POSTINSTALL

%elseif DEB
%postinstall << END_POSTINSTALL

# if not already running - start tomcat
RESULT=$$(ps ax | grep -v grep | grep -i tomcat)
if [ -n "$$RESULT" ];
then
  echo "INFO :: Starting Tomcat ..."
  /usr/sbin/service ${TOMCAT_VER} start
fi

# wait until the tomcat conf/Catalina/localhost folder is created
# or timeout after about 10 seconds
TRIES=0
while [ "$$TRIES" -lt 100 -a ! -e ${TOMCAT_HOME_DIR}/conf/Catalina/localhost ]; do
  TRIES=$$((TRIES + 1))
  sleep .1
done

# create config file (if it does not exist) for idrop-web in order to allow symbolic linking
echo "INFO :: Configuring iDrop Web for Tomcat ..."
if [ -f ${TOMCAT_HOME_DIR}/conf/Catalina/localhost/${OS_IDROP_DIR}.xml ];
then
 echo "WARNING :: ${TOMCAT_HOME_DIR}/conf/Catalina/localhost/${OS_IDROP_DIR}.xml Already Exists"
else
 echo "<?xml version='1.0' encoding='utf-8'?>
<Context path=\"/idrop-web\" allowLinking=\"true\">

    <WatchedResource>WEB-INF/web.xml</WatchedResource>

</Context>" > ${TOMCAT_HOME_DIR}/conf/Catalina/localhost/${OS_IDROP_DIR}.xml
fi

# create symbolic link to idrop-web
if [ -f ${TOMCAT_HOME_DIR}/webapps/${OS_IDROP_DIR} ];
then
 echo "WARNING :: ${TOMCAT_HOME_DIR}/webapps/${OS_IDROP_DIR} Already Exists"
else
 ln -s ${IDROP_HOME_DIR} ${TOMCAT_HOME_DIR}/webapps/${OS_IDROP_DIR}
fi

# add iptables entry for HTTP and port 8080
echo "INFO :: Modifying Firewall For HTTP Port 8080 access ..."
/sbin/iptables -N idropweb
/sbin/iptables -I INPUT 1 -j idropweb
/sbin/iptables -A idropweb -m state --state NEW -p tcp --dport 80 -j ACCEPT
/sbin/iptables -A idropweb -m tcp -p tcp --dport 8080 -m state --state NEW -j ACCEPT
/sbin/iptables -A idropweb -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables-save

# Done - print info for starting up
echo "INFO :: To Run IDrop Web In Web Browser Type: http://127.0.0.1:8080/idrop-web"
echo "INFO :: To use iDrop-Lite applet or iDrop Swing Desktop application, verify that your browser supports JAVA"
END_POSTINSTALL

%endif

# =-=-=-=-=-=-=-
# preremove
# =-=-=-=-=-=-=-

%if RPM
%preremove << END_PREREMOVE
# first check to make sure idrop-web is not logged in.
USER=$$( who | grep $OS_IDROP_ACCT )
if [ -n "$$USER" ]; then
  echo "${OS_IDROP_ACCT} is currently logged in. Aborting."
  exit 1
fi

# stop tomcat if RPM
RESULT=$$(ps ax | grep -v grep | grep -i $OS_TOMCAT_ACCT )
if [ -n "$$RESULT" ];
then
 echo "INFO :: Stopping Tomcat ..."
 su -p -s /bin/sh $OS_TOMCAT_ACCT ${TOMCAT_HOME_DIR}/bin/shutdown.sh
fi

# remove iptables entries related to idropweb install
echo "INFO :: Removing Firewall Access for iDrop Web ..."
/sbin/iptables -F idropweb
/sbin/iptables -D INPUT -j idropweb
/sbin/iptables -X idropweb
/sbin/service iptables save
END_PREREMOVE

%elseif DEB
%preremove << END_PREREMOVE
# first check to make sure idrop-web is not logged in.
USER=$$( who | grep $OS_IDROP_ACCT )
if [ -n "$$USER" ]; then
  echo "${OS_IDROP_ACCT} is currently logged in. Aborting."
  exit 1
fi

# remove iptables entries related to idropweb install
echo "INFO :: Removing Firewall Access for iDrop Web ..."
/sbin/iptables -F idropweb
/sbin/iptables -D INPUT -j idropweb
/sbin/iptables -X idropweb
/sbin/iptables-save
END_PREREMOVE

%endif

# =-=-=-=-=-=-=-
# postremove
%if RPM
%postremove << END_POSTREMOVE

# remove idropweb service account
echo "INFO: :: Removing iDrop Web Service Account: ${OS_IDROP_ACCT} ..."
USER=$$( grep $OS_IDROP_ACCT /etc/passwd )
if [ -n "$$USER" ];
then
 /usr/sbin/userdel -r $OS_IDROP_ACCT
else
 echo "WARNING :: Service Account: ${OS_IDROP_ACCT} Already Removed"
fi

# clean up tomcat install if this is RPM
# remove tomcat service account
echo "INFO: :: Removing iDrop Web Tomcat Service Account: ${OS_TOMCAT_ACCT} ..."
USER=$$( grep $OS_TOMCAT_ACCT /etc/passwd )
if [ -n "$$USER" ];
then
 /usr/sbin/userdel -r $OS_TOMCAT_ACCT
else
 echo "WARNING :: Service Account: ${OS_TOMCAT_ACCT} Already Removed."
fi
END_POSTREMOVE

%elseif DEB
%postremove << END_POSTREMOVE

# remove idropweb service account
echo "INFO: :: Removing iDrop Web Service Account: ${OS_IDROP_ACCT} ..."
USER=$$( grep $OS_IDROP_ACCT /etc/passwd )
if [ -n "$$USER" ];
then
 /usr/sbin/userdel -r $OS_IDROP_ACCT
else
 echo "WARNING :: Service Account: ${OS_IDROP_ACCT} Already Removed"
fi
END_POSTREMOVE

%endif

# =-=-=-=-=-=-=-
# =-=-=-=-=-=-=-
# files, and more files...
d 775 idropweb idropweb /etc/idrop-web -
f 664 idropweb idropweb /etc/idrop-web/idrop-web-config.groovy ./idrop-web-config.groovy