source: gsdl/stable/gsicontrol.sh@ 20323

Last change on this file since 20323 was 19453, checked in by ak19, 15 years ago

Usage in its own subroutine. Switch on target commands now has a default clause which prints the usage. (Noticed the need for this when I found that the target configure-port is no longer available.)

  • Property svn:executable set to *
File size: 5.3 KB
Line 
1#!/bin/bash
2
3testdone=0
4
5function test-gsdlhome {
6 if [ $testdone == "0" ] ; then
7 if test -z "$GSDLHOME" ; then
8 echo "" ;
9 echo "Environment variable GSDLHOME not set." ;
10 echo " This needs to be set to run this gsicontrol command." ;
11 echo " Have you run 'source setup.bash'?" ;
12 echo "" ;
13 exit 1
14 else
15 echo "Using: " ;
16 echo " GSDLHOME = $GSDLHOME" ;
17 echo " GSDLOS = $GSDLOS" ;
18 fi
19 testdone=1
20 fi
21}
22
23function configure-cgi {
24 test-gsdlhome
25 if test ! -e $GSDLHOME/cgi-bin/gsdlsite.cfg ; then
26 echo "Configuring cgi-bin/gsdlsite.cfg" ;
27 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg ;
28 else
29 echo "WARNING: Nothing done for make configure-cgi." ;
30 echo " If you wish to regenerate the file " ;
31 echo " $GSDLHOME/cgi-bin/gsdlsite.cfg" ;
32 echo " from scratch, delete the existing file first." ;
33 fi
34}
35
36function configure-admin {
37 test-gsdlhome
38 echo "" ;
39 echo "Configuring admin user password:" ;
40 encrypted_password=`getpw` ;
41 if [ $? = "0" ] ; then
42 echo -e "[admin]\n<enabled>true\n<groups>administrator,colbuilder,all-collections-editor\n<password>$encrypted_password\n<username>admin" \
43 | txt2db -append "$GSDLHOME/etc/users.gdb" ;
44 else
45 echo "Did not set password" ;
46 fi
47 echo ""
48}
49
50
51function _configure-port-and-connection {
52 test-gsdlhome
53 echo "Enter port number to use:"
54 read port ;
55 echo "Allow external connections [yes/no]:"
56 read connection ;
57 if [ $connection = "yes" ] || [ $connection = "y" ] ; then
58 allowfrom="all"
59 else
60 allowfrom="127.0.0.1"
61 fi
62
63 if test ! -z $port ; then
64 echo "Port: $port" ;
65 echo "Stopping web server (if running)" ;
66 web-stop-tested ;
67 echo "Setting config file to use port $port";
68 cat "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf.in" \
69 | sed "s@\*\*PORT\*\*@$port@g" \
70 | sed "s@\*\*CONNECTION\*\*@$allowfrom@g" \
71 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
72 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \
73 > "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ;
74 echo "Type '$0 web-start' to start the web server running on port $port" ;
75 fi ;
76 echo "Done" ;
77}
78
79
80MONITOR_SUCCESS="MAKE SUCCESSFUL"
81MONITOR_FAILED="MAKE FAILED"
82MONITOR_FINISHED="MAKE DONE"
83
84function configure-apache {
85 test-gsdlhome
86 configfile=$1 ;
87# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
88 if [ "x$configfile" = "x" ]; then
89 if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
90 cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
91 fi
92 configfile="$GSDLHOME/llssite.cfg";
93 fi ;
94 echo "Configuring the apache webserver..." ;
95 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
96
97 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
98 if [ $externalaccess == "1" ] ; then
99 externalaccess="yes"
100 else
101 externalaccess="no"
102 fi
103
104 echo -e "$port\n$externalaccess" | _configure-port-and-connection ;
105 if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
106 echo $MONITOR_SUCCESS;
107 else
108 echo $MONITOR_FAILED;
109 fi
110 echo $MONITOR_FINISHED
111}
112
113function configure-web {
114 configure-cgi
115 configure-apache $1
116}
117
118function web-status {
119 test-gsdlhome
120 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl status
121}
122
123function web-start {
124 test-gsdlhome
125 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl start
126 echo $MONITOR_SUCCESS
127 echo $MONITOR_FINISHED
128}
129
130function web-restart {
131 test-gsdlhome
132 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
133 echo $MONITOR_SUCCESS
134 echo $MONITOR_FINISHED
135}
136
137function web-graceful {
138 test-gsdlhome
139 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
140 echo $MONITOR_SUCCESS
141 echo $MONITOR_FINISHED
142}
143
144function web-stop-tested {
145# This version runs without testing for GSDLHOME
146# Useful to be run as a target when we know test-gsdlhome has already
147# been done. This avoids a unnecessary repetition of printing
148# out the values of GSDLHOME and GSDLOS
149 if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
150 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl stop ;
151 fi
152}
153
154function web-stop {
155 test-gsdlhome
156 web-stop-tested
157 echo $MONITOR_SUCCESS
158 echo $MONITOR_FINISHED
159}
160
161function usage {
162 echo ""
163 echo " Usage: $0 <command>"
164 echo " where <command> is any of the following: "
165 echo " web-start"
166 echo " web-stop"
167 echo " web-restart"
168 echo " web-status"
169 echo " web-graceful"
170 echo " configure-admin"
171 echo " configure-web [config-filename]"
172 echo " configure-apache [config-filename]"
173 echo " configure-cgi"
174 echo " test-gsdlhome"
175 echo " web-stop-tested"
176 echo ""
177}
178
179
180if [[ $# < 1 || $# > 2 ]] ; then
181 usage
182 exit 0
183fi
184
185target=$1
186configfile=$2
187
188case $target in
189 web-start)
190 web-start;;
191 web-stop)
192 web-stop;;
193 web-restart)
194 web-restart;;
195 web-status)
196 web-status;;
197 web-graceful)
198 web-graceful;;
199 configure-admin)
200 configure-admin;;
201 configure-web)
202 configure-web $configfile;;
203 configure-apache)
204 configure-apache $configfile;;
205 configure-cgi)
206 configure-cgi;;
207 test-gsdlhome)
208 test-gsdlhome;;
209 web-stop-tested)
210 web-stop-tested;;
211 *)
212 echo
213 echo "Command unrecognised: $target"
214 usage;;
215
216esac
217
218exit;
Note: See TracBrowser for help on using the repository browser.