1 Reply Latest reply on Dec 15, 2003 5:10 AM by chrisgrze

    Nukes build script

    chrisgrze Newbie

      Here is a BASH script i wrote and used to deploy nukes. It worked for me with a little effort ( because of my first post ); in general it doesnt handle errors very gracefully. But given no errors occur it is the shortest path between CVS -> running nukes.

      Just copy/paste into a file ( buildNuke ) then:

      chmod +x buildNuke
      export JBOSS_HOME="/your/jboss/home/dir"
      ./buildNuke all-cvs

      Enter the DB password a whole bunch of times,

      then hit http://your.domain.com:8080/nukes/

      I wrote it in an hour or so, so i definitly wouldnt use this in anything but testing ( i added a flag --nodb which skips all steps that would otherwise either cause alot of complaining, or trash your DB ).

      It also only supports MySQL.

      If anyone wants to let me know how it works for them where it fails etc, i can make it a little better/cleaner, and info about the HSQL setup too.

      -d

      p.s. be sure to execute it in the directory nukes/ directory unless you are pulling from CVS, since the dir doesnt exist then ;-)

      ------------------------------------------------------------------------------------------

      #JBOSS_HOME="/apps/jboss"
      #export JBOSS_HOME
      #NUKES_HOME="/root/nukes"
      SKIP_DB="false"

      yellow="\033[1;33m"
      bold_red="\033[1;31m"
      bold_blue="\033[1;34m"
      reset="\033[0m"


      buildAll()
      {
      if [[ "${SKIP_DB}" == "true" ]]
      then
      echo -e "${reset}Skipping ${bold_red}Database setup!"
      else
      initDb
      fi
      echo -e "${reset}Creating ${bold_red}${JBOSS_HOME}/server/default/nukes${reset}"
      mkdir ${JBOSS_HOME}/server/default/nukes
      echo -e "${reset}Copying ${bold_red}${NUKES_HOME}/nukes/src/resources/mysql/nukes-ds.xml to ${JBOSS_HOME}/server/default/deploy/${reset}"
      cp ${NUKES_HOME}/nukes/src/resources/mysql/nukes-ds.xml ${JBOSS_HOME}/server/default/deploy/
      echo -e "${reset}Copying ${bold_red}${NUKES_HOME}/build/etc/local.properties-mysql ${NUKES_HOME}/build/local.properties${reset}"
      cp ${NUKES_HOME}/build/etc/local.properties-mysql ${NUKES_HOME}/build/local.properties
      echo -e "${reset}Running ${bold_red}${NUKES_HOME}/build/build.sh${reset}"
      ${NUKES_HOME}/build/build.sh
      echo -e "${reset}Running ${bold_red}${NUKES_HOME}/nukes/build.sh deploy${reset}"
      ${NUKES_HOME}/nukes/build.sh deploy
      buildModule bb
      buildModule adminmessages
      buildModule faq
      buildModule journal
      buildModule list
      buildModule mp3player
      buildModule news
      buildModule polls
      buildModule quotes
      buildModule script
      buildModule sections
      }

      grabCvs()
      {
      cvs -d:pserver:anonymous@cvs.jboss.sourceforge.net:/cvsroot/jboss co nukes
      }

      initDb()
      {
      echo -e "${bold_blue}Init DB, enter password:${reset}"
      mysql -u root -p < $NUKES_HOME/nukes/src/resources/mysql/prepare.ddl
      echo -e "${bold_blue}Loading schema, enter password:${reset}"
      mysql -u root -p nukes < $NUKES_HOME/nukes/src/resources/mysql/setup.ddl
      echo -e "${bold_blue}Reloading DB, enter password:${reset}"
      mysqladmin -u root -p reload
      }

      buildModule()
      {
      cd $NUKES_HOME
      MODULE=$1
      if [[ ${SKIP_DB} == "true" ]]
      then
      echo -e "${bold_blue}Skipping schema load for ${bold_red}${MODULE}${reset}"
      else
      echo -e "${bold_blue}Connecting to mysql to load schema for ${bold_red}${MODULE}${reset}"
      mysql -p nukes < $MODULE/src/resources/mysql/setup.ddl
      fi
      echo -e "${bold_blue}Building module ${bold_red}${MODULE}${reset}"
      $MODULE/build.sh
      echo -e "${bold_blue}Attempting to deploy ${bold_red}${MODULE}${reset}"
      $MODULE/build.sh deploy
      echo -e "${yellow}Deployed ${MODULE}${reset}"
      }

      #
      # What am i doing?!
      #
      if [[ "$#" -eq "0" ]]
      then
      echo -e "Usage: buildNuke [--nodb] TARGET"
      echo ""
      echo -e "--nodb\t -- Any db .ddl's are skipped ( if you already have that stuff setup )"
      echo ""
      echo -e "Valid TARGETs are:"
      echo ""
      echo -e "module\t -- any valid module"
      echo -e "\t\t( adminmessages, bb, jmx, journal, list, mp3player, news, \n\t\t nukes, polls, quotes, script, sections )"
      echo -e "\t\tThe validity of a module is verified by testing if NUKES_HOME/MODULE exists"
      echo -e "\t\tSo it is possible to do something like buildNuke build, even though its not a module"
      echo ""
      echo -e "all\t -- build the whole project"
      echo ""
      echo -e "all-cvs\t -- pull the latest CVS with co nukes, and build it"
      exit 1
      fi

      #
      # Need this
      #
      if [ -z ${JBOSS_HOME} ]
      then
      echo -e "${bold_red}Please set the JBOSS_HOME environment variable"
      exit 1
      fi

      #
      # This too
      #
      if [ -z ${NUKES_HOME} ]
      then
      echo -e "${bold_yellow}Assuming ${PWD} as the NUKES_HOME"
      echo -e "${bold_yellow}Otherwise set the NUKES_HOME environment variable"
      NUKES_HOME=${PWD}
      fi

      TARGET=$1

      #
      # Are we going to init the DB?
      #
      if [[ "${TARGET}" == "--nodb" ]]
      then
      TARGET=$2
      SKIP_DB="true"
      fi

      rm $NUKES_HOME/*/build.bat
      chmod +x $NUKES_HOME/*/build.sh

      #
      # Check the TARGET
      #
      if [ -e ${NUKES_HOME}/${TARGET} ]
      then
      buildModule $TARGET
      elif [[ "${TARGET}" == "all-cvs" ]]
      then
      grabCvs
      NUKES_HOME=${NUKES_HOME}/nukes
      buildAll
      elif [[ "${TARGET}" == "all" ]]
      then
      buildAll
      else
      echo -e "${TARGET} ${bold_red}NOT A VALID TARGET${reset}"
      fi