forked from GaborWnuk/docker-usergrid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_tomcat_admin_user.sh
34 lines (28 loc) · 1.31 KB
/
create_tomcat_admin_user.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
#!/bin/bash
#
# Based on https://github.com/tutumcloud/tutum-docker-tomcat
#
if [ -f ${TOMCAT_CONFIGURATION_FLAG} ]; then
echo "Tomcat 'admin' user already created"
exit 0
fi
#generate password
PASS=${TOMCAT_PASS:-$(pwgen -s 12 1)}
_word=$( [ ${TOMCAT_PASS} ] && echo "preset" || echo "random" )
echo "=> Creating and admin user with a ${_word} password in Tomcat ..."
sed -i -r 's/<\/tomcat-users>//' /etc/tomcat7/tomcat-users.xml
echo '<role rolename="manager-gui"/>' >> /etc/tomcat7/tomcat-users.xml
echo '<role rolename="manager-script"/>' >> /etc/tomcat7/tomcat-users.xml
echo '<role rolename="manager-jmx"/>' >> /etc/tomcat7/tomcat-users.xml
echo '<role rolename="admin-gui"/>' >> /etc/tomcat7/tomcat-users.xml
echo '<role rolename="admin-script"/>' >> /etc/tomcat7/tomcat-users.xml
echo "<user username=\"admin\" password=\"${PASS}\" roles=\"manager-gui,manager-script,manager-jmx,admin-gui, admin-script\"/>" >> ${TOMCAT_CONFIG_DIR}/tomcat-users.xml
echo '</tomcat-users>' >> /etc/tomcat7/tomcat-users.xml
echo "=> Done!"
touch ${TOMCAT_CONFIGURATION_FLAG}
echo "========================================================================"
echo "You can now configure to this Tomcat server using:"
echo ""
echo " admin:${PASS}"
echo ""
echo "========================================================================"