add Angular (eg2) install steps
[sitka/sitka-tools.git] / deployment / install-eg.sh
index 4563d80..d4ad0a6 100755 (executable)
@@ -4,16 +4,14 @@
 HOSTNAME="nonprod"
 DEFAULT_USER="opensrf"
 INSTALL_USER="opensrf"
-#EGRELEASE="Evergreen-ILS-2.12.beta"
-#BUILDDIR="/home/${INSTALL_USER}/${EGRELEASE}"
 BUILDDIR="/home/${INSTALL_USER}/evergreen"
 INSTALLDIR="/srv/openils"
-BRANCH="user/jeffdavis/upgrade-303-tpac"
-STAMP_ID="rel_3_0_3"
-ALT_STAMP_IDS="3_0_3 rel_3_0_2 3_0_2 rel_3_0_1 3_0_1 rel_3_0_0 3_0_0"
-VERSION="3.0.3.sitka.beta1"
+BRANCH="user/jeffdavis/eg317-tpac"
+STAMP_ID="rel_3_1_7"
+ALT_STAMP_IDS="3_1_7"
+VERSION="3.1.7.sitka.1"
 SITKACONF="/home/${DEFAULT_USER}/sysadmin"
-SITKACONF_BRANCH="eg303"
+SITKACONF_BRANCH="master"
 SITKATOOLS="/root/sitka-tools"
 
 THISHOST=`hostname -s`
@@ -22,13 +20,15 @@ suwrap() {
   su -s /bin/bash -c "source ~/.bashrc ; $1" $2
 }
 
-while getopts ":pecwb" opt ; do
+while getopts ":pecWbtu" opt ; do
   case $opt in
     p ) PROD="prod";;
     e ) EDI="edi";;
     c ) CRONTAB="crontab";;
-    w ) WEBCLIENT="webclient";;
+    W ) SKIPWEBCLIENT="skipwebclient";;
     b ) USEBUNDLE="usebundle";;
+    t ) TARBALL="tarball";;
+    u ) UPDATEONLY="updateonly";;
   esac
 done
 shift $(($OPTIND - 1))
@@ -46,30 +46,41 @@ fi
 if [ ! -d "${SITKACONF}" ]
 then
   # this will fail unless DEFAULT_USER has read access to the repo
-  suwrap "cd /home/${DEFAULT_USER} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
+  suwrap "cd /home/${DEFAULT_USER} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER} || { echo "Could not get config files; exiting." ; exit 1; }
 fi
-suwrap "cd ${SITKACONF} && git fetch origin && git checkout ${SITKACONF_BRANCH} && git pull" ${DEFAULT_USER}
-
-# checkout EG source
-if [ ! -d "${BUILDDIR}" ]
-then
-  suwrap "cd /home/${INSTALL_USER} && git clone git://git.sitka.bclibraries.ca/sitka/evergreen evergreen" ${INSTALL_USER}
+suwrap "cd ${SITKACONF} && git fetch origin && git checkout ${SITKACONF_BRANCH} && git pull" ${DEFAULT_USER} || { echo "Could not checkout ${SITKACONF_BRANCH} config files; exiting." ; exit 1; }
+
+if [[ -n "$TARBALL" ]] ; then
+  EGRELEASE="Evergreen-ILS-${VERSION}"
+  EGRELEASETGZ="${EGRELEASE}.tar.gz"
+  [ ${VERSION} == "3.1.0" ] && EGRELEASETGZ="Evergreen-ILS-3.1.0a.tar.gz"
+  BUILDDIR="/home/${INSTALL_USER}/${EGRELEASE}"
+  BRANCH="$VERSION"
+  echo "installing packaged upstream release ${EGRELEASE}"
+  # download and unpack EG release
+  rm -rf ${BUILDDIR}
+  if [ ! -f "/home/${INSTALL_USER}/${EGRELEASETGZ}" ] ; then
+    suwrap "cd /home/${INSTALL_USER} && wget http://open-ils.org/downloads/${EGRELEASETGZ}" ${INSTALL_USER} || { echo "Could not download EG release tarball ${EGRELEASETGZ}" ; exit 1; }
+  fi
+  suwrap "cd /home/${INSTALL_USER} && tar xzf ${EGRELEASETGZ}" ${INSTALL_USER}
+else
+  # checkout EG source
+  if [ ! -d "${BUILDDIR}" ]
+  then
+    suwrap "cd /home/${INSTALL_USER} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka/evergreen evergreen" ${INSTALL_USER}
+  fi
+  suwrap "cd ${BUILDDIR} && git fetch origin && git checkout ${BRANCH} && git pull" ${INSTALL_USER}
 fi
-suwrap "cd ${BUILDDIR} && git fetch origin && git checkout ${BRANCH} && git pull" ${INSTALL_USER}
 
-# download and unpack EG release
-#rm -rf ${BUILDDIR}
-#suwrap "cd /home/${INSTALL_USER} && wget http://open-ils.org/downloads/${EGRELEASE}.tar.gz && tar xzf ${EGRELEASE}.tar.gz" ${INSTALL_USER}
 # as root
-cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-trusty
-if [[ -n "$WEBCLIENT" ]] ; then
-  cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-trusty-developer # required for web client
+cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-xenial
+if [[ ! -n "$TARBALL" ]] ; then
+  cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-xenial-developer # required for web client
 fi
 # by default, CPAN needs some manual input at this point; you can just accept all defaults
  
 # web client
-if [[ -n "$WEBCLIENT" ]] ; then
+if [[ ! -n "$TARBALL" && ! -n "$SKIPWEBCLIENT" ]] ; then
   if [[ -n "$USEBUNDLE" ]] ; then
     # use bundled web client dependencies from upstream
     if [ ! -d "/home/${INSTALL_USER}/web-client-deps" ] ; then
@@ -82,13 +93,15 @@ if [[ -n "$WEBCLIENT" ]] ; then
     # install dependencies
     cd ${BUILDDIR}/Open-ILS/web/js/ui/default/staff/
     suwrap "npm install" ${INSTALL_USER}
-    suwrap "bower install" ${INSTALL_USER}
+    suwrap "npm run build-prod && npm run test" ${INSTALL_USER} || { echo 'Could not install files for AngularJS staff client' ; exit 1; }
+    cd ${BUILDDIR}/Open-ILS/src/eg2/
+    suwrap "npm install" ${INSTALL_USER}
+    suwrap "ng build --prod && npm run test" ${INSTALL_USER} || { echo 'Could not install files for Angular staff client' ; exit 1; }
   fi
-  suwrap "grunt all" ${INSTALL_USER} || { echo 'Could not install files for web-based staff client' ; exit 1; }
 fi
 
 # as INSTALL_USER
-suwrap "cd ${BUILDDIR} && autoreconf -i" ${INSTALL_USER} # not required for release versions
+[ ! -n "$TARBALL" ] && suwrap "cd ${BUILDDIR} && autoreconf -i" ${INSTALL_USER} # not required for release versions
 suwrap "PATH=${INSTALLDIR}/bin:\$PATH cd ${BUILDDIR} && PATH=${INSTALLDIR}/bin:\$PATH ./configure -C --prefix=${INSTALLDIR} --sysconfdir=${INSTALLDIR}/conf --with-opensrf-headers=${INSTALLDIR}/include/ --with-opensrf-libs=${INSTALLDIR}/lib/" ${INSTALL_USER}
 suwrap "cd ${BUILDDIR} && make" ${INSTALL_USER}
 suwrap "cd ${BUILDDIR}/build/i18n && make LOCALE=fr-CA install && make LOCALE=en-CA install" ${INSTALL_USER}
@@ -97,6 +110,55 @@ suwrap "cd ${BUILDDIR}/build/i18n && make LOCALE=fr-CA install && make LOCALE=en
 cd ${BUILDDIR} && make STAFF_CLIENT_VERSION=${VERSION} STAFF_CLIENT_STAMP_ID=${STAMP_ID} install
 mv ${INSTALLDIR}/var/web/reports/fm_IDL.xml ${INSTALLDIR}/var/web/reports/fm_IDL.xml.orig && cp ${INSTALLDIR}/conf/fm_IDL.xml ${INSTALLDIR}/var/web/reports/
  
+# setup start page
+if [ ! -d "${INSTALLDIR}/var/web/news" ]
+then
+  mkdir ${INSTALLDIR}/var/web/news
+fi
+if [ ! -d "${INSTALLDIR}/var/web/news/media" ]
+then
+  mkdir ${INSTALLDIR}/var/web/news/media
+fi
+NEWSFILES="index.html style.css media/logo.png media/book.png media/policy.png media/dash.png media/delete.png"
+for NEWSFILE in ${NEWSFILES}
+do
+  if [ -f "${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME}" ]
+  then
+    cp ${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME} ${INSTALLDIR}/var/web/news/${NEWSFILE}
+  fi
+done
+if [[ -n "$PROD" ]] ; then
+  if [ ! -e "${INSTALLDIR}/var/web/news/wikipull.pl" ] ; then cp ${SITKACONF}/files/${INSTALLDIR}/var/web/news/wikipull.pl/${HOSTNAME} ${INSTALLDIR}/var/web/news/wikipull.pl ; fi
+  if [ ! -e "/etc/cron.d/news" ] ; then cp ${SITKACONF}/files/etc/cron.d/news/${HOSTNAME} /etc/cron.d/news ; fi
+else
+  # nonprod server, auto-update splash page with install info
+  TODAY=`date +'%A %d %B %Y'`
+  sed -i "s|__THISHOST__|${THISHOST}|g" ${INSTALLDIR}/var/web/news/index.html
+  sed -i "s|__TODAY__|${TODAY}|g" ${INSTALLDIR}/var/web/news/index.html
+  sed -i "s|__VERSION__|${VERSION}|g" ${INSTALLDIR}/var/web/news/index.html
+  sed -i "s|__BRANCH__|${BRANCH}|g" ${INSTALLDIR}/var/web/news/index.html
+fi
+
+# setup/update test server banner
+if [[ ! -n "$PROD" ]] ; then
+  SITECONFIGS="/etc/apache2/sites-available/test-server.conf"
+  for SITECONFIG in ${SITECONFIGS} ; do
+    cp ${SITKACONF}/files/${SITECONFIG}/${HOSTNAME} ${SITECONFIG}
+    sed -i "s|__NONPROD__|${THISHOST}|g" ${SITECONFIG}
+    sed -i "s|__VERSION__|${VERSION}|g" ${SITECONFIG}
+  done
+  a2ensite test-server.conf
+fi
+
+# if we are just updating an existing EG install, we're all done!
+if [[ -n "$UPDATEONLY" ]] ; then
+    exit 0
+fi
+
+if [[ ! -n "$SKIPWEBCLIENT" ]] ; then
+    apt-get install -y nginx
+fi
+
 # Apache stuff (as root):
 APACHEFILES="/etc/apache2/mods-available/mpm_prefork.conf"
 for APACHEFILE in ${APACHEFILES}
@@ -106,6 +168,9 @@ do
 done
 cp ${BUILDDIR}/Open-ILS/examples/apache/eg_startup /etc/apache2/eg_startup
 sed -i 's/export APACHE_RUN_USER=www-data/export APACHE_RUN_USER=opensrf/' /etc/apache2/envvars
+if [ ! -d "/etc/apache2/includes" ] ; then
+  mkdir /etc/apache2/includes
+fi
 a2dismod mpm_event
 a2enmod mpm_prefork
 a2enmod headers
@@ -114,16 +179,6 @@ chown -R opensrf:opensrf /var/lock/apache2
 
 # More Apache stuff for non-production sites
 if [[ ! -n "$PROD" ]] ; then
-  if [ ! -d "/etc/apache2/includes" ] ; then
-    mkdir /etc/apache2/includes
-  fi
-  SITECONFIGS="/etc/apache2/sites-available/test-server.conf"
-  for SITECONFIG in ${SITECONFIGS} ; do
-    cp ${SITKACONF}/files/${SITECONFIG}/${HOSTNAME} ${SITECONFIG}
-    sed -i "s|__NONPROD__|${THISHOST}|g" ${SITECONFIG}
-    sed -i "s|__VERSION__|${VERSION}|g" ${SITECONFIG}
-  done
-  a2ensite test-server.conf
   a2dissite 000-default
   if [ ! -d "/etc/apache2/ssl/libraries.coop/star.catalogue.libraries.coop" ]
   then
@@ -135,9 +190,7 @@ if [[ ! -n "$PROD" ]] ; then
 fi
 
 # websockets config
-if [[ -n "$WEBCLIENT" ]] ; then
-    # use nginx proxy for websockets traffic
-    apt-get install -y nginx
+if [[ ! -n "$SKIPWEBCLIENT" ]] ; then
     cp -b ${SITKACONF}/files/etc/nginx/sites-available/osrf-ws-http-proxy/${HOSTNAME} /etc/nginx/sites-available/osrf-ws-http-proxy
     ln -s /etc/nginx/sites-available/osrf-ws-http-proxy /etc/nginx/sites-enabled/osrf-ws-http-proxy
     rm /etc/nginx/sites-enabled/default
@@ -147,28 +200,6 @@ if [[ -n "$WEBCLIENT" ]] ; then
         # NOTE: this should be unnecessary if we installed OpenSRF with ./configure --with-websockets-port=443
         sed -i 's/var WEBSOCKET_PORT_SSL = 7682;/var WEBSOCKET_PORT_SSL = 443;/g' ${INSTALLDIR}/lib/javascript/$WSJSFILE
     done
-    # apache2-websockets
-    if [[ ! -n "$PROD" ]] ; then
-        if [ ! -d "/etc/apache2-websockets/ssl" ] ; then
-            cd /etc/apache2-websockets/ && ln -s /etc/apache2/ssl
-        fi
-    fi
-    if [ ! -d "/etc/apache2-websockets/includes" ] ; then
-        mkdir /etc/apache2-websockets/includes
-    fi
-    for WSINCLUDE in `ls /etc/apache2/includes` ; do
-        ln -s /etc/apache2/includes/${WSINCLUDE} /etc/apache2-websockets/includes/
-    done
-    for WSSITE in `ls /etc/apache2/sites-available` ; do
-        ln -s /etc/apache2/sites-available/${WSSITE} /etc/apache2-websockets/sites-available/
-    done
-    for WSSITEENABLED in `ls /etc/apache2/sites-enabled` ; do
-        ln -s /etc/apache2-websockets/sites-available/${WSSITEENABLED} /etc/apache2-websockets/sites-enabled/
-    done
-    if [[ -d "/etc/apache2-websockets/ssl" ]] ; then
-        rm -rf /etc/apache2-websockets/ssl
-    fi
-    cd /etc/apache2-websockets && ln -s /etc/apache2/ssl
 fi
 
 # install default crontab, if specified
@@ -178,6 +209,11 @@ if [[ -c "$CRONTAB" ]]; then
   fi
 fi
 
+# LDAP config
+if ! `diff ${SITKACONF}/files/etc/ldap/ldap.conf/${HOSTNAME} /etc/ldap/ldap.conf >/dev/null` ; then
+    cp -b --suffix=.`date +%Y-%m-%d-%H%M%S` ${SITKACONF}/files/etc/ldap/ldap.conf/${HOSTNAME} /etc/ldap/ldap.conf
+fi
+
 # set up log rotation
 if [[ ! -n "$PROD" ]] ; then
   if [ ! -f "/etc/logrotate.d/evergreen" ]
@@ -186,6 +222,17 @@ if [[ ! -n "$PROD" ]] ; then
   fi
 fi
 
+# remote logging (prod only)
+if [[ -n "$PROD" ]] ; then
+  apt-get install syslog-ng
+  cp ${SITKACONF}/files/etc/syslog-ng/syslog-ng.conf/${HOSTNAME} /etc/syslog-ng/syslog-ng.conf
+  cp ${SITKACONF}/files/etc/syslog-ng/conf.d/sitka.conf/${HOSTNAME} /etc/syslog-ng/conf.d/sitka.conf
+  systemctl restart syslog-ng.service
+  cp ${SITKACONF}/files/usr/local/bin/eg-stats-collector-remote-log.pl /usr/local/bin/eg-stats-collector-remote-log.pl
+  cp ${SITKACONF}/files/usr/local/bin/eg-stats-keepalive.sh /usr/local/bin/eg-stats-keepalive.sh
+  cp ${SITKACONF}/files/etc/cron.d/eg-stats-keepalive/${HOSTNAME} /etc/cron.d/eg-stats-keepalive
+fi
+
 # action trigger filters (prod only)
 if [[ -n "$PROD" ]] ; then
   if [ -f "${INSTALLDIR}/conf/action_trigger_filters.json" ] ; then
@@ -200,12 +247,17 @@ OSRFCONFFILES="${INSTALLDIR}/conf/opensrf.xml ${INSTALLDIR}/conf/opensrf_core.xm
 for OSRFCONFFILE in ${OSRFCONFFILES}
 do
   mv ${OSRFCONFFILE} ${OSRFCONFFILE}.`date +%Y-%m-%d-%H%M%S`
-  cp ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME} ${OSRFCONFFILE}
+  if [[ -n "$PROD" && -f "${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME}-314" ]] ; then
+    cp ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME}-314 ${OSRFCONFFILE}
+  else
+    cp ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME} ${OSRFCONFFILE}
+  fi
   sed -i "s|__HOSTNAME__|${THISHOST}|g" ${OSRFCONFFILE}
 done
 if [ ! -f "/home/opensrf/.srfsh.xml" ]
 then
   cp ${SITKACONF}/files/home/opensrf/.srfsh.xml/${HOSTNAME} /home/opensrf/.srfsh.xml
+  sed -i "s|__HOSTNAME__|${THISHOST}|g" /home/opensrf/.srfsh.xml
 fi 
 
 # 1. install dojo
@@ -277,35 +329,9 @@ if [[ -n "$EDI" ]] ; then
   cp ${BUILDDIR}/Open-ILS/src/support-scripts/edi_pusher.pl ${INSTALLDIR}/bin
   cp ${BUILDDIR}/Open-ILS/src/support-scripts/edi_fetcher.pl ${INSTALLDIR}/bin
   cp ${SYSADMIN}/files/${INSTALLDIR}/bin/edi_per_account_fetcher.sh ${INSTALLDIR}/bin/edi_per_account_fetcher.sh
-fi
-
-# 8. setup start page
-if [ ! -d "${INSTALLDIR}/var/web/news" ]
-then
-  mkdir ${INSTALLDIR}/var/web/news
-fi
-if [ ! -d "${INSTALLDIR}/var/web/news/media" ]
-then
-  mkdir ${INSTALLDIR}/var/web/news/media
-fi
-NEWSFILES="index.html style.css media/logo.png media/book.png media/policy.png media/dash.png media/delete.png"
-for NEWSFILE in ${NEWSFILES}
-do
-  if [ -f "${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME}" ]
-  then
-    cp ${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME} ${INSTALLDIR}/var/web/news/${NEWSFILE}
-  fi
-done
-if [[ -n "$PROD" ]] ; then
-  if [ ! -e "${INSTALLDIR}/var/web/news/wikipull.pl" ] ; then cp ${SITKACONF}/files/${INSTALLDIR}/var/web/news/wikipull.pl/${HOSTNAME} ${INSTALLDIR}/var/web/news/wikipull.pl ; fi
-  if [ ! -e "/etc/cron.d/news" ] ; then cp ${SITKACONF}/files/etc/cron.d/news/${HOSTNAME} /etc/cron.d/news ; fi
-else
-  # nonprod server, auto-update splash page with install info
-  TODAY=`date +'%A %d %B %Y'`
-  sed -i "s|__THISHOST__|${THISHOST}|g" ${INSTALLDIR}/var/web/news/index.html
-  sed -i "s|__TODAY__|${TODAY}|g" ${INSTALLDIR}/var/web/news/index.html
-  sed -i "s|__VERSION__|${VERSION}|g" ${INSTALLDIR}/var/web/news/index.html
-  sed -i "s|__BRANCH__|${BRANCH}|g" ${INSTALLDIR}/var/web/news/index.html
+  # add local modifications to openils-mapper rubygem (eww, yuck, barf)
+  cp -b ${SYSADMIN}/files/var/lib/gems/2.3.0/gems/openils-mapper-0.9.9/lib/openils/mapper.rb /var/lib/gems/2.3.0/gems/openils-mapper-0.9.9/lib/openils/mapper.rb
+  cp -b ${SYSADMIN}/files/var/lib/gems/2.3.0/gems/openils-mapper-0.9.9/lib/edi/mapper.rb /var/lib/gems/2.3.0/gems/openils-mapper-0.9.9/lib/edi/mapper.rb
 fi
 
 # 8.5 offline patron list
@@ -320,15 +346,7 @@ if [ ! -e "${INSTALLDIR}/bin/update-offline-blocked-list.sh" ] ; then cp ${SITKA
 
 cp ${SITKACONF}/files${INSTALLDIR}/var/data/zips.txt/${HOSTNAME} ${INSTALLDIR}/var/data/zips.txt
 
-# install legacy OverDrive API integration
-cp -r ${SITKATOOLS}/overdrive-eg-opac/build/* ${INSTALLDIR}/var/web/js/ui/default/opac
-ODAPI_LIBS="bc mb"
-for ODAPI_LIB in ${ODAPI_LIBS} ; do
-  cp ${SITKACONF}/files/${INSTALLDIR}/var/web/js/ui/default/opac/${ODAPI_LIB}/od_config.js ${INSTALLDIR}/var/web/js/ui/default/opac/${ODAPI_LIB}/od_config.js
-done
-
-# install mobile PAC
-cd ${INSTALLDIR}/var/web/opac/extras && git clone git://git.sitka.bclibraries.ca/sitka/mobile-evergreen-opac.git mobile
+cp -b --suffix=.`date +%Y-%m-%d-%H%M%S` ${SITKACONF}/files${INSTALLDIR}/var/web/robots.txt/${HOSTNAME} ${INSTALLDIR}/var/web/robots.txt
 
 # 9. make sure opensrf owns all the stuff we just did
 echo 'managing file permissions...'
@@ -361,7 +379,4 @@ apt-get install -y libconfig-simple-perl libgit-repository-perl libdate-manip-pe
 apt-get install -y python-reportlab python-reportlab-accel unifont
 
 echo 'Evergreen is installed!'
-if [[ -n "$WEBCLIENT" ]] ; then
-  echo 'Remember to start the websockets service: /etc/init.d/apache2-websockets start'
-fi