From e795709e7b9b752ff46870dc54ab7a8aced5aebf Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 3 Mar 2015 14:49:14 -0500 Subject: [PATCH] JBAS-415 brick updater additions * If no branch/tag/pull options are specified, install whatever code is present in the repository * Toggle -c. No configure/clean is run by default. * If no client build ID is specified, use the current date * Run build commands as the owner of the current directory, not necessarily as opensrf. * Move all post-install steps into the main script to finalize support for running the script as a non-opensr user. * Adds support for a code series (-i) parameter for symlinking the staff client to support persistent intra-series links. * eg-updater.sh -x now builds a Windows staff client. Signed-off-by: Bill Erickson --- KCLS/misc-scripts/eg-updater.sh | 220 ++++++++++++++++++++++++++------ KCLS/misc-scripts/post-install-tasks.sh | 71 ----------- 2 files changed, 181 insertions(+), 110 deletions(-) delete mode 100755 KCLS/misc-scripts/post-install-tasks.sh diff --git a/KCLS/misc-scripts/eg-updater.sh b/KCLS/misc-scripts/eg-updater.sh index c9edaae280..11c189c6d1 100755 --- a/KCLS/misc-scripts/eg-updater.sh +++ b/KCLS/misc-scripts/eg-updater.sh @@ -8,26 +8,33 @@ set -euo pipefail # ------------------------------------------------------------------------- # constants -EVERGREEN_BASE="/home/opensrf/Evergreen" +EVERGREEN_BASE="$(pwd)" # option to override? PING_FILE="/openils/var/web/ping.txt" +XUL_DIR="/openils/var/web/xul" +XULRUNNER_VERSION="14.0.1" DETACH_SLEEP=30 -OSRF="sudo -u opensrf" +START_SLEEP=10 +CONFIGURE_OPS="--prefix=/openils --sysconfdir=/openils/conf --with-dbi=/usr/lib/x86_64-linux-gnu/dbd" +RUNNER=$(whoami) +OWNER=$(stat -c %U $EVERGREEN_BASE); +BUILDER="" +OSRF="" +GIT="git" -# run git commands from an opensrf login shell (-i) and use git -C to -# set the Evergreen checkout directory, since -i drops you into $HOME. -GIT="$OSRF -i git -C $EVERGREEN_BASE" # command line arguments GIT_TAG="" GIT_BRANCH="" GIT_PULL="" CLIENT_BUILD_ID="" +CLIENT_SERIES_ID="" GIT_REMOTE="kcls" SKIP_DETACH="" REATTACH="" SKIP_APACHE="" WEB_ONLY="" -SKIP_REBUILD="" +REBUILD="" +BUILD_XUL="" # if the script exits early, SUCCESS will be left as 0, # which is our sign to warn the user. @@ -71,6 +78,13 @@ function usage { Staff client build ID. If -t is used and no -s is specified, the value for -t will also be used as the build ID. + -i + The major code series (e.g. "kcls-2.4") which we are + installing. If set, a symlink to the staff client build + for the series is also created. This is useful when clients + are deployed with a series version instead of a tag version + (which would require a new client with every update). + -r Defaults to "kcls". @@ -100,6 +114,11 @@ function usage { for major upgrades. This option is ignored when a branch (-b) is used, since checking out a branch results in a 'git reset --hard', forcing configure, etc. to run anyway. + + -x + Build a XUL client and place it in the published "builds" + directory. + USAGE trap - EXIT exit; @@ -121,29 +140,41 @@ function on_exit { fi } +function set_builder { + + if [ $RUNNER != $OWNER ]; then + BUILDER="sudo -u $OWNER " + # run git commands from a login shell (-i) and use git -C to set + # the Evergreen checkout directory, since -i drops you into $HOME. + GIT="$BUILDER -i git -C $EVERGREEN_BASE" + announce "Building as user $OWNER" + fi + + if [ $RUNNER != "opensrf" ]; then + OSRF="sudo -u opensrf" + fi +} + function inspect_params { - # parameter sanity checks - if [ -z "$GIT_TAG" -a -z "$GIT_BRANCH" -a -z "$GIT_PULL" ]; then - announce "Tag, branch, or pull must be specified" - usage; + if [ -z "$CLIENT_BUILD_ID" -a -n "$GIT_TAG" ]; then + # default to using the git tag if no client build ID is provided + CLIENT_BUILD_ID="$GIT_TAG"; fi; - # default to using the git tag if no client build ID is provided - [ -z "$CLIENT_BUILD_ID" -a -n "$GIT_TAG" ] && CLIENT_BUILD_ID="$GIT_TAG"; - - # more parameter sanity checks if [ -z "$CLIENT_BUILD_ID" -a -z "$WEB_ONLY" ]; then - announce "Staff client build ID (-s) required if no tag is specified" - usage; + # if we still have no build ID, use the current date. + # other symlinks will be + CLIENT_BUILD_ID=$(date +'%FT%T') + announce "No -s specified; using $CLIENT_BUILD_ID as client build ID" fi; # checking out a branch causes a 'git reset --hard', which # means that the full build has to be done regardless, # so skip this option when GIT_BRANCH is set. - if [ -n "$GIT_BRANCH" -a -n "$SKIP_REBUILD" ]; then - announce "-c param is ignored when a branch is specified" - SKIP_REBUILD=""; + if [ -n "$GIT_BRANCH" -a -z "$REBUILD" ]; then + announce "-c param is applied by default when a branch is specified" + REBUILD="YES"; fi } @@ -172,7 +203,7 @@ function checkout_code { # local checkout is available, but not checked out. announce "Recovering existing checkout for $LOCAL" - $GIT checkout "$LOCAL" > /dev/null + $GIT checkout -f "$LOCAL" > /dev/null else announce "$LOCAL is already checked out" @@ -217,39 +248,147 @@ function deploy_web { $OSRF cp /openils/conf/fm_IDL.xml /openils/var/web/reports/ } +# ----------------------------------------------------------------------- +# 1. Create persistent links to current staff client server directory +# 2. Make staff client build directories available for easy download +# from an Evergreen brick. +# ----------------------------------------------------------------------- +function publish_staff_client_build { + cd $EVERGREEN_BASE; + + $OSRF mkdir -p $XUL_DIR/builds/ + $OSRF cp -r Open-ILS/xul/staff_client/build $XUL_DIR/builds/ + cd $XUL_DIR + + # set up links to current server files + + $OSRF rm -f server + $OSRF rm -f current + $OSRF ln -s $CLIENT_BUILD_ID current + $OSRF ln -s current/server server + + if [ -n "$CLIENT_SERIES_ID" ]; then + $OSRF rm -f $CLIENT_SERIES_ID; + $OSRF ln -s $CLIENT_BUILD_ID $CLIENT_SERIES_ID; + fi + + # create current build bundle zip file + + cd builds + $OSRF rm -r build/server # server files are not needed by installed clients + $OSRF rm -f current-client-build.zip + $OSRF zip -rq $CLIENT_BUILD_ID.zip build + $OSRF ln -s $CLIENT_BUILD_ID.zip current-client-build.zip + $OSRF rm -r build # don't need the extracted version on the server + + if [ -n "$BUILD_XUL" ]; then + build_staff_client; + fi +} + +function build_staff_client { + cd $XUL_DIR/builds/ + if [ ! -r "xulrunner-$XULRUNNER_VERSION.en-US.win32.zip" ]; then + $OSRF wget "http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/$XULRUNNER_VERSION/runtimes/xulrunner-$XULRUNNER_VERSION.en-US.win32.zip" + fi + cd $EVERGREEN_BASE/Open-ILS/xul/staff_client + + # xulrunner exe has to be in the source directory to get packaged. + # link it into place, then later remove it. + $BUILDER ln -s $XUL_DIR/builds/"xulrunner-$XULRUNNER_VERSION.en-US.win32.zip" . + $BUILDER make rigrelease + $BUILDER make STAFF_CLIENT_STAMP_ID=$CLIENT_BUILD_ID build + $BUILDER make win-client + + $OSRF mv evergreen_staff_client_setup.exe \ + $XUL_DIR/builds/evergreen-setup-$CLIENT_BUILD_ID.exe + + $BUILDER rm "xulrunner-$XULRUNNER_VERSION.en-US.win32.zip" # remove symlink + + cd $XUL_DIR/builds/ + $OSRF rm -f evergreen-setup-current.exe + $OSRF ln -s "evergreen-setup-$CLIENT_BUILD_ID.exe" \ + evergreen-setup-current.exe +} + +# copy custom files into place +function copy_custom_files { + cd $EVERGREEN_BASE; + + # web templates + $OSRF cp -r KCLS/openils/var/templates_kcls /openils/var/ + + $OSRF mkdir -p /openils/var/cgi-bin/ezproxy/ + $OSRF cp Open-ILS/examples/remoteauth.cgi /openils/var/cgi-bin/ezproxy/ + + $OSRF cp ./KCLS/utility-scripts/send-print-notices.pl /openils/bin/ + + # copy bin files which are not normally installed into place + $OSRF cp ./Open-ILS/src/support-scripts/edi_fetcher.pl /openils/bin/ + $OSRF cp ./Open-ILS/src/support-scripts/edi_pusher.pl /openils/bin/ + $OSRF cp ./Open-ILS/src/edi_translator/edi_webrick.rb /openils/bin/ + $OSRF cp ./Open-ILS/src/edi_translator/edi_webrick.bash /openils/bin/ + $OSRF cp ./Open-ILS/src/support-scripts/marc_stream_importer.pl /openils/bin/ + $OSRF cp ./Open-ILS/src/support-scripts/oils_header.pl /openils/bin/ + $OSRF cp ./Open-ILS/src/support-scripts/set_pbx_holidays.pl /openils/bin/ +} + + function deploy_code { announce "Building and installing Evergreen" - if [ -n "$SKIP_REBUILD" ]; then - # pass PATH in case 'make' forces ./configure to run. - $OSRF PATH=$PATH:/openils/bin make > /dev/null - else + # the separate incantations for $BUILDER / $OSRF are required + # becuase it's an error to preceded setting a variable with + # an empty variable. - $OSRF autoreconf -i > /dev/null - $OSRF PATH=$PATH:/openils/bin ./configure --prefix=/openils \ - --sysconfdir=/openils/conf \ - --with-dbi=/usr/lib/x86_64-linux-gnu/dbd > /dev/null - $OSRF make clean all > /dev/null + if [ -z "$REBUILD" ]; then + if [ -n "$BUILDER" ]; then + $BUILDER PATH=$PATH:/openils/bin make > /dev/null + else + PATH=$PATH:/openils/bin make > /dev/null + fi + else + if [ -n "$BUILDER" ]; then + $BUILDER autoreconf -i > /dev/null + $BUILDER PATH=$PATH:/openils/bin ./configure $CONFIGURE_OPS > /dev/null + $BUILDER make clean all > /dev/null + else + autoreconf -i > /dev/null + PATH=$PATH:/openils/bin ./configure $CONFIGURE_OPS > /dev/null + make clean all > /dev/null + fi fi sudo make STAFF_CLIENT_STAMP_ID="$CLIENT_BUILD_ID" install > /dev/null - sudo chown -R opensrf:opensrf $EVERGREEN_BASE + + # recover ownership of repo files after sudo/install + sudo chown -R $OWNER:$OWNER $EVERGREEN_BASE announce "Running post-install steps" + # opensrf always owns /openils set +e # chown returns non-zero on R/O NFS shares sudo chown -R opensrf:opensrf /openils > /dev/null 2>&1; set -e - $OSRF KCLS/misc-scripts/post-install-tasks.sh -b kcls-2.4.001 > /dev/null + publish_staff_client_build; - $OSRF PATH=$PATH:/openils/bin \ - /openils/bin/osrf_control --localhost --start-all > /dev/null + copy_custom_files; + + if [ -n "$OSRF" ]; then + + $OSRF PATH=$PATH:/openils/bin \ + /openils/bin/osrf_control --localhost --start-all > /dev/null + else + + PATH=$PATH:/openils/bin \ + /openils/bin/osrf_control --localhost --start-all > /dev/null + fi # give services a chance to start up - announce "Giving services a few seconds to start up" - sleep 5; + announce "Giving services $START_SLEEP seconds to start up" + sleep $START_SLEEP; announce "Running autogen" $OSRF /openils/bin/autogen.sh > /dev/null @@ -259,22 +398,25 @@ function deploy_code { trap on_exit EXIT; -while getopts "t:b:r:s:pdanwch" opt; do +while getopts "t:b:r:s:i:pdanwchx" opt; do case $opt in t) GIT_TAG="$OPTARG";; b) GIT_BRANCH="$OPTARG";; r) GIT_REMOTE="$OPTARG";; s) CLIENT_BUILD_ID="$OPTARG";; + i) CLIENT_SERIES_ID="$OPTARG";; p) GIT_PULL="YES";; d) SKIP_DETACH="YES";; a) REATTACH="YES";; n) SKIP_APACHE="YES";; w) WEB_ONLY="YES";; - c) SKIP_REBUILD="YES";; + c) REBUILD="YES";; + x) BUILD_XUL="YES";; h|*) usage; esac done; +set_builder; inspect_params; if [ -z "$SKIP_DETACH" ]; then @@ -320,8 +462,8 @@ else fi if [ -n "$REATTACH" -a -z "$SKIP_DETACH" ]; then - announce "Reattaching brick (after a short sleep)" - sleep 5; + announce "Reattaching brick after $START_SLEEP seconds" + sleep $START_SLEEP; $OSRF mv $PING_FILE- $PING_FILE fi; diff --git a/KCLS/misc-scripts/post-install-tasks.sh b/KCLS/misc-scripts/post-install-tasks.sh deleted file mode 100755 index 0458d6b186..0000000000 --- a/KCLS/misc-scripts/post-install-tasks.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash -# ----------------------------------------------------------------------- -# Author: Bill Erickson -# -set -euo pipefail -BUILD_ID='' -XUL_DIR=/openils/var/web/xul - -while getopts "b:" opt; do - case $opt in - b) BUILD_ID="$OPTARG" - esac -done; - -[ -z "$BUILD_ID" ] && echo "-b required!" && exit; -[ "$(id -un)" != "opensrf" ] && echo "Run as opensrf!" && exit; - - - -# ----------------------------------------------------------------------- -# 1. Create persistent links to current staff client server directory -# 2. Make staff client build directories available for easy download -# from an Evergreen brick. -# ----------------------------------------------------------------------- -function publish_staff_client_build { - - cd /home/opensrf/Evergreen/ - mkdir -p $XUL_DIR/builds/ - cp -r Open-ILS/xul/staff_client/build $XUL_DIR/builds/ - cd $XUL_DIR - - # set up links to current server files - - rm -f server - rm -f current - ln -s $BUILD_ID current - ln -s current/server server - - # create current build bundle zip file - - cd builds - rm -r build/server # server files are not needed by installed clients - rm -f current-client-build.zip - zip -rq $BUILD_ID.zip build - ln -s $BUILD_ID.zip current-client-build.zip - rm -r build # don't need the extracted version on the server -} - -# copy custom files into place -function copy_custom_files { - cd /home/opensrf/Evergreen/ - # web templates - cp -r KCLS/openils/var/templates_kcls /openils/var/ - - mkdir -p /openils/var/cgi-bin/ezproxy/ - cp Open-ILS/examples/remoteauth.cgi /openils/var/cgi-bin/ezproxy/ - - cp ./KCLS/utility-scripts/send-print-notices.pl /openils/bin/ - - # copy bin files which are not normally installed into place - cp ./Open-ILS/src/support-scripts/edi_fetcher.pl /openils/bin/ - cp ./Open-ILS/src/support-scripts/edi_pusher.pl /openils/bin/ - cp ./Open-ILS/src/edi_translator/edi_webrick.rb /openils/bin/ - cp ./Open-ILS/src/edi_translator/edi_webrick.bash /openils/bin/ - cp ./Open-ILS/src/support-scripts/marc_stream_importer.pl /openils/bin/ - cp ./Open-ILS/src/support-scripts/oils_header.pl /openils/bin/ - cp ./Open-ILS/src/support-scripts/set_pbx_holidays.pl /openils/bin/ -} - -publish_staff_client_build; -copy_custom_files; -- 2.11.0