adding evergreen upgrade script
authorChris Sharp <csharp@georgialibraries.org>
Tue, 10 Nov 2020 23:10:45 +0000 (18:10 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Tue, 10 Nov 2020 23:10:45 +0000 (18:10 -0500)
install-eg/update_eg.sh [new file with mode: 0755]

diff --git a/install-eg/update_eg.sh b/install-eg/update_eg.sh
new file mode 100755 (executable)
index 0000000..7f6ba12
--- /dev/null
@@ -0,0 +1,150 @@
+#!/bin/bash
+
+OSRF_GIT_URL=git://git.evergreen-ils.org/OpenSRF.git
+OSRF_GIT_BRANCH=master
+EG_GIT_URL=git://git.evergreen-ils.org/Evergreen.git
+EG_GIT_BRANCH=master
+DB_USER=evergreen
+DB_PASS=evergreen
+DB_HOST=localhost
+DB_PORT=5432
+DB_NAME=evergreen
+ADMIN_USER=admin
+ADMIN_PASS=demo123
+SCREEN_PID=$(screen -ls eg-build | grep eg-build | awk '{print $1}' | awk -F'.' '{print $1}')
+OSRF_REPODIR=$(echo $OSRF_GIT_URL | awk -F/ '{print $NF}' | sed -e 's/.git//')
+EG_REPODIR=$(echo $EG_GIT_URL | awk -F/ '{print $NF}' | sed -e 's/.git//')
+DISTRONAME="$(lsb_release -si | tr [:upper:] [:lower:])-$(lsb_release -sc | tr [:upper:] [:lower:])"
+
+Usage () {
+       echo "$0 [-m] [-o] [-h]"
+       echo "-m install Evergreen Master"
+       echo "-o also install OpenSRF"
+       echo "-h show this message"
+       echo
+}
+
+
+while getopts moh OPTIONS
+do  case "$OPTIONS" in
+    m)  MASTER="1";;
+    o)  INSTALL_OSRF="1";;
+    h)  Usage ; exit 1;;
+    [?])    Usage ; exit 2;;
+    esac
+done
+
+
+#stop opensrf
+StopOpenSRF () {
+systemctl stop opensrf
+}
+
+#install opensrf
+CreateOsrfUser () {
+if [ ! $(grep opensrf /etc/passwd) ]; then
+    useradd -m -s /bin/bash opensrf
+fi
+}
+
+UpdateOsrfGit () {
+if [ ! -e /home/opensrf/$OSRF_REPODIR ]; then
+    su - opensrf -c "git clone $OSRF_GIT_URL"
+fi
+su - opensrf -c "cd $OSRF_REPODIR && git checkout $OSRF_GIT_BRANCH"
+cd /home/opensrf/$OSRF_REPODIR
+git pull
+}
+
+InstallOpenSRF () {
+cd /home/opensrf/$OSRF_REPODIR
+apt update
+make -f src/extras/Makefile.install $DISTRONAME
+su - opensrf -c "cd $OSRF_REPODIR && autoreconf -i && ./configure --prefix=/openils --sysconfdir=/openils/conf --with-websockets-port=443 && make"
+make install
+chown -R opensrf:opensrf /openils
+}
+
+#install evergreen
+UpdateEgGit () {
+if [ ! -e /home/opensrf/$OSRF_REPODIR ]; then
+    su - opensrf -c "git clone $EG_GIT_URL"
+fi
+su - opensrf -c "cd $EG_REPODIR && git checkout $EG_GIT_BRANCH"
+cd /home/opensrf/$EG_REPODIR
+git pull
+}
+
+InstallEG () {
+cd /home/opensrf/$EG_REPODIR
+make -f Open-ILS/src/extras/Makefile.install $DISTRONAME
+make -f Open-ILS/src/extras/Makefile.install ${DISTRONAME}-developer
+su - opensrf -c "cd $EG_REPODIR/Open-ILS/web/js/ui/default/staff && npm install && npm run build-prod && CHROME_BIN=/usr/bin/chromium-browser npm run test"
+# install bootstrap deps
+su - opensrf -c "cd $EG_REPODIR/Open-ILS/web/opac/deps && npm install"
+if [ ! -z $SCREEN_PID ]; then
+       kill $SCREEN_PID
+fi
+# remove symlink to eg2
+rm /openils/var/web/eg2
+su - opensrf -c "cd $EG_REPODIR && PATH=$PATH:/openils/bin autoreconf -i && PATH=$PATH:/openils/bin ./configure --prefix=/openils --sysconfdir=/openils/conf && make"
+make install
+# re-create symlink to eg2
+rm -rf /openils/var/web/eg2 && ln -s /home/opensrf/Evergreen/Open-ILS/web/eg2 /openils/var/web/eg2
+screen -d -m -S eg-build su - opensrf -c "cd $EG_REPODIR/Open-ILS/src/eg2 && npm install && ng build --watch"
+chown -R opensrf:opensrf /openils
+}
+
+#replace database
+InstallDB () {
+cd /home/opensrf/$EG_REPODIR && \
+ perl Open-ILS/src/support-scripts/eg_db_config \
+--update-config \
+--service all \
+--create-database \
+--create-schema \
+--create-offline \
+--user $DB_USER \
+--password $DB_PASS \
+--hostname $DB_HOST \
+--port $DB_PORT \
+--database $DB_NAME \
+--admin-user $ADMIN_USER \
+--admin-pass $ADMIN_PASS \
+--load-all-sample
+}
+
+#start it all back up
+StartOpenSRF () {
+systemctl start opensrf
+systemctl restart apache2 nginx websocketd-osrf
+}
+
+InstallMaster () {
+StopOpenSRF
+if [ ! -z $INSTALL_OSRF ]; then
+       CreateOsrfUser
+       UpdateOsrfGit
+       InstallOpenSRF
+fi
+UpdateEgGit
+InstallEG
+InstallDB
+StartOpenSRF
+}
+
+Install () {
+StopOpenSRF
+if [ ! -z $INSTALL_OSRF ]; then
+       InstallOpenSRF
+fi
+InstallEG
+InstallDB
+StartOpenSRF
+}
+
+if [ -z $MASTER ]; then
+       Install
+else
+       InstallMaster
+fi