From d4a7f3c8b7ee92ca200ca4a45831e2ee24753d7b Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Thu, 10 Oct 2013 18:43:12 -0400 Subject: [PATCH] refactored, untested --- installer/wheezy/eg_wheezy_installer.sh | 788 +++++++++++++++++--------------- 1 file changed, 425 insertions(+), 363 deletions(-) diff --git a/installer/wheezy/eg_wheezy_installer.sh b/installer/wheezy/eg_wheezy_installer.sh index 0621f6e7c..e8c21e1f3 100755 --- a/installer/wheezy/eg_wheezy_installer.sh +++ b/installer/wheezy/eg_wheezy_installer.sh @@ -14,58 +14,106 @@ # GNU General Public License for more details. # ----------------------------------------------------------------------- -date - -DOJO_VERSION='1.3.3'; - -export PATH=/openils/bin:$PATH -export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH - -# ----------------------------------------------------------------------- -# Change to suit... -# ----------------------------------------------------------------------- -# If you change the jabber password, you will need to -# edit opensrf_core.xml and srfsh.xml accordingly -JABBER_PASSWORD='password' -ADMIN_USER='admin'; -ADMIN_PASS='demo123'; -# ----------------------------------------------------------------------- - -# ----------------------------------------------------------------------- -# Handling passed arguments to the script -# ----------------------------------------------------------------------- -while getopts ayst option -do - case "${option}" - in - a) AUTOSTART=1;; - y) YES=1;; - s) SAMPLEDATA=--load-all-sample;; - t) LIVETEST=1;; - esac -done - -# ----------------------------------------------------------------------- -# force CPAN to load by installing something that should already be installed -echo _.-~= test CPAN -if [ $YES ]; then - yes | cpan Fcntl -else - cpan Fcntl -fi -echo Return Value = $? -echo End of test CPAN =~-._ - -# CPAN follow pre-reqs? -if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then -if [ $YES ]; then +function my_init { + date + init_variables + configure_cpan + build_essentials + setting_up_opensrf_env + cloning_git_repos + opensrf_prereqs + evergreen_prereqs + evergreen_db_prereqs + setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd + build_opensrf + test_opensrf_build + install_opensrf + build_evergreen + test_evergreen_build + install_evergreen + configure_database + configure_apache + if [ $AUTOSTART ]; then + start_evergreen + fi +} + +function init_variables { + echo _.-~= initializing installer + # ----------------------------------------------------------------------- + # Handling passed arguments to the script + # ----------------------------------------------------------------------- + while getopts ayst option + do + case "${option}" + in + a) AUTOSTART=1;; + y) YES=1;; + s) SAMPLEDATA=--load-all-sample;; + t) LIVETEST=1;; + esac + done + export DOJO_VERSION='1.3.3'; + export PATH=/openils/bin:$PATH + export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH + export BASE_DIR=$PWD + echo AUTOSTART=${AUTOSTART} + echo YES=${YES} + echo SAMPLEDATA=${SAMPLEDATA} + echo LIVETEST=${LIVETEST} + echo DOJO_VERSION=${DOJO_VERSION} + echo PATH=${PATH} + echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH} + echo BASE_DIR=${BASE_DIR} + # ----------------------------------------------------------------------- + # Change to suit... + # ----------------------------------------------------------------------- + # If you change the jabber password, you will need to + # edit opensrf_core.xml and srfsh.xml accordingly + export JABBER_PASSWORD='password' + export ADMIN_USER='admin'; + export ADMIN_PASS='demo123'; + # ----------------------------------------------------------------------- + # You can override these like so: + # EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh + # ----------------------------------------------------------------------- + OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git' + OPENSRF_BRANCH='master' + EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git' + EVERGREEN_BRANCH='master' + echo OPENSRF_REPO=${OPENSRF_REPO} + echo OPENSRF_BRANCH=${OPENSRF_BRANCH} + echo EVERGREEN_REPO=${EVERGREEN_REPO} + echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH} + OPENSRF_PREREQ_TARGET=debian-wheezy + EVERGREEN_PREREQ_TARGET=debian-wheezy + EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-wheezy + echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET} + echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET} + echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET} + echo End of intializing installer =~-._ +} + +function configure_cpan { + echo _.-~= configure CPAN + # ----------------------------------------------------------------------- + # force CPAN to load by installing something that should already be installed + if [ $YES ]; then + yes | cpan Fcntl + else + cpan Fcntl + fi + echo Return Value = $? + # CPAN follow pre-reqs? + if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then + if [ $YES ]; then - echo "setting cpan prerequisites_policy to follow" - echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan + echo "setting cpan prerequisites_policy to follow" + echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan -else + else - echo ' + echo ' ----------------------------------------------------------------------- The install will go faster if CPAN is configured to automatically install @@ -73,302 +121,343 @@ prerequisites. You can revert the action later with: echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan ' - while true; do - echo -n 'Automatically install prereqs? [Y/n] '; - read X; - [ "$X" == 'n' -o "$X" == "N" ] && break; - if [ "$X" == 'y' -o "$X" == 'Y' ]; then - echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan - break; - fi; - done; -fi; -fi; - -# ----------------------------------------------------------------------- - -# And they're off... -BASE_DIR=$PWD - -# Install some essential tools -echo _.-~= Installing some pre-requisites -apt-get update \ -&& apt-get -yq dist-upgrade \ -&& apt-get -yq install build-essential automake git psmisc ntp rsyslog; -echo Return Value = $? -echo End of Installing some pre-requisites =~-._ - -if [ $LIVETEST ]; then - cpan TAP::Parser::SourceHandler::pgTAP -fi; - -cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/ -ldconfig; - -# Create opensrf user and set up environment -if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then - useradd -m -s /bin/bash opensrf - echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc - echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc -fi; - -# XXX for now, fetch the debian-wheezy install target working branches and merge in master -# You can override these like so: EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh -OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git' -OPENSRF_BRANCH='master' -#EVERGREEN_REPO='git://git.evergreen-ils.org/working/Evergreen.git' -#EVERGREEN_BRANCH='collab/phasefx/qa-integration' -EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git' -EVERGREEN_BRANCH='master' -OSRF_COMMAND=" -cd /home/opensrf; -git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF; -git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen; -" -rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF -echo _.-~= Cloning git repos -su - opensrf sh -c "$OSRF_COMMAND"; -echo Return Value = $? -echo End of Cloning git repos =~-._ - -# Show tips - -cd /home/opensrf/OpenSRF/ -echo 'Tip of OpenSRF:' `git log --format=oneline | head -1` -cd /home/opensrf/Evergreen/ -echo 'Tip of Evergreen:' `git log --format=oneline | head -1` - -# Install pre-reqs -mkdir -p /usr/src/evergreen; -cd /usr/src/evergreen; -echo _.-~= Installing OpenSRF pre-requisites -if [ $YES ]; then - yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install debian-wheezy -else - make -f /home/opensrf/OpenSRF/src/extras/Makefile.install debian-wheezy -fi; -echo Return Value = $? -echo End of Installing OpenSRF pre-requisites =~-._ -echo _.-~= Installing Evergreen pre-requisites -if [ $YES ]; then - yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install debian-wheezy -else - make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install debian-wheezy -fi; -echo Return Value = $? -echo End of Installing Evergreen pre-requisites =~-._ -echo _.-~= Installing Evergreen database pre-requisites -if [ $YES ]; then - yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install postgres-server-debian-wheezy -else - make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install postgres-server-debian-wheezy -fi; -echo Return Value = $? -echo End of Installing Evergreen database pre-requisites =~-._ - -# Configure rsyslog and restart -cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf -/etc/init.d/rsyslog restart - - -# Patch Ejabberd and register users -if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then - cd /etc/ejabberd/ - /etc/init.d/ejabberd stop; - killall beam epmd; # just in case - cp ejabberd.cfg /root/ejabberd.cfg.orig - patch -p0 < $BASE_DIR/ejabberd.EG.patch - chown ejabberd:ejabberd ejabberd.cfg - /etc/init.d/ejabberd start - sleep 2; - ejabberdctl register router private.localhost $JABBER_PASSWORD - ejabberdctl register opensrf private.localhost $JABBER_PASSWORD - ejabberdctl register router public.localhost $JABBER_PASSWORD - ejabberdctl register opensrf public.localhost $JABBER_PASSWORD -fi; - - - -# Build and install OpenSRF -OSRF_COMMAND=' -cd /home/opensrf/OpenSRF; -autoreconf -i; -./configure --prefix=/openils --sysconfdir=/openils/conf; -make;' - -echo _.-~= Building OpenSRF -su - opensrf sh -c "$OSRF_COMMAND" -echo Return Value = $? -echo End of Building OpenSRF =~-._ -cd /home/opensrf/OpenSRF; -echo _.-~= Running OpenSRF build tests -make check -echo Return Value = $? -echo End of OpenSRF build tests =~-._ -echo _.-~= Installing OpenSRF -make install -echo Return Value = $? -echo End of Installing OpenSRF =~-._ - -# Build and install the ILS -OSRF_COMMAND=' -export PATH=/openils/bin:$PATH -cd /home/opensrf/Evergreen; -autoreconf -i; -./configure --prefix=/openils --sysconfdir=/openils/conf; -make; -' - -echo _.-~= Building Evergreen -su - opensrf sh -c "$OSRF_COMMAND" -echo Return Value = $? -echo End of Building Evergreen =~-._ -cd /home/opensrf/Evergreen -echo _.-~= Running Evergreen build tests -make check -echo Return Value = $? -echo End of Evergreen build tests =~-._ - -echo _.-~= Installing Evergreen -make install -echo Return Value = $? - -cp /openils/conf/opensrf.xml.example /openils/conf/opensrf.xml -cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml - -# fetch and install Dojo -cd /tmp; -wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz"; -tar -zxf dojo-release-$DOJO_VERSION.tar.gz; -cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/; - -# give it all to opensrf -chown -R opensrf:opensrf /openils - -# copy srfsh config into place -cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml; -chown opensrf:opensrf /home/opensrf/.srfsh.xml; - -if [ $YES ]; then - echo "Using password evergreen for the evergreen database user." - echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;' -else - echo -e "\n\nPlease enter a password for the evergreen database user.\n If you do not want to edit configs, use \"evergreen\"\n" - su - postgres sh -c 'createuser -P -s evergreen;' -fi; - -# Apply the DB schema -cd /home/opensrf/Evergreen -perl Open-ILS/src/support-scripts/eg_db_config \ - --create-database \ - --create-schema \ - --create-offline \ - --update-config $SAMPLEDATA \ - --service all \ - --user evergreen \ - --password evergreen \ - --hostname localhost \ - --database evergreen \ - --admin-user $ADMIN_USER \ - --admin-pass $ADMIN_PASS; -echo Return Value = $? - -if [ $LIVETEST ]; then - PG_CMD=" - git clone --depth 0 https://github.com/theory/pgtap.git \ - && cd pgtap \ - && make \ - && make installcheck + while true; do + echo -n 'Automatically install prereqs? [Y/n] '; + read X; + [ "$X" == 'n' -o "$X" == "N" ] && break; + if [ "$X" == 'y' -o "$X" == 'Y' ]; then + echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan + break; + fi; + done; + fi; + fi; + echo End of configure CPAN =~-._ +} + +function build_essentials { + echo _.-~= Installing some build essentials + # Install some essential tools + apt-get update \ + && apt-get -yq dist-upgrade \ + && apt-get -yq install build-essential automake git psmisc ntp rsyslog; + echo Return Value = $? + + if [ $LIVETEST ]; then + cpan TAP::Parser::SourceHandler::pgTAP + echo Return Value = $? + fi; + echo End of Installing some build essentials =~-._ +} + +function setting_up_opensrf_env { + echo _.-~= creating opensrf user and environment + # Create opensrf user and set up environment + if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then + useradd -m -s /bin/bash opensrf + echo Return Value = $? + echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc + echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc + fi; + echo end of creating opensrf user and environment =~-._ +} + +function cloning_git_repos { + echo _.-~= cloning git repositories + OSRF_COMMAND=" + cd /home/opensrf; + git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF; + git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen; " - su - postgres -c "$PG_CMD" - cd /var/lib/postgresql/pgtap \ - && make install; - echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen" -fi; - -# Copy apache configs into place and create SSL cert -cd /home/opensrf/Evergreen/ -cp Open-ILS/examples/apache/eg.conf /etc/apache2/sites-available/ -cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/ -cp Open-ILS/examples/apache/eg_startup /etc/apache2/ - -mkdir -p /etc/apache2/ssl; -if [ ! -f /etc/apache2/ssl/server.key ] ; then - echo -e "\n\nConfiguring a new temporary SSL certificate....\n"; + rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF + su - opensrf sh -c "$OSRF_COMMAND"; + echo Return Value = $? + + # Show tips + cd /home/opensrf/OpenSRF/ + echo 'Tip of OpenSRF:' `git log --format=oneline | head -1` + cd /home/opensrf/Evergreen/ + echo 'Tip of Evergreen:' `git log --format=oneline | head -1` + + echo End of cloning git repositories =~-._ +} + +function opensrf_prereqs { + echo _.-~= Installing OpenSRF pre-requisites + # Install pre-reqs + mkdir -p /usr/src/evergreen; + cd /usr/src/evergreen; if [ $YES ]; then - yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key + yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET} else - openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key + make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET} fi; -else - echo -e "\nkeeping existing ssl/server.key file\n"; -fi - -a2enmod ssl -a2enmod rewrite -a2enmod expires -a2dissite 000-default -a2ensite eg.conf - -if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then + echo Return Value = $? + echo End of Installing OpenSRF pre-requisites =~-._ +} +function evergreen_prereqs { + echo _.-~= Installing Evergreen pre-requisites if [ $YES ]; then - echo 'Adding public.localhost and private.localhost to /etc/hosts' - echo '127.0.1.2 public.localhost public' >> /etc/hosts - echo '127.0.1.3 private.localhost private' >> /etc/hosts + yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET} else - - cat <> /etc/hosts + echo '127.0.1.3 private.localhost private' >> /etc/hosts + else + + cat <