4 #Can this be fetched from dpkg?
5 OPENSRF_PREFIX="/openils"
6 . /usr/share/debconf/confmodule
7 HFQDN=$(perl -MNet::Domain -e 'print Net::Domain::hostfqdn() . "\n";')
10 if [ $_DEBUG > 0 ]; then $@;fi
14 HOSTS_FILE_TAG="OPENSRF_DEB Addresses"
15 if ! grep -q "$HOSTS_FILE_TAG" /etc/hosts
17 cp -f /etc/hosts /etc/hosts.orig
18 DEBUG echo "Adding entries to /etc/hosts..."
19 sed -i "2i\#$HOSTS_FILE_TAG" /etc/hosts
20 sed -i "3i\127.0.1.2\tpublic.$HFQDN\tpublic #OPENSRF_DEB" /etc/hosts
21 sed -i "4i\127.0.1.3\tprivate.$HFQDN\tprivate #OPENSRF_DEB" /etc/hosts
22 sed -i '5i\ ' /etc/hosts
24 DEBUG echo "Hosts file has already been modified!"
27 } #modify_hosts_file()
29 if ! grep -q "^opensrf:" /etc/passwd
31 DEBUG echo "Opensrf user does not exist! Creating..."
32 if ! grep -q "x:2000" /etc/passwd; then
33 useradd -m -s /bin/bash -u 2000 opensrf
35 useradd -m -s /bin/bash opensrf
37 db_get opensrf/user_password || true
40 if [ ! -f "$tfile" ]; then
41 echo "ERROR Creating temp file!"
45 DEBUG echo "creating tmp pw file as $tfile"
49 DEBUG echo "about to change"
51 DEBUG echo "about to rm"
53 DEBUG echo "Set user opensrf's password"
55 DEBUG echo "Opensrf user already exists, so not doing anything!"
62 if ! grep -q "$OPENSRF_PREFIX/bin" /home/opensrf/.bashrc
64 DEBUG echo "Adding path for opensrf user..."
65 sed -i "2i\export PATH=$OPENSRF_PREFIX/bin:\$PATH" /home/opensrf/.bashrc
66 sed -i '3i\export PERL5LIB=/openils/lib/perl5:$PERL5LIB' /home/opensrf/.bashrc
68 DEBUG echo "OpenSRF Path already added!"
73 reconfigure_ejabberd()
75 if grep -q "^{hosts, \[\"localhost\"]}" /etc/ejabberd/ejabberd.cfg
77 DEBUG echo "Stock ejabberd detecting. Stopping and modifying config!"
78 /etc/init.d/ejabberd stop
79 cp /etc/ejabberd/ejabberd.cfg /etc/ejabberd/ejabberd.cfg.orig
80 sed -i "s/^{hosts, \[\"localhost\"\]}/{hosts, [\"localhost\", \"private.$HFQDN\", \"public.$HFQDN\"]}/g" /etc/ejabberd/ejabberd.cfg
81 sed -i "s/max_user_sessions,\ \[{10,/max_user_sessions,\ \[{10000,/g" /etc/ejabberd/ejabberd.cfg
82 sed -i 's/{max_stanza_size, 65536}/{max_stanza_size, 2000000}/g' /etc/ejabberd/ejabberd.cfg
83 sed -i 's/{max_stanza_size, 131072}/{max_stanza_size, 2000000}/g' /etc/ejabberd/ejabberd.cfg
84 sed -i 's/{shaper, normal, {maxrate, 1000}}/{shaper, normal, {maxrate, 500000}}/g' /etc/ejabberd/ejabberd.cfg
85 sed -i 's/{shaper, fast, {maxrate, 50000}}/{shaper, fast, {maxrate, 500000}}/g' /etc/ejabberd/ejabberd.cfg
86 sed -i 's/{mod_offline/%%{mod_offline/g' /etc/ejabberd/ejabberd.cfg
87 chown ejabberd.ejabberd /etc/ejabberd/ejabberd.cfg
88 /etc/init.d/ejabberd start
90 DEBUG echo "Ejabberd has already been modified (or atleast the hosts line has). No Changes made."
92 } #reconfigure_ejabberd()
98 if ! status=$(ejabberdctl register "$USER" "$HOST" "$PASSWD") ; then
99 if echo $status | grep -q "already registered" ; then
100 DEBUG echo "User \"$USER@$HOST\" is already registered. Password IS NOT changed."
102 echo "Can't register user \"$USER@$HOST\"."
105 DEBUG echo "User \"$USER@$HOST\" is registered successfully."
111 register_ejabberd_users()
113 db_get opensrf/ejabber_password
115 #if [ -n "$USER" -a -n "$PASSWD" ]; then
116 DEBUG echo -n "Waiting for ejabberd to register admin user"
118 if ejabberdctl status >/dev/null || test $? = 1 ; then
119 # Ejabberd is starting ($? = 1) or running ($? = 0) already.
122 while ! ejabberdctl status >/dev/null ; do
125 if [ $cnt -ge 60 ] ; then
127 echo "Can't register Ejabberd users."
128 echo -n "Ejabberd is taking too long to start!"
136 if [ $flag -eq 1 ] ; then
137 add_ejabber_user router private.$HFQDN $EJABBER_PASS
138 add_ejabber_user opensrf private.$HFQDN $EJABBER_PASS
139 add_ejabber_user router public.$HFQDN $EJABBER_PASS
140 add_ejabber_user opensrf public.$HFQDN $EJABBER_PASS
143 # if ! status=$(ejabberdctl register "$USER" "$HOST" "$PASSWD") ; then
144 # if echo $status | grep -q "already registered" ; then
145 # echo "Admin user \"$USER@$HOST\" is already registered. Password IS NOT changed."
147 # echo "Can't register admin user \"$USER@$HOST\"."
150 # echo "Admin user \"$USER@$HOST\" is registered successfully."
156 echo "Can't register Ejabberd users!"
157 echo "Ejabberd server is not started."
160 } #register_ejabberd_users()
163 #END EJABBERD SECTION
167 #CODE SOURCE: Makefile.install
169 for m in ssl osrf_http_translator osrf_json_gateway; do a2enmod $m > /dev/null; done;
170 # adds a placeholder module so apxs will be happy
171 if [ ! "$(grep mod_placeholder /etc/apache2/httpd.conf)" ]; then
172 echo -e "#\n#LoadModule mod_placeholder /usr/lib/apache2/modules/mod_placeholder.so" >> /etc/apache2/httpd.conf
173 /etc/init.d/apache2 restart
180 LD_CONF_FILE="/etc/ld.so.conf.d/osrf.conf"
181 #not sure if this should nuke the file first or just append
182 # this violates sane naming policies, but follows the install docs
183 if ! test -e $LD_CONF_FILE
185 DEBUG echo "Confgiuring library paths..."
186 echo "$OPENSRF_PREFIX/lib" > $LD_CONF_FILE
187 echo "/usr/local/lib" >> $LD_CONF_FILE
190 DEBUG echo "Library paths already configured!"
196 #Fixperms... But why?
197 DEBUG echo "Changing ownership of $OPENSRF_PREFIX (and everything in it) to opensrf..."
198 mkdir -p $OPENSRF_PREFIX/var/run
199 mkdir -p $OPENSRF_PREFIX/var/log
200 mkdir -p $OPENSRF_PREFIX/var/lock
201 chown -R opensrf:opensrf $OPENSRF_PREFIX
203 configure_opensrf_xml()
205 db_get opensrf/ejabber_password
207 cp -n $OPENSRF_PREFIX/conf/opensrf.xml.example $OPENSRF_PREFIX/conf/opensrf.xml
208 cp -n $OPENSRF_PREFIX/conf/opensrf_core.xml.example $OPENSRF_PREFIX/conf/opensrf_core.xml
209 cp -n $OPENSRF_PREFIX/conf/srfsh.xml.example $OPENSRF_PREFIX/conf/srfsh.xml
210 sed -i "s|d>password|d>$RET|g" $OPENSRF_PREFIX/conf/*.xml
211 cp -n $OPENSRF_PREFIX/conf/srfsh.xml /home/opensrf/.srfsh.xml && \
212 chown opensrf /home/opensrf/.srfsh.xml && chmod 600 /home/opensrf/.srfsh.xml
213 HFQDN=$(perl -MNet::Domain -e 'print Net::Domain::hostfqdn() . "\n";')
214 sed -i "s/<localhost>/<$HFQDN>/g" $OPENSRF_PREFIX/conf/opensrf.xml
215 sed -i "s/<\/localhost>/<\/$HFQDN>/g" $OPENSRF_PREFIX/conf/opensrf.xml
216 sed -i "s/\.localhost</\.$HFQDN</g" $OPENSRF_PREFIX/conf/opensrf_core.xml
217 sed -i "s/\.localhost</\.$HFQDN</g" $OPENSRF_PREFIX/conf/opensrf.xml
218 sed -i "s/\.localhost</\.$HFQDN</g" /home/opensrf/.srfsh.xml
226 update-rc.d opensrf defaults > /dev/null
228 osfr_control_symlink()
230 if [ -e /openils/bin/osrf_control ]
232 rm /openils/bin/osrf_control
233 ln -s /openils/bin/opensrf-perl.pl /openils/bin/osrf_control
235 ln -s /openils/bin/opensrf-perl.pl /openils/bin/osrf_control
242 register_ejabberd_users
246 configure_opensrf_xml
252 DEBUG echo "Installation of OpenSRF completed!"
253 #DEBUG echo "Starting OpenSRF:"
254 echo "To start opensrf, run /etc/init.d/opensrf start"
255 echo "Please make sure any pending network changes have taken place before attempting this"
256 #/etc/init.d/opensrf start