release.sh | 967 +++++++++++++++++++++++++++++++++-------------------------- rhq_bash.lib | 253 +++++++++++++++ 2 files changed, 804 insertions(+), 416 deletions(-)
New commits: commit 2b7266c2eaa65b465ca24ae70a6bf802c163ec92 Author: Jay Shaughnessy jshaughn@redhat.com Date: Mon Dec 19 12:44:42 2011 -0500
Update release script for build automation
diff --git a/release.sh b/release.sh index b11a225..9847c0e 100755 --- a/release.sh +++ b/release.sh @@ -1,472 +1,607 @@ -#!/bin/sh +#!/bin/bash +#======================================================================================== +# Usage: +# See usage function. +# +# Description: +# RHQ release script. Supports tagging and branching model described in the community +# wiki: +# http://www.rhq-project.org/display/RHQ/Source+Control +# +# Options: +# See usage function. +#======================================================================================== + + +#include the utility library +source `dirname $0`/rhq_bash.lib + + +#======================================================================================== +# Description: Display usage information then abort the script. +#======================================================================================== +usage() +{ + USAGE=$( +cat << EOF +USAGE: release.sh OPTIONS + + --release-version=version [REQUIRED] + The release version to be tagged by this script. + + --development-version=version [REQUIRED] + The version under which development will continue after tagging. + + --release-branch=git_branch [REQUIRED] + Git branch to be used as base for tagging and/or branching. + + --release-type=community|enterprise [REQUIRED] + Type of release. + + --test-mode [OPTIONAL, DEFAULT] + Run this script in test mode. Create a test branch from release branch and perform tagging and version updates on this test branch.
-if [ -n "$RELEASE_DEBUG" ]; then - echo "Debug output is enabled." - set -x -fi + --production-mode [OPTIONAL] + Run this script in production mode. Follow the official branching and tagging model.
+ --mode=test|production [OPTIONAL] + Used to directly set the script mode.
-# Constants + --branch [OPTIONAL] + Branch from release branch before tagging the release version. And updated development version on original branch.
-PROJECT_NAME="rhq" -PROJECT_DISPLAY_NAME="RHQ" -PROJECT_GIT_WEB_URL="http://git.fedorahosted.org/git/?p=rhq/rhq.git" -TAG_PREFIX="RHQ" -MINIMUM_MAVEN_VERSION="2.1.0" + --tag [OPTIONAL, DEFAULT] + Use the release branch to tag the release version. And update development version on the same branch.
+ --scm-strategy=tag|branch [OPTIONAL] + Used to directly set the scm strategy. + + --extra-profile=extra_profile [OPTIONAL] + An extra maven profile to be used for all the maven commands. + + --debug=[true|false] [OPTIONAL] + Set maven in debug mode. Default is false; true if option specified without argument. + + --workspace=workspace_to_use [OPTIONAL] + Override the workspace used by default by the script. + + --override-tag=[true|false] [OPTIONAL] + Override the tag if it already exists remotely. Default is false; true if option specified without argument. + +EOF +)
-# Functions + EXAMPLE="release.sh --release-type="enterprise" --release-version="5.0.0.GA" --development-version="5.0.1-SNAPSHOT" --release-branch="stefan/release_test" --branch"
-abort() + abort "$@" "$USAGE" "$EXAMPLE" +} + + +#======================================================================================== +# Description: Validate and parse input arguments +#======================================================================================== +parse_and_validate_options() { - echo >&2 - for ARG in "$@"; do - echo "$ARG" >&2 + print_function_information $FUNCNAME + + RELEASE_VERSION= + DEVELOPMENT_VERSION= + RELEASE_BRANCH= + RELEASE_TYPE="community" + MODE="test" + SCM_STRATEGY="tag" + EXTRA_MAVEN_PROFILE= + DEBUG_MODE=false + OVERRIDE_TAG=false + + short_options="h" + long_options="help,release-version:,development-version:,release-branch:,release-type:,test-mode,production-mode,mode:,branch,tag,scm-strategy:,extra-profile:,debug::,workspace:,override-tag::" + + PROGNAME=${0##*/} + ARGS=$(getopt -s bash --options $short_options --longoptions $long_options --name $PROGNAME -- "$@" ) + eval set -- "$ARGS" + + while true; do + case $1 in + -h|--help) + usage + ;; + --release-version) + shift + RELEASE_VERSION="$1" + shift + ;; + --development-version) + shift + DEVELOPMENT_VERSION="$1" + shift + ;; + --release-branch) + shift + RELEASE_BRANCH="$1" + shift + ;; + --release-type) + shift + RELEASE_TYPE="$1" + shift + ;; + --test-mode) + MODE="test" + shift + ;; + --production-mode) + MODE="production" + shift + ;; + --mode) + shift + MODE="$1" + shift + ;; + --tag) + SCM_STRATEGY="tag" + shift + ;; + --branch) + SCM_STRATEGY="branch" + shift + ;; + --scm-strategy) + shift + SCM_STRATEGY="$1" + shift + ;; + --extra-profile) + shift + EXTRA_MAVEN_PROFILE="$1" + shift + ;; + --debug) + shift + case "$1" in + true) + DEBUG_MODE=true + shift + ;; + false) + DEBUG_MODE=false + shift + ;; + "") + DEBUG_MODE=true + shift + ;; + *) + DEBUG_MODE=false + shift + ;; + esac + ;; + --workspace) + shift + WORKSPACE=$1 + shift + ;; + --override-tag) + shift + case "$1" in + true) + OVERRIDE_TAG=true + shift + ;; + false) + OVERRIDE_TAG=false + shift + ;; + "") + OVERRIDE_TAG=true + shift + ;; + *) + OVERRIDE_TAG=false + shift + ;; + esac + ;; + --) + shift + break + ;; + *) + usage + ;; + esac done - exit 1 -}
-usage() -{ - abort "$@" "Usage: $EXE community|enterprise RELEASE_VERSION DEVELOPMENT_VERSION RELEASE_BRANCH GIT_USERNAME test|production" "Example: $EXE enterprise 3.0.0.GA 3.0.0-SNAPSHOT release-3.0.0 ips test" -} + if [ -z "$RELEASE_VERSION" ]; + then + usage "Release version not specified!" + fi + + if [ -z "$DEVELOPMENT_VERSION" ]; + then + usage "Development version not specified!" + fi + + if [ -z "$RELEASE_BRANCH" ]; + then + usage "Release branch not specified!" + fi + + if [ "$RELEASE_TYPE" != "community" ] && [ "$RELEASE_TYPE" != "enterprise" ]; then + usage "Invalid release type: $RELEASE_TYPE (valid release types are 'community' or 'enterprise')" + fi
+ if [ "$MODE" != "test" ] && [ "$MODE" != "production" ]; then + usage "Invalid script mode: $MODE (valid modes are 'test' or 'production')" + fi
-# Process command line args. + if [ "$SCM_STRATEGY" != "tag" ] && [ "$SCM_STRATEGY" != "branch" ]; then + usage "Invalid scm strategy: $SCM_STRATEGY (valid scm strategies are 'tag' or 'branch')" + fi
-EXE=`basename $0` -if [ "$#" -ne 6 ]; then - usage -fi -RELEASE_TYPE="$1" -if [ "$RELEASE_TYPE" != "community" ] && [ "$RELEASE_TYPE" != "enterprise" ]; then - usage "Invalid release type: $RELEASE_TYPE (valid release types are 'community' or 'enterprise')" -fi -RELEASE_VERSION="$2" -DEVELOPMENT_VERSION="$3" -RELEASE_BRANCH="$4" -GIT_USERNAME="$5" -MODE="$6" -if [ "$MODE" != "test" ] && [ "$MODE" != "production" ]; then - usage "Invalid mode: $MODE (valid modes are 'test' or 'production')" -fi + print_centered "Script Options" + script_options=( "RELEASE_VERSION" "DEVELOPMENT_VERSION" "RELEASE_BRANCH" "RELEASE_TYPE" \ + "MODE" "SCM_STRATEGY" ) + print_variables "${script_options[@]}" +}
-if [ "$MODE" = "production" ]; then - if [ -z "$JBOSS_ORG_USERNAME" ] || [ -z "$JBOSS_ORG_PASSWORD" ]; then - usage "In production mode, jboss.org credentials must be specified via the JBOSS_ORG_USERNAME and JBOSS_ORG_PASSWORD environment variables." - fi -fi
+#======================================================================================== +# Description: Set all the local and environment variables required by the script. +#======================================================================================== +set_local_and_environment_variables() +{ + print_function_information $FUNCNAME
-# Make sure JAVA_HOME points to a valid JDK 1.6+ install. + # Set environment variables + MAVEN_OPTS="-Xms512M -Xmx1024M -XX:PermSize=128M -XX:MaxPermSize=256M" + export MAVEN_OPTS
-if [ -z "$JAVA_HOME" ]; then - abort "JAVA_HOME environment variable is not set - JAVA_HOME must point to a JDK (not JRE) 6 install dir." -fi
-if [ ! -d "$JAVA_HOME" ]; then - abort "JAVA_HOME ($JAVA_HOME) does not exist or is not a directory - JAVA_HOME must point to a JDK (not JRE) 6 install dir." -fi + # Set various local variables + if [ -n "$WORKSPACE" ]; then + echo "Running script in a Hudson job." + MAVEN_LOCAL_REPO_DIR="$WORKSPACE/.m2/repository" + if [ ! -d "$MAVEN_LOCAL_REPO_DIR" ]; then + mkdir -p "$MAVEN_LOCAL_REPO_DIR" + fi + MAVEN_SETTINGS_FILE="$WORKSPACE/.m2/settings.xml" + else + MAVEN_LOCAL_REPO_DIR="$HOME/.m2/repository" + MAVEN_SETTINGS_FILE="$HOME/.m2/settings.xml" + fi
-echo "Prepending $JAVA_HOME/bin to PATH..." -PATH="$JAVA_HOME/bin:$PATH" + MAVEN_ARGS="--settings $MAVEN_SETTINGS_FILE -Dmaven.repo.local=$MAVEN_LOCAL_REPO_DIR --batch-mode --errors"
-if ! which java >/dev/null 2>&1; then - abort "java not found in PATH ($PATH) - JAVA_HOME must point to a JDK (not JRE) 6 install dir." -fi + if [ -n "$EXTRA_MAVEN_PROFILE" ]; + then + MAVEN_ARGS="$MAVEN_ARGS --activate-profiles $EXTRA_MAVEN_PROFILE,enterprise,dist,release" + else + MAVEN_ARGS="$MAVEN_ARGS --activate-profiles enterprise,dist,release" + fi
-if ! which javac >/dev/null 2>&1; then - abort "javac not found in PATH ($PATH) - JAVA_HOME must point to a JDK (not JRE) 6 install dir." -fi
-if ! javap java.util.Deque >/dev/null 2>&1; then - abort "java.util.Deque not found - Java version appears to be less than 1.6 - Jave version must be 1.6 or later." -fi + if [ "$RELEASE_TYPE" = "enterprise" ]; + then + MAVEN_ARGS="$MAVEN_ARGS -Dexclude-webdav -Pdisable-tags -DTagManager=false -Dfiltered.location=target/filtered-sources/java" + fi
-# TODO: Check that JDK version is < 1.7. + if [ -n "$DEBUG_MODE" ]; then + echo "Maven debug enabled" + MAVEN_ARGS="$MAVEN_ARGS --debug" + fi
+ TAG_PREFIX="RHQ" + TAG_VERSION=`echo $RELEASE_VERSION | sed 's/[.|-]/_/g'` + RELEASE_TAG="${TAG_PREFIX}_${TAG_VERSION}" + + # Set the system character encoding to ISO-8859-1 to ensure i18log reads its + # messages and writes its resource bundle properties files in that encoding, + # since that is how the German and French I18NMessage annotation values are + # encoded and the encoding used by i18nlog to read in resource bundle + # property files. + LANG=en_US.iso8859 + export LANG + + # Print out a summary of the environment. + print_centered "Environment Variables" + environment_variables=( "JAVA_HOME" "M2_HOME" "MAVEN_OPTS" "PATH" "LANG" ) + print_variables "${environment_variables[@]}" + + print_centered "Local Variables" + local_variables=( "MAVEN_LOCAL_REPO_DIR" "MAVEN_SETTINGS_FILE" "MAVEN_ARGS" \ + "JBOSS_ORG_USERNAME" ) + print_variables "${local_variables[@]}" +}
-# If this is an enterprise release, make sure JAVA5_HOME points to a valid JDK 1.5 install. -# We need this to validate only Java 5 or earlier APIs are used in all modules, except the CLI, which requires Java 6.
-if [ "$RELEASE_TYPE" = "enterprise" ]; then - if [ -z "$JAVA5_HOME" ]; then - abort "JAVA5_HOME environment variable is not set - JAVA5_HOME must point to a JDK (not JRE) 1.5 install dir." - fi +#======================================================================================== +# Description: Perform version update process and test the outcome by building +# from source. +#======================================================================================== +run_release_version_and_tag_process() +{ + print_function_information $FUNCNAME + + echo "1) Perform a test build before changing version." + mvn clean install $MAVEN_ARGS -Ddbreset + [ "$?" -ne 0 ] && abort "Test build failed. Please see output for details, fix any issues, then try again." + + echo "2) Run a maven cleanup to remove all the artifacts from previous build, this cleans module target dirs." + mvn clean $MAVEN_ARGS + [ "$?" -ne 0 ] && abort "Failed to cleanup snbapshot jars produced by test build from module target dirs. Please see above Maven output for details, fix any issues, then try again." + + echo "3) Increment version on all poms." + mvn versions:set versions:use-releases -DnewVersion=$RELEASE_VERSION -DallowSnapshots=false -DgenerateBackupPoms=false + [ "$?" -ne 0 ] && abort "Version set failed. Please see output for details, fix any issues, then try again." + + echo "4) Perform a test build with the new version." + mvn clean install $MAVEN_ARGS -DskipTests=true -Ddbsetup-do-not-check-schema=true + [ "$?" -ne 0 ] && abort "Maven build for new version failed. Please see output for details, fix any issues, then try again." + + echo "6) Cleanup again after this test build before commiting changes." + mvn clean $MAVEN_ARGS + [ "$?" -ne 0 ] && abort "Failed to cleanup snbapshot jars produced by test build from module target dirs. Please see above Maven output for details, fix any issues, then try again." + + echo "7) Commit the change in version; if everything went well so far then this is a good tag." + git add -u + [ "$?" -ne 0 ] && abort "Adding modified files to commit failed." + git commit -m "tag $RELEASE_TAG" + [ "$?" -ne 0 ] && abort "The commit with version modified files failed." + + echo "8) Tag the current source." + if [ "$OVERRIDE_TAG" ]; + then + git tag --force "$RELEASE_TAG" + [ "$?" -ne 0 ] && abort "Force tagging failed." + else + git tag "$RELEASE_TAG" + [ "$?" -ne 0 ] && abort "Tagging failed" + fi
- if [ ! -d "$JAVA5_HOME" ]; then - abort "JAVA5_HOME ($JAVA5_HOME) does not exist or is not a directory - JAVA5_HOME must point to a JDK (not JRE) 1.5 install dir." - fi + echo "9) Merge any remote changes into the local branch to be able to push tag and version change. This will fail if the merge process requires manual merges." + git pull origin "$BUILD_BRANCH" + [ "$?" -ne 0 ] && abort "Merge with remote $BUILD_BRANCH failed."
- if [ ! -x "$JAVA5_HOME/bin/java" ]; then - abort "$JAVA5_HOME/bin/java does not exist or is not executable - JAVA5_HOME must point to a JDK (not JRE) 1.5 install dir." - fi - - if [ ! -x "$JAVA5_HOME/bin/javac" ]; then - abort "$JAVA5_HOME/bin/javac does not exist or is not executable - JAVA5_HOME must point to a JDK (not JRE) 1.5 install dir." - fi + echo "10) If everything went well so far than means all the changes can be pushed!!!" + git push origin "refs/heads/$BUILD_BRANCH" + [ "$?" -ne 0 ] && abort "$BUILD_BRANCH branch push to origin failed." + git push origin "refs/tags/$RELEASE_TAG" + [ "$?" -ne 0 ] && abort "$BUILD_BRANCH branch push to origin failed." +}
- if ! "$JAVA5_HOME/bin/javap" java.lang.Enum >/dev/null 2>&1; then - abort "java.lang.Enum not found - JAVA5_HOME ($JAVA5_HOME) version appears to be less than 1.5 - version must be 1.5.x." - fi
- if "$JAVA5_HOME/bin/javap" java.util.Deque >/dev/null 2>&1; then - abort "java.util.Deque found - JAVA5_HOME ($JAVA5_HOME) version appears to be greater than or equal to 1.6 - version must be 1.5.x." - fi -fi +#======================================================================================== +# Description: Update the version for the development branch. +#======================================================================================== +update_development_version() +{ + print_function_information $FUNCNAME
+ echo "1) Set version to the current development version" + mvn versions:set versions:use-releases -DnewVersion=$DEVELOPMENT_VERSION -DallowSnapshots=false -DgenerateBackupPoms=false + [ "$?" -ne 0 ] && abort "Version set failed. Please see output for details, fix any issues, then try again."
-# Make sure M2_HOME points to a valid Maven 2.1.x or 2.2.x install. + echo "2) Commit the change in version." + git add -u + [ "$?" -ne 0 ] && abort "Adding modified files to commit failed." + git commit -m "development RHQ_$DEVELOPMENT_VERSION" + [ "$?" -ne 0 ] && abort "The commit with version modified files failed."
-if [ -z "$M2_HOME" ]; then - abort "M2_HOME environment variable is not set - M2_HOME must point to a Maven, $MINIMUM_MAVEN_VERSION or later, install dir." -fi + echo "3) Merge any remote changes into the local branch to be able to push tag and version change. This will fail if the merge process requires manual merges." + git pull origin "$BUILD_BRANCH" + [ "$?" -ne 0 ] && abort "Merge with remote $BUILD_BRANCH failed."
-if [ ! -d "$M2_HOME" ]; then - abort "M2_HOME ($M2_HOME) does not exist or is not a directory - M2_HOME must point to a Maven, $MINIMUM_MAVEN_VERSION or later, install dir." -fi + echo "4) If everything went well so far than means all the changes can be pushed!!!" + git push origin "refs/heads/$BUILD_BRANCH" + [ "$?" -ne 0 ] && abort "$BUILD_BRANCH branch push to origin failed." +}
-echo "Prepending $M2_HOME/bin to PATH..." -PATH="$M2_HOME/bin:$PATH"
-unalias mvn 2>/dev/null -unset -f mvn 2>/dev/null - -if ! which mvn >/dev/null 2>&1; then - abort "mvn not found in PATH ($PATH) - M2_HOME must point to a Maven, $MINIMUM_MAVEN_VERSION or later, install dir." -fi - -mvn -version >/dev/null -[ $? -ne 0 ] && abort "mvn --version failed with exit code $?." -MAVEN_VERSION=`mvn -version | head -1 | sed 's|[^0-9]*([^ ]*).*|\1|'` -if echo $MAVEN_VERSION | grep -v "^2.[12]"; then - abort "Unsupported Maven version - $MAVEN_VERSION. Only Maven 2.1.x or 2.2.x are supported. Please update the value of M2_HOME, then try again." -fi - - -# Make sure git 1.6.x or 1.7.x is in the PATH. - -if ! which git >/dev/null 2>&1; then - abort "git not found in PATH ($PATH)." -fi - -git --version >/dev/null -[ $? -ne 0 ] && abort "git --version failed with exit code $?." -GIT_VERSION=`git --version | sed 's|[^0-9]*([^ ]*).*|\1|'` -if echo $GIT_VERSION | grep -v "^1.[67]"; then - abort "Unsupported git version - $GIT_VERSION. Only git 1.6.x or 1.7.x are supported. Please add a directory containing a supported version of git to your PATH, then try again." -fi - - -# Set various environment variables. - -MAVEN_OPTS="-Xms512M -Xmx1024M -XX:PermSize=128M -XX:MaxPermSize=256M" -export MAVEN_OPTS - - -# Set various local variables. - -if [ -n "$HUDSON_URL" ] && [ -n "$WORKSPACE" ]; then - echo "We appear to be running in a Hudson job." - WORKING_DIR="$WORKSPACE" - MAVEN_LOCAL_REPO_DIR="$HOME/.m2/hudson-release-$RELEASE_TYPE-repository" - MAVEN_SETTINGS_FILE="$HOME/.m2/hudson-$JOB_NAME-settings.xml" -elif [ -z "$WORKING_DIR" ]; then - WORKING_DIR="$HOME/release/rhq" - MAVEN_LOCAL_REPO_DIR="$HOME/release/m2-repository" - MAVEN_SETTINGS_FILE="$HOME/release/m2-settings.xml" -fi - -PROJECT_GIT_URL="ssh://${GIT_USERNAME}@git.fedorahosted.org/git/rhq/rhq.git" - -MAVEN_ARGS="--settings $MAVEN_SETTINGS_FILE --batch-mode --errors -Penterprise,dist,release" -# TODO: We may eventually want to reenable tests for production releases. -#if [ "$MODE" = "test" ]; then -# MAVEN_ARGS="$MAVEN_ARGS -Dmaven.test.skip=true" -#fi -MAVEN_ARGS="$MAVEN_ARGS -Dmaven.test.skip=true" -if [ "$RELEASE_TYPE" = "enterprise" ]; then - MAVEN_ARGS="$MAVEN_ARGS -Dexclude-webdav -Djava5.home=$JAVA5_HOME/jre" -fi -if [ -n "$RELEASE_DEBUG" ]; then - MAVEN_ARGS="$MAVEN_ARGS --debug" -fi -if [ -n "$RELEASE_ADDITIONAL_MAVEN_ARGS" ]; then - MAVEN_ARGS="$MAVEN_ARGS $RELEASE_ADDITIONAL_MAVEN_ARGS" -fi -if [ -z "$MAVEN_LOCAL_REPO_PURGE_INTERVAL_HOURS" ]; then - MAVEN_LOCAL_REPO_PURGE_INTERVAL_HOURS="6" -fi - -# TODO: We may eventually want to reenable publishing of enterprise artifacts. -if [ "$MODE" = "production" ] && [ "$RELEASE_TYPE" = "community" ]; then - MAVEN_RELEASE_PERFORM_GOAL="deploy" -else - MAVEN_RELEASE_PERFORM_GOAL="install" -fi - - -TAG_VERSION=`echo $RELEASE_VERSION | sed 's/./_/g'` -RELEASE_TAG="${TAG_PREFIX}_${TAG_VERSION}" - - -# Set the system character encoding to ISO-8859-1 to ensure i18log reads its -# messages and writes its resource bundle properties files in that encoding, -# since that is how the German and French I18NMessage annotation values are -# encoded and the encoding used by i18nlog to read in resource bundle -# property files. -LANG=en_US.iso8859 -export LANG - - -# Print out a summary of the environment. - -echo -echo "========================== Environment Variables ==============================" -echo "JAVA_HOME=$JAVA_HOME" -[ "$RELEASE_TYPE" = "enterprise" ] && echo "JAVA5_HOME=$JAVA5_HOME" -echo "M2_HOME=$M2_HOME" -echo "MAVEN_OPTS=$MAVEN_OPTS" -echo "PATH=$PATH" -echo "LANG=$LANG" -echo "============================= Local Variables =================================" -echo "WORKING_DIR=$WORKING_DIR" -echo "PROJECT_NAME=$PROJECT_NAME" -echo "PROJECT_GIT_URL=$PROJECT_GIT_URL" -echo "RELEASE_TYPE=$RELEASE_TYPE" -echo "RELEASE_VERSION=$RELEASE_VERSION" -echo "DEVELOPMENT_VERSION=$DEVELOPMENT_VERSION" -echo "RELEASE_BRANCH=$RELEASE_BRANCH" -echo "RELEASE_TAG=$RELEASE_TAG" -echo "MODE=$MODE" -echo "MAVEN_LOCAL_REPO_DIR=$MAVEN_LOCAL_REPO_DIR" -echo "MAVEN_LOCAL_REPO_PURGE_INTERVAL_HOURS=$MAVEN_LOCAL_REPO_PURGE_INTERVAL_HOURS" -echo "MAVEN_SETTINGS_FILE=$MAVEN_SETTINGS_FILE" -echo "MAVEN_ARGS=$MAVEN_ARGS" -echo "MAVEN_RELEASE_PERFORM_GOAL=$MAVEN_RELEASE_PERFORM_GOAL" -echo "JBOSS_ORG_USERNAME=$JBOSS_ORG_USERNAME" -echo "============================= Program Versions ================================" -git --version -echo -java -version -echo -mvn --version | head -1 -echo "===============================================================================" -echo - - -# Clean the Maven local repo if it hasn't been purged recently. - -if [ -f "$MAVEN_LOCAL_REPO_DIR" ]; then - if [ "$MODE" = "production" ]; then - echo "Purging MAVEN_LOCAL_REPO_DIR ($MAVEN_LOCAL_REPO_DIR) since this is a production build..." - #rm -rf "$MAVEN_LOCAL_REPO_DIR" - else - OUTPUT=`find "$MAVEN_LOCAL_REPO_DIR" -maxdepth 0 -mtime $MAVEN_LOCAL_REPO_PURGE_INTERVAL_HOURS` - if [ -n "$OUTPUT" ]; then - echo "MAVEN_LOCAL_REPO_DIR ($MAVEN_LOCAL_REPO_DIR) has existed for more than $MAVEN_LOCAL_REPO_PURGE_INTERVAL_HOURS hours - purging it for a clean-clean build..." - rm -rf "$MAVEN_LOCAL_REPO_DIR" +#======================================================================================== +# Description: Perform tag verification process +# 1) if the tag already exists on the remote repo than abort the script +# 2) if the tag exists only locally then delete it, that means there was +# error during the previous run of this script. Tags are committed to +# repo only this script runs successfully. +#======================================================================================== +verify_tags() +{ + print_function_information $FUNCNAME + + # If the specified tag already exists remotely and we're in production mode, then abort. If it exists and + # we're in test mode, delete it + EXISTING_REMOTE_TAG=`git ls-remote --tags origin "$RELEASE_TAG"` + if [ -n "$EXISTING_REMOTE_TAG" ]; + then + if [ "$OVERRIDE_TAG" ]; + then + echo "A remote tag named $RELEASE_TAG already exists, but will be overriden." + else + abort "A remote tag named $RELEASE_TAG already exists - aborting" fi fi - -fi -mkdir -p "$MAVEN_LOCAL_REPO_DIR" - - -# Create the Maven settings file. -cat <<EOF >"${MAVEN_SETTINGS_FILE}" -<settings> - <localRepository>$MAVEN_LOCAL_REPO_DIR</localRepository> - - <profiles> - - <profile> - <id>release</id> - <properties> - <rhq.test.ds.server-name>hudson-qe.rhq.rdu.redhat.com</rhq.test.ds.server-name> - <rhq.test.ds.port>5432</rhq.test.ds.port> - <rhq.test.ds.db-name>rhq_release_tag</rhq.test.ds.db-name> - <rhq.test.ds.connection-url>jdbc:postgresql://hudson-qe.rhq.rdu.redhat.com:5432/rhq_release_tag</rhq.test.ds.connection-url> - <rhq.test.ds.user-name>rhqadmin</rhq.test.ds.user-name> - <rhq.test.ds.password>rhqadmin</rhq.test.ds.password> - <rhq.test.ds.type-mapping>PostgreSQL</rhq.test.ds.type-mapping> - <rhq.test.ds.driver-class>org.postgresql.Driver</rhq.test.ds.driver-class> - <rhq.test.ds.xa-datasource-class>org.postgresql.xa.PGXADataSource</rhq.test.ds.xa-datasource-class> - <rhq.test.ds.hibernate-dialect>org.hibernate.dialect.PostgreSQLDialect</rhq.test.ds.hibernate-dialect> - <!-- quartz properties --> - <rhq.test.quartz.driverDelegateClass>org.quartz.impl.jdbcjobstore.PostgreSQLDelegate</rhq.test.quartz.driverDelegateClass> - <rhq.test.quartz.selectWithLockSQL>SELECT * FROM {0}LOCKS ROWLOCK WHERE LOCK_NAME = ? FOR UPDATE</rhq.test.quartz.selectWithLockSQL> - <rhq.test.quartz.lockHandlerClass>org.quartz.impl.jdbcjobstore.StdRowLockSemaphore</rhq.test.quartz.lockHandlerClass> - - <DatabaseTest.nofail>true</DatabaseTest.nofail> - - <rhq.testng.excludedGroups>agent-comm,comm-client,postgres-plugin,native-system</rhq.testng.excludedGroups> - </properties> - </profile> - - </profiles> - - <!-- This is used by the deploy plugin to publish release artifacts to the jboss.org Nexus repo. --> - <servers> - <server> - <id>jboss-releases-repository</id> - <username>$JBOSS_ORG_USERNAME</username> - <password>$JBOSS_ORG_PASSWORD</password> - </server> - </servers> - -</settings> -EOF
-# Clone and/or checkout the source from git. + # See if the specified tag already exists locally - if so, delete it (even if in production mode). + # If the tag is just local then there were errors during the last run; no harm in removing it. + EXISTING_LOCAL_TAG=`git tag -l "$RELEASE_TAG"` + if [ -n "$EXISTING_LOCAL_TAG" ]; + then + echo "A local tag named $RELEASE_TAG already exists - deleting it..." + git tag -d "$RELEASE_TAG" + [ "$?" -ne 0 ] && abort "Failed to delete local tag ($RELEASE_TAG)." + fi +} +
-if [ -d "$WORKING_DIR" ]; then - cd "$WORKING_DIR" +#======================================================================================== +# Description: Run the validation process for all the system utilities needed by +# the script. At the end print the version of each utility. +#======================================================================================== +validate_system_utilities() +{ + print_function_information $FUNCNAME + + # TODO: Check that JDK version is < 1.7. + + validate_java_6 + + validate_java_5 + + validate_maven + + validate_git + + print_centered "Program Versions" + program_versions=("git --version" "java -version" "mvn --version") + print_program_versions "${program_versions[@]}" +} + + +#======================================================================================== +# Description: Prints the release information. +#======================================================================================== +print_release_information() +{ + print_function_information $FUNCNAME + + echo + print_centered "Release Info" + echo "Version: $RELEASE_VERSION" + echo "Branch URL: http://git.fedorahosted.org/git/?p=rhq/rhq.git;a=shortlog;h=refs/heads/$RELE..." + echo "Tag URL: http://git.fedorahosted.org/git/?p=rhq/rhq.git;a=shortlog;h=refs/tags/$RELEA..." + print_centered "=" +} + + +#======================================================================================== +# Description: Checkout release branch. +#======================================================================================== +checkout_release_branch() +{ + print_function_information $FUNCNAME + + # Checkout the source from git, assume that the git repo is already cloned git status >/dev/null 2>&1 GIT_STATUS_EXIT_CODE=$? # Note, git 1.6 and earlier returns an exit code of 1, rather than 0, if there are any uncommitted changes, - # and git 1.7 returns 0, so we check if the exit code is less than or equal to 1 to determine if $WORKING_DIR + # and git 1.7 returns 0, so we check if the exit code is less than or equal to 1 to determine if current folder # is truly a git working copy. - if [ "$GIT_STATUS_EXIT_CODE" -le 1 ]; then + if [ "$GIT_STATUS_EXIT_CODE" -le 1 ]; + then echo "Checking out a clean copy of the release branch ($RELEASE_BRANCH)..." git fetch origin "$RELEASE_BRANCH" [ "$?" -ne 0 ] && abort "Failed to fetch release branch ($RELEASE_BRANCH)." - git checkout "$RELEASE_BRANCH" 2>/dev/null - if [ "$?" -ne 0 ]; then - git checkout --track -b "$RELEASE_BRANCH" "origin/$RELEASE_BRANCH" + + git checkout --track "origin/$RELEASE_BRANCH" + if [ "$?" -ne 0 ]; + then + git checkout "$RELEASE_BRANCH" fi - [ "$?" -ne 0 ] && abort "Failed to checkout release branch ($RELEASE_BRANCH)." + [ "$?" -ne 0 ] && abort "Failed to checkout release branch ($RELEASE_BRANCH)." + git reset --hard "origin/$RELEASE_BRANCH" [ "$?" -ne 0 ] && abort "Failed to reset release branch ($RELEASE_BRANCH)." + git clean -dxf [ "$?" -ne 0 ] && abort "Failed to clean release branch ($RELEASE_BRANCH)." - git pull + + git pull origin $RELEASE_BRANCH [ "$?" -ne 0 ] && abort "Failed to update release branch ($RELEASE_BRANCH)." else - echo "$WORKING_DIR does not appear to be a git working directory ('git status' returned $GIT_STATUS_EXIT_CODE) - removing it so we can freshly clone the repo..." - cd .. - rm -rf "$WORKING_DIR" - [ "$?" -ne 0 ] && abort "Failed to remove bogus working directory ($WORKING_DIR)." + echo "Current folder does not appear to be a git working directory ('git status' returned $GIT_STATUS_EXIT_CODE) - removing it so we can freshly clone the repo..." + fi +} + + +#======================================================================================== +# Description: Checkout or create the build branch for the release process. +#======================================================================================== +checkout_build_branch_for_release() +{ + print_function_information $FUNCNAME + + # if this is a test build then create a temporary build branch off of RELEASE_BRANCH. This allows checkins to + # continue in RELEASE_BRANCH without affecting the release plugin work, which will fail if the branch contents + # change before it completes. + if [ "$MODE" = "test" ]; + then + BUILD_BRANCH="${RELEASE_BRANCH}-test-build" + # delete the branch if it exists, so we can recreate it fresh + EXISTING_BUILD_BRANCH=`git ls-remote --heads origin "$BUILD_BRANCH"` + if [ -n "$EXISTING_BUILD_BRANCH" ]; + then + echo "Deleting remote branch origin/$BUILD_BRANCH" + git branch -D -r "origin/$BUILD_BRANCH" + echo "Deleting local branch $BUILD_BRANCH" + git branch -D "$BUILD_BRANCH" + fi + + echo "Creating and checking out local branch $BUILD_BRANCH from $RELEASE_BRANCH" + git checkout -b "$BUILD_BRANCH" + else + if [ "$SCM_STRATEGY" = "tag" ]; + then + BUILD_BRANCH="${RELEASE_BRANCH}" + else + BUILD_BRANCH="release-$RELEASE_VERSION" + # delete the branch if it exists, so we can recreate it fresh + EXISTING_BUILD_BRANCH=`git ls-remote --heads origin "$BUILD_BRANCH"` + if [ -n "$EXISTING_BUILD_BRANCH" ]; + then + abort "Remote repository already contains $BUILD_BRANCH." + fi + + echo "Creating and checking out local branch $BUILD_BRANCH from $RELEASE_BRANCH" + git checkout -b "$BUILD_BRANCH" + fi fi -fi -if [ ! -d "$WORKING_DIR" ]; then - echo "Cloning the $PROJECT_NAME git repo (this will take about 10-15 minutes)..." - git clone "$PROJECT_GIT_URL" "$WORKING_DIR" - [ "$?" -ne 0 ] && abort "Failed to clone $PROJECT_NAME git repo ($PROJECT_GIT_URL)." - cd "$CLONE_DIR" - git checkout --track -b $RELEASE_BRANCH "origin/$RELEASE_BRANCH" - [ "$?" -ne 0 ] && abort "Failed to checkout release branch ($RELEASE_BRANCH)." -fi - - -# if this is a test build then create a temporary build branch off of RELEASE_BRANCH. This allows checkins to -# continue in RELEASE_BRANCH without affecting the release plugin work, which will fail if the branch contents -# change before it completes. -if [ "$MODE" = "production" ]; then - BUILD_BRANCH="${RELEASE_BRANCH}" -else - BUILD_BRANCH="${RELEASE_BRANCH}-test-build" -# delete the branch if it exists, so we can recreate it fresh - EXISTING_BUILD_BRANCH=`git ls-remote --heads origin "$BUILD_BRANCH"` - if [ -n "$EXISTING_BUILD_BRANCH" ]; then - echo "Deleting remote branch origin/$BUILD_BRANCH" - git branch -D -r "origin/$BUILD_BRANCH" - echo "Deleting local branch $BUILD_BRANCH" - git branch -D "$BUILD_BRANCH" - fi - echo "Creating and checking out local branch $BUILD_BRANCH from $RELEASE_BRANCH" - git checkout -b "$BUILD_BRANCH" - echo "Creating remote branch $BUILD_BRANCH" - git pull origin "$BUILD_BRANCH" - git push origin "$BUILD_BRANCH" -fi - - -# We should now have the build_branch checked out -echo "Current Branch is $BUILD_BRANCH" - -# If the specified tag already exists remotely and we're in production mode, then abort. If it exists and -# we're in test mode, delete it - -EXISTING_REMOTE_TAG=`git ls-remote --tags origin "$RELEASE_TAG"` -if [ -n "$EXISTING_REMOTE_TAG" ] && [ "$MODE" = "production" ]; then - abort "A remote tag named $RELEASE_TAG already exists - aborting, since we are in production mode..." -fi - -if [ -n "$EXISTING_REMOTE_TAG" ] && [ "$MODE" = "test" ]; then - echo "A remote tag named $RELEASE_TAG already exists - deleting it, since we are in test mode..." - git push origin ":refs/tags/$RELEASE_TAG" - [ "$?" -ne 0 ] && abort "Failed to delete remote tag ($RELEASE_TAG)." -fi - - -# See if the specified tag already exists locally - if so, delete it (even if in production mode). - -EXISTING_LOCAL_TAG=`git tag -l "$RELEASE_TAG"` -if [ -n "$EXISTING_LOCAL_TAG" ]; then - echo "A local tag named $RELEASE_TAG already exists - deleting it..." - git tag -d "$RELEASE_TAG" - [ "$?" -ne 0 ] && abort "Failed to delete local tag ($RELEASE_TAG)." -fi - -# Run a test build before tagging. This will publish the snapshot artifacts to the local repo to "bootstrap" the repo. - -echo "Building project to ensure tests pass and to bootstrap local Maven repo (this will take about 15-30 minutes)..." -# NOTE: There is no need to do a mvn clean below, since we just did either a clone or clean checkout above. -mvn install $MAVEN_ARGS -Ddbreset -[ "$?" -ne 0 ] && abort "Test build failed. Please see above Maven output for details, fix any issues, then try again." -echo -echo "Test build succeeded!" - - -# Clean up the snapshot jars produced by the test build from module target dirs. - -echo "Cleaning up snapshot jars produced by test build from module target dirs..." -mvn clean $MAVEN_ARGS -[ "$?" -ne 0 ] && abort "Failed to cleanup snbapshot jars produced by test build from module target dirs. Please see above Maven output for details, fix any issues, then try again." - - -# If this is a production build perform a dry run of tagging the release. Skip this for test builds to reduce the -# build time -# TODO: Re-enable this. -#if [ "$MODE" = "production" ]; then -# echo "Doing a dry run of tagging the release..." -# mvn release:prepare $MAVEN_ARGS -DreleaseVersion=$RELEASE_VERSION -DdevelopmentVersion=$DEVELOPMENT_VERSION -Dresume=false -Dtag=$RELEASE_TAG "-DpreparationGoals=install $MAVEN_ARGS -Dmaven.test.skip=true -Ddbsetup-do-not-check-schema=true" -DdryRun=true -# [ "$?" -ne 0 ] && abort "Tagging dry run failed. Please see above Maven output for details, fix any issues, then try again." -# mvn release:clean $MAVEN_ARGS -# [ "$?" -ne 0 ] && abort "Failed to cleanup release plugin working files from tagging dry run. Please see above Maven output for details, fix any issues, then try again." -# echo -# echo "Tagging dry run succeeded!" -#fi - - -# If the dry run was skipped or succeeded, tag it for real. - -echo "Tagging the release..." -mvn release:prepare $MAVEN_ARGS -DreleaseVersion=$RELEASE_VERSION -DdevelopmentVersion=$DEVELOPMENT_VERSION -Dresume=false -Dtag=$RELEASE_TAG "-DpreparationGoals=install $MAVEN_ARGS -Dmaven.test.skip=true -Ddbsetup-do-not-check-schema=true" -DdryRun=false -Dusername=$GIT_USERNAME -[ "$?" -ne 0 ] && abort "Tagging failed. Please see above Maven output for details, fix any issues, then try again." -echo -echo "Tagging succeeded!" - - -# Checkout the tag and build it. If in production mode, publish the Maven artifacts. - -echo "Checking out release tag $RELEASE_TAG..." -git checkout "$RELEASE_TAG" -[ "$?" -ne 0 ] && abort "Checkout of release tag ($RELEASE_TAG) failed. Please see above git output for details, fix any issues, then try again." -git clean -dxf -[ "$?" -ne 0 ] && abort "Failed to cleanup unversioned files. Please see above git output for details, fix any issues, then try again." -echo "Building release from tag and publishing Maven artifacts (this will take about 10-15 minutes)..." -mvn $MAVEN_RELEASE_PERFORM_GOAL $MAVEN_ARGS -Dmaven.test.skip=true -Ddbsetup-do-not-check-schema=true -[ "$?" -ne 0 ] && abort "Release build failed. Please see above Maven output for details, fix any issues, then try again." -echo -echo "Release build succeeded!" - - -echo -echo "=============================== Release Info ==================================" -echo "Version: $RELEASE_VERSION" -echo "Branch URL: $PROJECT_GIT_WEB_URL;a=shortlog;h=refs/heads/$RELEASE_BRANCH" -echo "Tag URL: $PROJECT_GIT_WEB_URL;a=shortlog;h=refs/tags/$RELEASE_TAG" -echo "===============================================================================" +} + + +#======================================================================================== +# Description: Checkout or create the build branch for updating the development version. +#======================================================================================== +checkout_build_branch_for_development() +{ + print_function_information $FUNCNAME + + if [ "$MODE" = "production" ]; + then + if [ "$SCM_STRATEGY" = "branch" ]; + then + checkout_release_branch + BUILD_BRANCH="${RELEASE_BRANCH}" + fi + fi +} + + + +############ MAIN SCRIPT ############ + +parse_and_validate_options $@ + +set_script_debug_mode $DEBUG_MODE + +validate_system_utilities + +set_local_and_environment_variables + +verify_tags + +checkout_release_branch + +checkout_build_branch_for_release + +run_release_version_and_tag_process + +checkout_build_branch_for_development + +update_development_version + +print_release_information
+unset_script_debug_mode $DEBUG_MODE diff --git a/rhq_bash.lib b/rhq_bash.lib new file mode 100644 index 0000000..8b1a300 --- /dev/null +++ b/rhq_bash.lib @@ -0,0 +1,253 @@ +#======================================================================================== +# Usage: +# Include in any script file as script dependency. +# +# Description: +# Library of common functions used between multiple release related scripts. +# +# Options: +# N/A +#======================================================================================== + + + +#======================================================================================== +# Description: Display an error message and abort the script. +#======================================================================================== +abort() +{ + echo >&2 + for ARG in "$@"; do + echo "$ARG" >&2 + echo "">&2 + done + exit 1 +} + + +#======================================================================================== +# Description: Prints an array of variables passed in as arguments. +#======================================================================================== +print_variables() +{ + for variable in "$@" + do + temp_var='eval "echo $$variable"' + eval_temp_var=`eval $temp_var` + + if [ -z "$eval_temp_var" ]; then + echo "$variable is NOT defined!" + else + echo "$variable=$eval_temp_var" + fi + done +} + + +#======================================================================================== +# Description: Prints the eval result of each array element passed in. +#======================================================================================== +print_program_versions() +{ + for variable in "$@" + do + eval $variable + echo + done +} + + +#======================================================================================== +# Description: Validates that a compatible version of Java 6 is installed. +#======================================================================================== +validate_java_6() +{ + # Make sure JAVA_HOME points to a valid JDK 1.6+ install. + + if [ -z "$JAVA_HOME" ]; then + abort "JAVA_HOME environment variable is not set - JAVA_HOME must point to a JDK (not JRE) 6 install dir." + fi + + if [ ! -d "$JAVA_HOME" ]; then + abort "JAVA_HOME ($JAVA_HOME) does not exist or is not a directory - JAVA_HOME must point to a JDK (not JRE) 6 install dir." + fi + + echo "Prepending $JAVA_HOME/bin to PATH..." + PATH="$JAVA_HOME/bin:$PATH" + + if ! which java >/dev/null 2>&1; then + abort "java not found in PATH ($PATH) - JAVA_HOME must point to a JDK (not JRE) 6 install dir." + fi + + if ! which javac >/dev/null 2>&1; then + abort "javac not found in PATH ($PATH) - JAVA_HOME must point to a JDK (not JRE) 6 install dir." + fi + + if ! javap java.util.Deque >/dev/null 2>&1; then + abort "java.util.Deque not found - Java version appears to be less than 1.6 - Jave version must be 1.6 or later." + fi +} + + +#======================================================================================== +# Description: Validates that a compatible version of Java 5 is installed. +#======================================================================================== +validate_java_5() +{ + echo "nothing executed here" + # spinder 8/30/11: commenting out the JAVA5 support, but leaving logic in place for when we need the same backwards + # compatibility logic for JD6 vs. JDK7 support. + # If this is an enterprise release, make sure JAVA5_HOME points to a valid JDK 1.5 install. + # We need this to validate only Java 5 or earlier APIs are used in all modules, except the CLI, which requires Java 6. + # + #if [ "$RELEASE_TYPE" = "enterprise" ]; then + # if [ -z "$JAVA5_HOME" ]; then + # abort "JAVA5_HOME environment variable is not set - JAVA5_HOME must point to a JDK (not JRE) 1.5 install dir." + # fi + # + # if [ ! -d "$JAVA5_HOME" ]; then + # abort "JAVA5_HOME ($JAVA5_HOME) does not exist or is not a directory - JAVA5_HOME must point to a JDK (not JRE) 1.5 install dir." + # fi + # + # if [ ! -x "$JAVA5_HOME/bin/java" ]; then + # abort "$JAVA5_HOME/bin/java does not exist or is not executable - JAVA5_HOME must point to a JDK (not JRE) 1.5 install dir." + # fi + # + # if [ ! -x "$JAVA5_HOME/bin/javac" ]; then + # abort "$JAVA5_HOME/bin/javac does not exist or is not executable - JAVA5_HOME must point to a JDK (not JRE) 1.5 install dir." + # fi + # + # if ! "$JAVA5_HOME/bin/javap" java.lang.Enum >/dev/null 2>&1; then + # abort "java.lang.Enum not found - JAVA5_HOME ($JAVA5_HOME) version appears to be less than 1.5 - version must be 1.5.x." + # fi + # + # if "$JAVA5_HOME/bin/javap" java.util.Deque >/dev/null 2>&1; then + # abort "java.util.Deque found - JAVA5_HOME ($JAVA5_HOME) version appears to be greater than or equal to 1.6 - version must be 1.5.x." + # fi + #fi +} + + +#======================================================================================== +# Description: Validates that a compatible version of Maven is installed. +#======================================================================================== +validate_maven() +{ + # Make sure M2_HOME points to a valid Maven 2.1.x or 2.2.x install. + MINIMUM_MAVEN_VERSION="2.1.0" + + if [ -z "$M2_HOME" ]; then + abort "M2_HOME environment variable is not set - M2_HOME must point to a Maven, $MINIMUM_MAVEN_VERSION or later, install dir." + fi + + if [ ! -d "$M2_HOME" ]; then + abort "M2_HOME ($M2_HOME) does not exist or is not a directory - M2_HOME must point to a Maven, $MINIMUM_MAVEN_VERSION or later, install dir." + fi + + echo "Prepending $M2_HOME/bin to PATH..." + PATH="$M2_HOME/bin:$PATH" + + if ! which mvn >/dev/null 2>&1; then + abort "mvn not found in PATH ($PATH) - M2_HOME must point to a Maven, $MINIMUM_MAVEN_VERSION or later, install dir." + fi + + mvn -version >/dev/null + [ $? -ne 0 ] && abort "mvn --version failed with exit code $?." + MAVEN_VERSION=`mvn -version | head -1 | sed 's|[^0-9]*([^ ]*).*|\1|'` + if echo $MAVEN_VERSION | grep -Ev "^(2.[12]|3.0)"; then + abort "Unsupported Maven version - $MAVEN_VERSION. Only Maven 2.1.x, 2.2.x, or 3.0.x is supported. Please update the value of M2_HOME, then try again." + fi +} + + +#======================================================================================== +# Description: Validates that a compatible version of Git is installed. +#======================================================================================== +validate_git() +{ + # Make sure git 1.6.x or 1.7.x is in the PATH. + + if ! which git >/dev/null 2>&1; then + abort "git not found in PATH ($PATH)." + fi + + git --version >/dev/null + [ $? -ne 0 ] && abort "git --version failed with exit code $?." + GIT_VERSION=`git --version | sed 's|[^0-9]*([^ ]*).*|\1|'` + if echo $GIT_VERSION | grep -v "^1.[67]"; then + abort "Unsupported git version - $GIT_VERSION. Only git 1.6.x or 1.7.x are supported. Please add a directory containing a supported version of git to your PATH, then try again." + fi +} + + +#======================================================================================== +# Description: Prints the input string centered. +#======================================================================================== +print_centered() +{ + max_length=90 + string_length=${#1} + + if [ $string_length -ge `expr $max_length - 2` ] + then + echo $1 + return 0 + fi + + left_side=`expr $max_length - $string_length` + left_side=`expr $left_side / 2` + + is_odd_number=$(( $string_length % 2 )) + if [ $is_odd_number -eq 0 ] + then + right_side=$left_side + else + right_side=`expr $left_side + 1 ` + fi + + eval "printf '=%.0s' {1..${left_side}}" + printf " $1 " + eval "printf '=%.0s' {1..${right_side}}" + printf "\n" +} + + +#======================================================================================== +# Description: Sets the script in debug mode; this will print all the commands before +# executing them. +#======================================================================================== +set_script_debug_mode() +{ + if [ -n "$1" ] && [ "$1" ]; + then + set -x + else + set +x + fi +} + + +#======================================================================================== +# Description: Resets the script in debug mode; this will stop printing all the commands +# before executing them. +#======================================================================================== +unset_script_debug_mode() +{ + set +x +} + + +#======================================================================================== +# Description: Print function information (name and parameters). +#======================================================================================== +print_function_information() +{ + function_name=$1 + shift + + function_parameters=$(printf ", %s " "$@") + function_parameters=${function_parameters:1} + + echo "+ $function_name ($function_parameters)" +} +
rhq-commits@lists.fedorahosted.org