#!/bin/bash function show_title() { echo "RK_HOME: $RK_HOME" echo "O---------------------------------------------O" echo echo " $rk_name "; echo " $rk_fullname "; echo echo "O---------------------------------------------O" } function show_help { echo "usage: {rk2|rk3|sork2|sork2|cdrk2|derk|clientrk} [-help|-cmd] [ANT_ARGS]" echo " -help show this help screen" echo " -cmd show the ant command being used by the releas kit" echo " ANT_ARGS additional arguments to be passed to ant" } #determine requested release kit rk_name=$(basename "$0") rk_dirname=$(dirname "$0") export RK_HOME=$(cd "$rk_dirname/.." && pwd) if [ "$rk_name" == "rk2" ]; then rk_fullname="Release Kit for Greenstone2" elif [ "$rk_name" == "rk3" ]; then rk_fullname="Release Kit for Greenstone3" elif [ "$rk_name" == "sork2" ]; then rk_fullname="Source Code Release Kit for Greenstone2" elif [ "$rk_name" == "sork3" ]; then rk_fullname="Source Code Release Kit for Greenstone3" elif [ "$rk_name" == "cdrk2" ]; then rk_fullname="CD-ROM Release Kit for Greenstone2" elif [ "$rk_name" == "derk" ]; then rk_fullname="Documented Examples Release Kit" elif [ "$rk_name" == "clientrk" ]; then rk_fullname="Standalone Client-GLI Release Kit" else show_help exit fi #make sure ant has enough memory GSDLOS=`uname -s` if [ "x$GSDLOS" = "xDarwin" ] ; then export ANT_OPTS=-Xmx2048M else #export ANT_OPTS=-Xmx1024M export ANT_OPTS=-Xmx2048M fi # Ensure there is a self-extracting jre, or generate one for this OS and bitness SHARED_DIR="$RK_HOME/shared" # HOME_DIR is gs-release-builder directory HOME_DIR=$(cd "$RK_HOME/.." && pwd) if [ -d "$HOME_DIR/ext-cli/selfcontained-jdk64" ] ; then target_bitness=64 jre_suffix=_x64 jre_download_suffix=$jre_suffix elif [ -d "$HOME_DIR/ext-cli/selfcontained-jdk32" ] ; then target_bitness=32 jre_suffix="" jre_download_suffix="_i686" fi if [ "x$GSDLOS" = "xDarwin" ] ; then shared_os_name=mac else shared_os_name=linux fi #echo "#### GSDLOS: $GSDLOS" #if [ -e "$SHARED_DIR/$shared_os_name/jre.tar" ] ; then # echo "Removing jre.tar " # rm -f "$SHARED_DIR/$shared_os_name/jre.tar" #fi # To change the bundled self-extracting Java from packages/JRE into the self-contained JDK # (or even packages/jdk) involved editing some 20 files in the release-kits (not all successfully) # and this could break the Greenstone CD-ROM and GS2 as they will remain untested. # And a tarred up self-extracting JRE is 26Mb versus 163 Mb for the self-extracting JDK. # To ensure the cd-rom and release-kit's many uses of the self-extracting packages/jre # don't get messed up and remains minimally sized, the java used to unpack and # run the GS2 and GS3 installer will always be a JRE. However, for GS3 we will remove the # packages/jre after installation so that the self-contained JDK will be available for use. # It is only GS3 that has Java tomcat (GS2 has apache httpd) and can support jsp pages # for which the bundled JDK's javac compiler would be useful. # If there's already a self-extracting jre for the OS, don't generate a new one # (For example, we may have manually created one from a downloaded JRE and committed # that self-extracting JRE to SVN. In which case it would get pulled automatically) # else if a self-extracting jre does not already exist # if a jre folder doesn't exist either # use jlink to generate a jre folder from the selfcontained-jdk we're using to compile GS # generate a self-extracting jre from the jre folder after first tarring it up # delete the jre folder (leave the jre.tar until this script is re-run: allows debugging jre) if [ -f "$SHARED_DIR/$shared_os_name/jre_bin${jre_suffix}" ] ; then echo "@@@ Found self-extracting JRE at $SHARED_DIR/$shared_os_name/jre_bin${jre_suffix}" echo " Will use this." else echo "@@@ NO self-extracting JRE at $SHARED_DIR/${shared_os_name}/jre_bin${jre_suffix}." selfcon_jdk="$HOME_DIR/ext-cli/selfcontained-jdk"* zulu_jdk="$HOME_DIR/ext-cli/selfcontained-jdk"*"/zulu-jdk"* pushd "$SHARED_DIR/$shared_os_name" if [ ! -d "jre" ] && [ ! -f "jre.tar" ] ; then if [ -z "target_bitness" ] ; then echo "!!! WARNING: can't locate $HOME_DIR/ext-cli/selfcontained-jdk* to generate self-extracting jre" else echo "" echo "**************************************************************" echo "" echo " Detected no $SHARED_DIR/${shared_os_name}/jre_bin${jre_suffix} (self-extracting JRE)" # echo " Assuming this means you want a JRE generated from the selfcontained-jdk" echo " Assuming this means you want a JRE matching the version of the selfcontained-jdk" echo " and for it to be made into a self-extracting JRE" echo "" echo "**************************************************************" echo "" # https://wiki.greenstone.org/doku.php?id=internal:building_a_complete_jre_from_jdk_11 # Per the 2nd chat with Gemini, the following is the closest equivalent we can get # to a downloaded zulu JRE. So far, this is able to startup solr at least. # "${zulu_jdk}/bin/jlink" --module-path "${zulu_jdk}/jmods" \ # --add-modules java.se,jdk.unsupported,jdk.management,jdk.management.agent,jdk.crypto.ec,jdk.charsets,jdk.localedata,jdk.zipfs,jdk.net,jdk.httpserver,jdk.accessibility,jdk.xml.dom,jdk.scripting.nashorn,jdk.scripting.nashorn.shell,jdk.naming.ldap,jdk.sctp,jdk.jsobject,jdk.aot,jdk.pack,jdk.jcmd,jdk.jdi,jdk.hotspot.agent \ # --bind-services \ # --output jre # source jdkversion-settings.sh to get at the version # of the JDK we are compiling the nightlies with pushd $selfcon_jdk # don't put this in quotes, else the tab completion/file globbing doesn't work . ./jdkversion-settings.sh popd # Now we have variables majorversion=11, bitness=64 and fullversion=11.82.19-ca-jdk11.0.28 #https://stackoverflow.com/questions/3306007/replace-a-string-in-shell-script-using-a-variable find="jdk" replace="jre" jre_version=${fullversion//$find/$replace} # Will build up to # https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jre11.0.28-linux_x64.tar.gz # https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jre11.0.28-linux_i686.tar.gz # curl https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jre11.0.28-macosx_x64.tar.gz jre_file=zulu${jre_version} # prefix echo "" echo "### Going to try downloading JRE:" echo " Version: $jre_version" # The Darwin JRE download once extracted has structure. Need to move and rename the jre within it if [ "x$GSDLOS" = "xDarwin" ] ; then # curl https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jre11.0.28-macosx_x64.tar.gz jre_file=${jre_file}-macosx${jre_download_suffix} jre_url=https://cdn.azul.com/zulu/bin/${jre_file}.tar.gz echo " File : ${jre_file}.tar.gz" echo " URL : $jre_url" echo "" curl $jre_url > ${jre_file}.tar.gz tar -xvzf ${jre_file}.tar.gz mv "${jre_file}/zulu-${majorversion}.jre/Contents/Home" "jre" rm -rf "$jre_file" else # https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jre11.0.28-linux_x64.tar.gz jre_file=${jre_file}-linux${jre_download_suffix} jre_url=https://cdn.azul.com/zulu/bin/${jre_file}.tar.gz echo " File : ${jre_file}.tar.gz" echo " URL : $jre_url" echo "" wget --no-check-certificate $jre_url tar -xvzf ${jre_file}.tar.gz mv $jre_file "jre" fi rm "${jre_file}.tar.gz" # Now we should have downloaded (or generated) a jre folder echo "********************************************" echo "Will now generate the self-extracting jre" echo "You may want to commit it." echo "********************************************" echo "" fi elif [ -d "jre" ] ; then # a jre folder pre-existed echo "" echo "**************************************************************" echo "" echo " Detected a jre folder, but no self-extracting jre at" echo " $SHARED_DIR/${shared_os_name}/jre_bin${jre_suffix}" echo " Assuming you mean to turn the jre folder into a self-extracting JRE" echo " Beware that the jre folder will be removed after this." echo "" echo "**************************************************************" echo "" else # there was a jre.tar file in the folder echo "" echo "**************************************************************" echo "" echo " Detected a jre.jar, but no jre folder nor self-extracting jre at" echo " $SHARED_DIR/${shared_os_name}/jre_bin${jre_suffix}" echo " Assuming you mean to turn the jre.tar into a self-extracting JRE" echo " The jre.tar will be left around for the future." echo "" echo "**************************************************************" echo "" fi # We either generated or downloaded a jre folder above, or a Developer could have put # a downloaded extracted jre into the shared/ folder or a jre.tar was left from # the past occasions. Either way, if there's a jre folder, the following will generate # a self-extracting jre of it if [ -d jre ] ; then if [ -f jre.tar ] ; then rm -f jre.tar fi # tar the jre folder and turn that jre.tar into a self-extracting JRE tar -cvf jre.tar jre # Remove jre folder, so it's not around next time to trigger this generate process rm -rf jre fi if [ -e jre.tar ] ; then parent_of_7za=$SHARED_DIR/${shared_os_name}/p7z-essentials if [ "x$GSDLOS" = "xLinux" ] ; then parent_of_7za=$parent_of_7za/${target_bitness}-bit fi $parent_of_7za/7za a -sfx -mx=9 jre_bin${jre_suffix} jre.tar # Remove jre.tar, so it's not around next time to trigger this generate process rm -f jre.tar fi # Ensure there's execute permissions on the jre_bin chmod u+x jre_bin${jre_suffix} # It's OK if the user forgets to commit the self-extracting jre, as its local presence # hereafter will prevent triggering the regeneration of the self-extracting JRE, # so we also won't keep downloading the JRE from azure at each nightly build # undo pushd into release-kits/shared/os popd fi if [ "x$JAVACFLAGS" = "x" ] ; then echo "****" >&2 echo "Warning: Expected to have JAVACFLAGS set. Have your sourced rk3-setup.bassh?" >&2 echo "****" >&2 echo "Sleeping for 5 seconds then continuing, unless ^C is pressed" >&2 sleep 5 fi #create the command toexec="ant -lib \"`pwd`/installer/classes\" -f \"$RK_HOME/kits/$rk_name/ant-scripts/build.xml\" \"-Dbasedir=`pwd`\" \"-Drk.home=$RK_HOME\" \"-Drk.name=$rk_name\"" # Generally, an ant property can be true|on|yes vs false|off|no (or left unset) # see https://ant.apache.org/manual/properties.html#if+unless # However, the release-kit code requires envvar KEEP_SRC to be "true" in order to stop it deleting source code # set KEEP_SRC env var here or in envi/etc/tasks/snapshot/environment.pl #KEEP_SRC=true #echo "KEEP_SRC: $KEEP_SRC" if test -n $KEEP_SRC ; then toexec="$toexec \"-Dkeep.src=$KEEP_SRC\"" fi show_cmd=false #pass on the arguments while [ "$1" != "" ]; do if [ "$1" == "-help" ]; then show_help exit elif [ "$1" == "-cmd" ]; then show_cmd=true else toexec="$toexec \"$1\"" fi shift done #show the command to be executed if [ "$show_cmd" == "true" ]; then echo "" echo export JAVACFLAGS=$JAVACFLAGS echo "" echo $toexec echo "" #execute else show_title | tee ${rk_name}.out bash -c "$toexec" 2>&1 | tee -a ${rk_name}.out fi