123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- # /////////////////////////////////////////////////////////////////////////////
- # REFCODES.ORG
- # =============================================================================
- # This code is copyright (c) by Siegfried Steiner, Munich, Germany and licensed
- # under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
- # licenses:
- # =============================================================================
- # GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
- # =============================================================================
- # Apache License, v2.0 ("http://www.apache.org/licenses/LICENSE-2.0")
- # =============================================================================
- # Please contact the copyright holding author(s) of the software artifacts in
- # question for licensing issues not being covered by the above listed licenses,
- # also regarding commercial licensing models or regarding the compatibility
- # with other open source licenses.
- # /////////////////////////////////////////////////////////////////////////////
- #!/bin/bash
- # ------------------------------------------------------------------------------
- # INIT:
- # ------------------------------------------------------------------------------
- TARGET_DIR="target"
- CURRENT_PATH="$(pwd)"
- SCRIPT_PATH="$(dirname $0)"
- cd "${SCRIPT_PATH}"
- SCRIPT_PATH="$(pwd)"
- cd "${CURRENT_PATH}"
- SCRIPT_DIR="${SCRIPT_PATH##*/}"
- SCRIPT_NAME="$(basename $0 .sh)"
- PARENT_PATH="$(realpath $(dirname $0)/..)"
- PARENT_DIR="${PARENT_PATH##*/}"
- MODULE_NAME="$(echo -e "${SCRIPT_DIR}" | cut -d- -f3- )"
- if [ -z "${MODULE_NAME}" ]; then
- MODULE_NAME="$(echo -e "${SCRIPT_DIR}" | cut -d- -f2- )"
- if [ -z "${MODULE_NAME}" ]; then
- MODULE_NAME="${SCRIPT_DIR}"
- fi
- fi
- if [ -z ${COLUMNS} ] ; then
- export COLUMNS=$(tput cols)
- fi
- # ------------------------------------------------------------------------------
- # ANSI ESCAPE CODES:
- # ------------------------------------------------------------------------------
- ESC_BOLD="\E[1m"
- ESC_FAINT="\E[2m"
- ESC_FG_RED="\E[31m"
- ESC_FG_GREEN="\E[32m"
- ESC_FG_YELLOW="\E[33m"
- ESC_FG_BLUE="\E[34m"
- ESC_FG_MAGENTA="\E[35m"
- ESC_FG_CYAN="\E[36m"
- ESC_FG_WHITE="\E[37m"
- ESC_RESET="\E[0m"
- # ------------------------------------------------------------------------------
- # PRINTLN:
- # ------------------------------------------------------------------------------
- function printLn {
- char="-"
- if [[ $# == 1 ]] ; then
- char="$1"
- fi
- echo -en "${ESC_FAINT}"
- for (( i=0; i< ${COLUMNS}; i++ )) ; do
- echo -en "${char}"
- done
- echo -e "${ESC_RESET}"
- }
- # ------------------------------------------------------------------------------
- # QUIT:
- # ------------------------------------------------------------------------------
- function quit {
- input=""
- while ([ "$input" != "q" ] && [ "$input" != "y" ]); do
- echo -ne "> Continue? Enter [${ESC_BOLD}q${ESC_RESET}] to quit, [${ESC_BOLD}y${ESC_RESET}] to continue: ";
- read input;
- done
- # printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
- if [ "$input" == "q" ] ; then
- printLn
- echo -e "> ${ESC_BOLD}Aborting due to user input.${ESC_RESET}"
- cd "${CURRENT_PATH}"
- exit 1
- fi
- }
- # ------------------------------------------------------------------------------
- # BANNER:
- # ------------------------------------------------------------------------------
- function printBanner {
- figlet -w 180 "/${MODULE_NAME}:>>>${SCRIPT_NAME}..." 2> /dev/null
- if [ $? -ne 0 ]; then
- banner "${SCRIPT_NAME}..." 2> /dev/null
- if [ $? -ne 0 ]; then
- echo -e "> ${SCRIPT_NAME}:" | tr a-z A-Z
- fi
- fi
- }
- printBanner
- # ------------------------------------------------------------------------------
- # HELP:
- # ------------------------------------------------------------------------------
- function printHelp {
- printLn
- echo -e "Usage: ${ESC_BOLD}${SCRIPT_NAME}${ESC_RESET}.sh [ -h ] | [ <appName> [ <appVersion> ] ]"
- printLn
- echo -ne "jEXEfy all this project in case an executable jar JAR file is found, e.g. a fat self-executable executable is created if applicable. "
- echo -ne "In case there is a <${ESC_BOLD}${SCRIPT_NAME}.conf${ESC_RESET}> file, then the ${ESC_BOLD}APP_NAME${ESC_RESET} property is used as ${ESC_BOLD}<appName>${ESC_RESET} and the ${ESC_BOLD}APP_VERSION${ESC_RESET} property is used as the ${ESC_BOLD}<appVersion>${ESC_RESET} (if not specified other on the command line). "
- echo -e "An empty version declaration or a version specified as ${ESC_BOLD}\"-1\"${ESC_RESET} denotes that no version is to be used in the resulting filename!"
- printLn
- echo -e " ${ESC_BOLD}<appName>${ESC_RESET}: The name of the file to be created (optional)."
- echo -e "${ESC_BOLD}<appVersion>${ESC_RESET}: The version of the file with <appName> to be created (optional)."
- echo -e " ${ESC_BOLD}-h${ESC_RESET}: Print this help"
- printLn
- }
- if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
- printHelp
- exit 0
- fi
- # ------------------------------------------------------------------------------
- # JEXEFY:
- # ------------------------------------------------------------------------------
- function jexefy {
- local jarFile=$1
- local launcher=$2
- local targetPath=$3
- local binName=$4
- local arch=${launcher/jexefy-launcher-/}
- if [[ $arch = *.exe ]] ; then
- arch="${arch/\.exe/}"
- arch="Windows-${arch}"
- fi
- if [[ $arch = *.elf ]] ; then
- arch="${arch/\.elf/}"
- arch="Linux-${arch}"
- fi
- binFile="${targetPath}/${binName}"
- cat "${SCRIPT_PATH}/${launcher}" "${jarFile}" > "${binFile}" && chmod +x ${binFile}
- if (($? != 0)); then
- echo -e "> ${ESC_BOLD}Unable to create executable <${binName}> at <${targetPath}>!${ESC_RESET}" 1>&2;
- exit 1
- fi
- echo -e "> Created executable <${ESC_BOLD}${binName}${ESC_RESET}> for <${ESC_BOLD}${arch}${ESC_RESET}> at <${ESC_BOLD}${targetPath}${ESC_RESET}>!"
- }
- # ------------------------------------------------------------------------------
- # LAUNCHER NAME:
- # ------------------------------------------------------------------------------
- function toLauncherBaseName {
- local moduleName=$1
- local moduleVersion=$2
- local suffix=$3
- local arch=$4
- local argBinName=$5
- local confBinName=$6
- local argVersion=$7
- local confVersion=$8
-
- local binVersion="${argVersion}"
- if [ -z "${binVersion}" ]; then
- binVersion="${confVersion}"
- if [ -z "${binVersion}" ]; then
- binVersion="${moduleVersion}"
- fi
- fi
- local binName="${argBinName}"
- if [ ! -z "${binName}" ]; then
- if [ ! -z "${argVersion}" ] && [ "${argVersion}" != "-1" ] ; then
- binName="${binName}-${argVersion}"
- fi
- else
- binName=${confBinName}
- if [ ! -z "${binName}" ]; then
- if [[ "${binVersion}" == "-1" ]] ; then
- binName="${binName}"
- else
- binName="${binName}-${binVersion}"
- fi
- else
- binName="$(echo -e "${moduleName}" | cut -d- -f3- )"
- if [ -z "${binName}" ]; then
- binName="$(echo -e "${moduleName}" | cut -d- -f2- )"
- if [ -z "${binName}" ]; then
- binName="${moduleName}"
- fi
- fi
- if [[ "${binVersion}" == "-1" ]] ; then
- binName="${binName}-launcher-${arch}"
- else
- binName="${binName}-launcher-${arch}-${binVersion}"
- fi
- fi
- fi
- echo "${binName}.${suffix}"
- }
- # ------------------------------------------------------------------------------
- # MAIN:
- # ------------------------------------------------------------------------------
- CONF_PATH="${SCRIPT_PATH}/${SCRIPT_NAME}.conf"
- if [ -f "${CONF_PATH}" ]; then
- . ${CONF_PATH}
- fi
- moduleName=$(xml2 < "${SCRIPT_PATH}/pom.xml" 2>/dev/null | grep "/project/artifactId=")
- moduleName="${moduleName#/project/artifactId=}"
- if [ -z "${moduleName}" ]; then
- moduleName=$(mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.artifactId -q -DforceStdout)
- fi
- moduleVersion="$(xml2 <"${SCRIPT_PATH}/pom.xml" | grep "/project/version=")"
- moduleVersion="${moduleVersion#/project/version=}"
- moduleVersion="${moduleVersion/-SNAPSHOT}"
- moduleVersion="${moduleVersion/-RELEASE}"
- if [ -z "${moduleVersion}" ]; then
- moduleVersion=$(mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version -q -DforceStdout)
- if [ -z "${moduleVersion}" ]; then
- moduleVersion="X.Y.Z"
- else
- moduleVersion="${moduleVersion#/project/version=}"
- moduleVersion="${moduleVersion/-SNAPSHOT}"
- moduleVersion="${moduleVersion/-RELEASE}"
- fi
- fi
- targetPath="${SCRIPT_PATH}/${TARGET_DIR}"
- if [ ! -e "${targetPath}" ] ; then
- echo -e "> ${ESC_BOLD}Folder <${targetPath}> does not exist, aborting!${ESC_RESET}" 1>&2;
- exit 1
- fi
- jarFile=$(find "${targetPath}" -name "${moduleName}*.jar" ! -name "*tests.jar" ! -name "*sources.jar")
- if [ ! -e "${jarFile}" ] ; then
- echo -e "> ${ESC_BOLD}No JAR file found for module <${moduleName}> in folder <${targetPath}>, aborting!${ESC_RESET}" 1>&2;
- exit 1
- fi
- if command -v "unzip" &> /dev/null ; then
- isExecutable=$(unzip -q -c ${jarFile} META-INF/MANIFEST.MF | grep "Main-Class:")
- if [ -z "${isExecutable}" ] ; then
- echo -e "> ${ESC_BOLD}JAR file at <${jarFile}> is not executable, aborting!${ESC_RESET}" 1>&2;
- exit 1
- fi
- fi
- argAppName="$1"
- argAppVersion="$2"
- if [ -v APP_VERSION ] && [ -z "${APP_VERSION}" ] ; then
- APP_VERSION=-1
- fi
- jexefy "${jarFile}" "jexefy-launcher-x86_64.elf" "${targetPath}" "$(toLauncherBaseName "${moduleName}" "${moduleVersion}" "elf" "x86_64" "${argAppName}" "${APP_NAME}" "${argAppVersion}" "${APP_VERSION}")"
- jexefy "${jarFile}" "jexefy-launcher-x86_64.exe" "${targetPath}" "$(toLauncherBaseName "${moduleName}" "${moduleVersion}" "exe" "x86_64" "${argAppName}" "${APP_NAME}" "${argAppVersion}" "${APP_VERSION}")"
- cd "${CURRENT_PATH}"
|