From: Bill Erickson Date: Fri, 6 Feb 2015 19:13:37 +0000 (-0500) Subject: JBAS-449 improve script dir names X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d95624f11112534f8c916d60f3e6e124c2b4b282;p=working%2FEvergreen.git JBAS-449 improve script dir names Better clarify the purpose of each script directory. Signed-off-by: Bill Erickson --- diff --git a/KCLS/admin-scripts/eg-updater.sh b/KCLS/admin-scripts/eg-updater.sh new file mode 100755 index 0000000000..3ff13ba1ad --- /dev/null +++ b/KCLS/admin-scripts/eg-updater.sh @@ -0,0 +1,495 @@ +#!/bin/bash +set -euo pipefail +# ------------------------------------------------------------------------- +# Author: Bill Erickson +# Date: 2015-01-21 +# +# Updates and deploys Evergreen code on an Ubuntu-based KCLS Evergreen server. +# ------------------------------------------------------------------------- + +# constants +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 +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" + + +# 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="" +REBUILD="" +BUILD_XUL="" + +# if the script exits early, SUCCESS will be left as 0, +# which is our sign to warn the user. +SUCCESS=0 + +function usage { + + cat < + Check out a copy of the specified git tag. + + -b + Check out (or use an existing checkout) of the specified + git branch. Beware this action is destructive. It discards + all local modifications to files in the checked out branch. + + -s + Server-side staff client files will be stored in this + directory on the server. Typically, this should match the + version of the code to be installed. If -t is used and no + -s is specified, the value for -t will be used as the server + stamp ID. E.g. kcls-2.4.001 + + -i + This is the ID set on staff client builds and defines which + directory the staff client will request files from. This + will be a symlink to the directory set by -s. This allows + clients of different versions to access the same set of + server files. E.g. kcls-2.4 + + -r + Defaults to "kcls". + + -d + Do NOT detach the server as one normally does for a brick. + This is useful for development servers. The default is + to always detach. + + -a + Automatically reattach the brick after the update. This is + useful if there is no desire to manually test the brick + after the update. The default is to leave detached. + This is ignored if -d is specified. + + -n + Do not stop/start Apache. This is useful for non-brick + servers, like SIP, etc. servers. + + -w + Update web files only. Instead of running the full make / + install dance, directly copy web files into place. This + is ideal for rapid UI development. + + -c + Skip the autoreconf, configure, and 'make clean' steps + when building Evergreen. These are generally only needed + 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; +} + +# -- utility functions -- + +function announce { + echo "$(date +'%F %T') $(hostname): $1" +} + +# called when the script exits for any reason. +# if the script exits early, warn the user. +function on_exit { + if [ $SUCCESS -ne 1 ]; then + announce "** $0 exited unexpectedly! **" + else + announce "$0 completed successfully" + 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 { + + 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; + + if [ -z "$CLIENT_BUILD_ID" -a -z "$WEB_ONLY" ]; then + # 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 -z "$REBUILD" ]; then + announce "-c param is applied by default when a branch is specified" + REBUILD="YES"; + fi +} + +function checkout_code { + LOCAL=$1 # local git target name + REMOTE=$2 # remote git target name + CURRENT=$($GIT rev-parse --abbrev-ref HEAD); + + if [ "$CURRENT" == "heads/$LOCAL" ]; then + # git rev-parse shows tags as 'heads/$tagname' + CURRENT=$LOCAL + fi + + set +e # temporarily disable exit-on-error setting + $GIT show-ref --verify --quiet "refs/heads/$LOCAL" + stat=$? + set -e + + if [ $stat -ne 0 ]; then + + # we have no local checkout for the requested target + announce "Checking out a new copy of $LOCAL" + $GIT checkout -f -b "$LOCAL" "$REMOTE" > /dev/null + + elif [ "$CURRENT" != "$LOCAL" ]; then + + # local checkout is available, but not checked out. + announce "Recovering existing checkout for $LOCAL" + $GIT checkout -f "$LOCAL" > /dev/null + + else + announce "$LOCAL is already checked out" + fi; +} + +function fetch_code { + + if [ -n "$GIT_PULL" ]; then + # 'git fetch' is unnecessary when pulling, plus it causes + # an extra password prompt when using SSH keys w/ passwords + announce "Pulling updates for $($GIT rev-parse --abbrev-ref HEAD)"; + $GIT pull > /dev/null + + elif [ -n "$GIT_TAG" ]; then + announce "Fetching Git remote $GIT_REMOTE" + $GIT fetch $GIT_REMOTE > /dev/null + announce "Checking out tag $GIT_TAG" + checkout_code "$GIT_TAG" "$GIT_TAG" + + elif [ -n "$GIT_BRANCH" ]; then + announce "Fetching Git remote $GIT_REMOTE" + $GIT fetch $GIT_REMOTE > /dev/null + announce "Checking out branch $GIT_BRANCH" + checkout_code "$GIT_BRANCH" "$GIT_REMOTE/$GIT_BRANCH" + + # discard uncommitted local changes and update + # the local checkout to match the remote. + $GIT reset --hard "$GIT_REMOTE/$GIT_BRANCH" > /dev/null + fi; +} + +# copy web-served files into place +function deploy_web { + announce "Deploying web files" + + $OSRF cp -r Open-ILS/web/* /openils/var/web/ + $OSRF cp -r Open-ILS/src/templates/* /openils/var/templates/ + $OSRF cp -r KCLS/openils/var/templates_kcls/* /openils/var/templates_kcls/ + $OSRF cp -r Open-ILS/xul/staff_client/server/* /openils/var/web/xul/server/ + $OSRF cp Open-ILS/examples/fm_IDL.xml /openils/conf/ + $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 + + STAMP_ID=$CLIENT_BUILD_ID + if [ -n "$CLIENT_SERIES_ID" ]; then + # use the series as the server stamp ID if available + STAMP_ID=$CLIENT_SERIES_ID + fi + + # 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=$STAMP_ID \ + STAFF_CLIENT_BUILD_ID="$CLIENT_BUILD_ID" \ + STAFF_CLIENT_VERSION="$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" + + # the separate incantations for $BUILDER / $OSRF are required + # becuase it's an error to preceded setting a variable with + # an empty variable. + + 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 + + # Put client server files under the build-id specific directory + # so we can track each build individually. A symlink from the + # series (if set) to the latest build is set later. + sudo make STAFF_CLIENT_STAMP_ID="$CLIENT_BUILD_ID" \ + STAFF_CLIENT_BUILD_ID="$CLIENT_BUILD_ID" \ + STAFF_CLIENT_VERSION="$CLIENT_BUILD_ID" install > /dev/null + + # 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 + + publish_staff_client_build; + + 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 $START_SLEEP seconds to start up" + sleep $START_SLEEP; + + announce "Running autogen" + $OSRF /openils/bin/autogen.sh > /dev/null +} + +# -- script starts here -- + +trap on_exit EXIT; + +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) REBUILD="YES";; + x) BUILD_XUL="YES";; + h|*) usage; + esac +done; + +set_builder; +inspect_params; + +if [ -z "$SKIP_DETACH" ]; then + + if [ ! -f $PING_FILE ]; then + announce "Detach requested, but no ping file exists at $PING_FILE" + announce "Try -d to skip the brick detach step." + exit; + fi; + + announce "Detaching brick and sleeping $DETACH_SLEEP seconds" + $OSRF mv $PING_FILE $PING_FILE- + sleep $DETACH_SLEEP +fi; + +cd $EVERGREEN_BASE; + +if [ -n "$WEB_ONLY" ]; then + # web-only updates don't require restarts. + fetch_code + deploy_web +else + + # Note the use of --fast-shutdown-all, which is faster than the + # default graceful shutdown. We don't need graceful shutdown, + # since we will not be stopping potentially active services. + announce "Stopping services" + $OSRF /openils/bin/osrf_control --localhost \ + --fast-shutdown-all > /dev/null + + if [ -z "$SKIP_APACHE" ]; then + announce "Stopping Apache" + sudo service apache2 stop > /dev/null + fi + + fetch_code; + deploy_code; + + if [ -z "$SKIP_APACHE" ]; then + announce "Starting Apache" + sudo service apache2 start > /dev/null + fi; +fi + +if [ -z "$SKIP_DETACH" ]; then + if [ -n "$REATTACH" ]; then + announce "Reattaching brick after $START_SLEEP seconds" + sleep $START_SLEEP; + $OSRF mv $PING_FILE- $PING_FILE + else + announce "Brick is still detached! Use -a to automatically re-attach" + fi +fi; + +SUCCESS=1 + +exit; + + diff --git a/KCLS/admin-scripts/linux-staff-client.sh b/KCLS/admin-scripts/linux-staff-client.sh new file mode 100755 index 0000000000..6f36a4c0e8 --- /dev/null +++ b/KCLS/admin-scripts/linux-staff-client.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# ------------------------------------------------------------------- +# Fetch and run the latest staff client build from a KCLS EG server. +# ------------------------------------------------------------------- +set -eu +SERVER="" +CLIENT_DIR="$HOME/staff_client" +XUL_BUNDLE="xulrunner-14.0.1.en-US.linux-x86_64.tar.bz2" +XUL_URL="http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/14.0.1/runtimes/$XUL_BUNDLE" + +function usage { + cat < +USAGE + exit; +} + +while getopts "s:h" opt; do + case $opt in + s) SERVER=$OPTARG;; + h) usage; + esac +done; + +[ -z "$SERVER" ] && usage; + +mkdir -p $CLIENT_DIR +cd $CLIENT_DIR + +if [ ! -d xulrunner ]; then + wget $XUL_URL + tar -jxf $XUL_BUNDLE +fi + +rm -f current-client-build.zip; +rm -rf build; + +# fetch new build +wget "http://$SERVER/xul/builds/current-client-build.zip" +unzip current-client-build.zip +cd build +../xulrunner/xulrunner-bin application.ini + diff --git a/KCLS/admin-scripts/manage-log-files.sh b/KCLS/admin-scripts/manage-log-files.sh new file mode 100755 index 0000000000..93da78d070 --- /dev/null +++ b/KCLS/admin-scripts/manage-log-files.sh @@ -0,0 +1,59 @@ +#!/bin/bash +set -eu +# Syslog server log file compressor and deleter. +# +# To future generations: this script was a lot simpler +# to implement and test than a logrotate setup. + +# Specifically, the hurdle is that logratate is designed +# to handle multiple log files in the last path component +# (e.g. /my/path/to/logfiles/*). KCLS log directory tree +# has several levels which are year, month and day. To +# fully express what this script does a lot of hardcoded +# configuration would need to be written. +# While it still technically should be possible to +# configure logrotate to do what this script achieves +# it will be really cumbersome and significantly time +# demanding. Especially, when the log directory tree +# structure needs to be modified in the future as it will +# necessitate revision of logrotate configuration that +# would need to be rewritten to account for the changes +# in the structure of the log directory tree. Not to mention +# use of underdocumented features (iliv@commandprompt.com) + +# *_AGE values are stored as days +# Example: a compress value of "3" means compress files +# last modified more than 3 days ago. +COMPRESS_AGE=3 +DELETE_AGE=365 + +function usage { + cat < -d +USAGE + exit; +} + +while getopts "d:c:h" opt; do + case $opt in + c) COMPRESS_AGE=$OPTARG;; + d) DELETE_AGE=$OPTARG;; + h) usage; + esac +done; + +# Delete all Evergreen log files that are older than DELETE_AGE +# days, except for the Apache access log and Evergreen activity log. + +/usr/bin/find /var/log/evergreen -type f -mtime +$DELETE_AGE \ + -not -name "ap_access*" -not -name "activity*" -delete + +# Compress Evergreen log files older than COMPRESS_AGE days + +/usr/bin/find /var/log/evergreen/ -type f -mtime +$COMPRESS_AGE \ + -not -name "*bz2" -exec /bin/bzip2 {} \; + +# clean up empty directories + +/usr/bin/find /var/log/evergreen/ -type d -empty -exec rmdir '{}' \; + diff --git a/KCLS/misc-scripts/eg-updater.sh b/KCLS/misc-scripts/eg-updater.sh deleted file mode 100755 index 3ff13ba1ad..0000000000 --- a/KCLS/misc-scripts/eg-updater.sh +++ /dev/null @@ -1,495 +0,0 @@ -#!/bin/bash -set -euo pipefail -# ------------------------------------------------------------------------- -# Author: Bill Erickson -# Date: 2015-01-21 -# -# Updates and deploys Evergreen code on an Ubuntu-based KCLS Evergreen server. -# ------------------------------------------------------------------------- - -# constants -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 -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" - - -# 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="" -REBUILD="" -BUILD_XUL="" - -# if the script exits early, SUCCESS will be left as 0, -# which is our sign to warn the user. -SUCCESS=0 - -function usage { - - cat < - Check out a copy of the specified git tag. - - -b - Check out (or use an existing checkout) of the specified - git branch. Beware this action is destructive. It discards - all local modifications to files in the checked out branch. - - -s - Server-side staff client files will be stored in this - directory on the server. Typically, this should match the - version of the code to be installed. If -t is used and no - -s is specified, the value for -t will be used as the server - stamp ID. E.g. kcls-2.4.001 - - -i - This is the ID set on staff client builds and defines which - directory the staff client will request files from. This - will be a symlink to the directory set by -s. This allows - clients of different versions to access the same set of - server files. E.g. kcls-2.4 - - -r - Defaults to "kcls". - - -d - Do NOT detach the server as one normally does for a brick. - This is useful for development servers. The default is - to always detach. - - -a - Automatically reattach the brick after the update. This is - useful if there is no desire to manually test the brick - after the update. The default is to leave detached. - This is ignored if -d is specified. - - -n - Do not stop/start Apache. This is useful for non-brick - servers, like SIP, etc. servers. - - -w - Update web files only. Instead of running the full make / - install dance, directly copy web files into place. This - is ideal for rapid UI development. - - -c - Skip the autoreconf, configure, and 'make clean' steps - when building Evergreen. These are generally only needed - 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; -} - -# -- utility functions -- - -function announce { - echo "$(date +'%F %T') $(hostname): $1" -} - -# called when the script exits for any reason. -# if the script exits early, warn the user. -function on_exit { - if [ $SUCCESS -ne 1 ]; then - announce "** $0 exited unexpectedly! **" - else - announce "$0 completed successfully" - 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 { - - 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; - - if [ -z "$CLIENT_BUILD_ID" -a -z "$WEB_ONLY" ]; then - # 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 -z "$REBUILD" ]; then - announce "-c param is applied by default when a branch is specified" - REBUILD="YES"; - fi -} - -function checkout_code { - LOCAL=$1 # local git target name - REMOTE=$2 # remote git target name - CURRENT=$($GIT rev-parse --abbrev-ref HEAD); - - if [ "$CURRENT" == "heads/$LOCAL" ]; then - # git rev-parse shows tags as 'heads/$tagname' - CURRENT=$LOCAL - fi - - set +e # temporarily disable exit-on-error setting - $GIT show-ref --verify --quiet "refs/heads/$LOCAL" - stat=$? - set -e - - if [ $stat -ne 0 ]; then - - # we have no local checkout for the requested target - announce "Checking out a new copy of $LOCAL" - $GIT checkout -f -b "$LOCAL" "$REMOTE" > /dev/null - - elif [ "$CURRENT" != "$LOCAL" ]; then - - # local checkout is available, but not checked out. - announce "Recovering existing checkout for $LOCAL" - $GIT checkout -f "$LOCAL" > /dev/null - - else - announce "$LOCAL is already checked out" - fi; -} - -function fetch_code { - - if [ -n "$GIT_PULL" ]; then - # 'git fetch' is unnecessary when pulling, plus it causes - # an extra password prompt when using SSH keys w/ passwords - announce "Pulling updates for $($GIT rev-parse --abbrev-ref HEAD)"; - $GIT pull > /dev/null - - elif [ -n "$GIT_TAG" ]; then - announce "Fetching Git remote $GIT_REMOTE" - $GIT fetch $GIT_REMOTE > /dev/null - announce "Checking out tag $GIT_TAG" - checkout_code "$GIT_TAG" "$GIT_TAG" - - elif [ -n "$GIT_BRANCH" ]; then - announce "Fetching Git remote $GIT_REMOTE" - $GIT fetch $GIT_REMOTE > /dev/null - announce "Checking out branch $GIT_BRANCH" - checkout_code "$GIT_BRANCH" "$GIT_REMOTE/$GIT_BRANCH" - - # discard uncommitted local changes and update - # the local checkout to match the remote. - $GIT reset --hard "$GIT_REMOTE/$GIT_BRANCH" > /dev/null - fi; -} - -# copy web-served files into place -function deploy_web { - announce "Deploying web files" - - $OSRF cp -r Open-ILS/web/* /openils/var/web/ - $OSRF cp -r Open-ILS/src/templates/* /openils/var/templates/ - $OSRF cp -r KCLS/openils/var/templates_kcls/* /openils/var/templates_kcls/ - $OSRF cp -r Open-ILS/xul/staff_client/server/* /openils/var/web/xul/server/ - $OSRF cp Open-ILS/examples/fm_IDL.xml /openils/conf/ - $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 - - STAMP_ID=$CLIENT_BUILD_ID - if [ -n "$CLIENT_SERIES_ID" ]; then - # use the series as the server stamp ID if available - STAMP_ID=$CLIENT_SERIES_ID - fi - - # 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=$STAMP_ID \ - STAFF_CLIENT_BUILD_ID="$CLIENT_BUILD_ID" \ - STAFF_CLIENT_VERSION="$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" - - # the separate incantations for $BUILDER / $OSRF are required - # becuase it's an error to preceded setting a variable with - # an empty variable. - - 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 - - # Put client server files under the build-id specific directory - # so we can track each build individually. A symlink from the - # series (if set) to the latest build is set later. - sudo make STAFF_CLIENT_STAMP_ID="$CLIENT_BUILD_ID" \ - STAFF_CLIENT_BUILD_ID="$CLIENT_BUILD_ID" \ - STAFF_CLIENT_VERSION="$CLIENT_BUILD_ID" install > /dev/null - - # 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 - - publish_staff_client_build; - - 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 $START_SLEEP seconds to start up" - sleep $START_SLEEP; - - announce "Running autogen" - $OSRF /openils/bin/autogen.sh > /dev/null -} - -# -- script starts here -- - -trap on_exit EXIT; - -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) REBUILD="YES";; - x) BUILD_XUL="YES";; - h|*) usage; - esac -done; - -set_builder; -inspect_params; - -if [ -z "$SKIP_DETACH" ]; then - - if [ ! -f $PING_FILE ]; then - announce "Detach requested, but no ping file exists at $PING_FILE" - announce "Try -d to skip the brick detach step." - exit; - fi; - - announce "Detaching brick and sleeping $DETACH_SLEEP seconds" - $OSRF mv $PING_FILE $PING_FILE- - sleep $DETACH_SLEEP -fi; - -cd $EVERGREEN_BASE; - -if [ -n "$WEB_ONLY" ]; then - # web-only updates don't require restarts. - fetch_code - deploy_web -else - - # Note the use of --fast-shutdown-all, which is faster than the - # default graceful shutdown. We don't need graceful shutdown, - # since we will not be stopping potentially active services. - announce "Stopping services" - $OSRF /openils/bin/osrf_control --localhost \ - --fast-shutdown-all > /dev/null - - if [ -z "$SKIP_APACHE" ]; then - announce "Stopping Apache" - sudo service apache2 stop > /dev/null - fi - - fetch_code; - deploy_code; - - if [ -z "$SKIP_APACHE" ]; then - announce "Starting Apache" - sudo service apache2 start > /dev/null - fi; -fi - -if [ -z "$SKIP_DETACH" ]; then - if [ -n "$REATTACH" ]; then - announce "Reattaching brick after $START_SLEEP seconds" - sleep $START_SLEEP; - $OSRF mv $PING_FILE- $PING_FILE - else - announce "Brick is still detached! Use -a to automatically re-attach" - fi -fi; - -SUCCESS=1 - -exit; - - diff --git a/KCLS/misc-scripts/linux-staff-client.sh b/KCLS/misc-scripts/linux-staff-client.sh deleted file mode 100755 index 6f36a4c0e8..0000000000 --- a/KCLS/misc-scripts/linux-staff-client.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -# ------------------------------------------------------------------- -# Fetch and run the latest staff client build from a KCLS EG server. -# ------------------------------------------------------------------- -set -eu -SERVER="" -CLIENT_DIR="$HOME/staff_client" -XUL_BUNDLE="xulrunner-14.0.1.en-US.linux-x86_64.tar.bz2" -XUL_URL="http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/14.0.1/runtimes/$XUL_BUNDLE" - -function usage { - cat < -USAGE - exit; -} - -while getopts "s:h" opt; do - case $opt in - s) SERVER=$OPTARG;; - h) usage; - esac -done; - -[ -z "$SERVER" ] && usage; - -mkdir -p $CLIENT_DIR -cd $CLIENT_DIR - -if [ ! -d xulrunner ]; then - wget $XUL_URL - tar -jxf $XUL_BUNDLE -fi - -rm -f current-client-build.zip; -rm -rf build; - -# fetch new build -wget "http://$SERVER/xul/builds/current-client-build.zip" -unzip current-client-build.zip -cd build -../xulrunner/xulrunner-bin application.ini - diff --git a/KCLS/misc-scripts/manage-log-files.sh b/KCLS/misc-scripts/manage-log-files.sh deleted file mode 100755 index 93da78d070..0000000000 --- a/KCLS/misc-scripts/manage-log-files.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -set -eu -# Syslog server log file compressor and deleter. -# -# To future generations: this script was a lot simpler -# to implement and test than a logrotate setup. - -# Specifically, the hurdle is that logratate is designed -# to handle multiple log files in the last path component -# (e.g. /my/path/to/logfiles/*). KCLS log directory tree -# has several levels which are year, month and day. To -# fully express what this script does a lot of hardcoded -# configuration would need to be written. -# While it still technically should be possible to -# configure logrotate to do what this script achieves -# it will be really cumbersome and significantly time -# demanding. Especially, when the log directory tree -# structure needs to be modified in the future as it will -# necessitate revision of logrotate configuration that -# would need to be rewritten to account for the changes -# in the structure of the log directory tree. Not to mention -# use of underdocumented features (iliv@commandprompt.com) - -# *_AGE values are stored as days -# Example: a compress value of "3" means compress files -# last modified more than 3 days ago. -COMPRESS_AGE=3 -DELETE_AGE=365 - -function usage { - cat < -d -USAGE - exit; -} - -while getopts "d:c:h" opt; do - case $opt in - c) COMPRESS_AGE=$OPTARG;; - d) DELETE_AGE=$OPTARG;; - h) usage; - esac -done; - -# Delete all Evergreen log files that are older than DELETE_AGE -# days, except for the Apache access log and Evergreen activity log. - -/usr/bin/find /var/log/evergreen -type f -mtime +$DELETE_AGE \ - -not -name "ap_access*" -not -name "activity*" -delete - -# Compress Evergreen log files older than COMPRESS_AGE days - -/usr/bin/find /var/log/evergreen/ -type f -mtime +$COMPRESS_AGE \ - -not -name "*bz2" -exec /bin/bzip2 {} \; - -# clean up empty directories - -/usr/bin/find /var/log/evergreen/ -type d -empty -exec rmdir '{}' \; -