installer.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # /////////////////////////////////////////////////////////////////////////////
  2. # REFCODES.ORG
  3. # =============================================================================
  4. # This code is copyright (c) by Siegfried Steiner, Munich, Germany and licensed
  5. # under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
  6. # licenses:
  7. # =============================================================================
  8. # GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
  9. # =============================================================================
  10. # Apache License, v2.0 ("http://www.apache.org/licenses/LICENSE-2.0")
  11. # =============================================================================
  12. # Please contact the copyright holding author(s) of the software artifacts in
  13. # question for licensing issues not being covered by the above listed licenses,
  14. # also regarding commercial licensing models or regarding the compatibility
  15. # with other open source licenses.
  16. # /////////////////////////////////////////////////////////////////////////////
  17. #!/bin/bash
  18. # ------------------------------------------------------------------------------
  19. # INIT:
  20. # ------------------------------------------------------------------------------
  21. CURRENT_PATH="$(pwd)"
  22. SCRIPT_PATH="$(dirname $0)"
  23. cd "${SCRIPT_PATH}"
  24. SCRIPT_PATH="$(pwd)"
  25. cd "${CURRENT_PATH}"
  26. SCRIPT_DIR="${SCRIPT_PATH##*/}"
  27. SCRIPT_NAME="$(basename $0 .sh)"
  28. PARENT_PATH="$(realpath $(dirname $0)/..)"
  29. PARENT_DIR="${PARENT_PATH##*/}"
  30. MODULE_NAME="$(echo -e "${SCRIPT_DIR}" | cut -d- -f3- )"
  31. if [ -z "${MODULE_NAME}" ]; then
  32. MODULE_NAME="$(echo -e "${SCRIPT_DIR}" | cut -d- -f2- )"
  33. if [ -z "${MODULE_NAME}" ]; then
  34. MODULE_NAME="${SCRIPT_DIR}"
  35. fi
  36. fi
  37. # ------------------------------------------------------------------------------
  38. # ANSI ESCAPE CODES:
  39. # ------------------------------------------------------------------------------
  40. ESC_BOLD="\E[1m"
  41. ESC_FAINT="\E[2m"
  42. ESC_FG_RED="\E[31m"
  43. ESC_FG_GREEN="\E[32m"
  44. ESC_FG_YELLOW="\E[33m"
  45. ESC_FG_BLUE="\E[34m"
  46. ESC_FG_MAGENTA="\E[35m"
  47. ESC_FG_CYAN="\E[36m"
  48. ESC_FG_WHITE="\E[37m"
  49. ESC_RESET="\E[0m"
  50. # ------------------------------------------------------------------------------
  51. # PRINTLN:
  52. # ------------------------------------------------------------------------------
  53. function printLn {
  54. char="-"
  55. if [[ $# == 1 ]] ; then
  56. char="$1"
  57. fi
  58. echo -en "${ESC_FAINT}"
  59. printf '%*s' "${COLUMNS:-$(tput cols)}" '' | tr ' ' ${char}
  60. echo -en "${ESC_RESET}"
  61. }
  62. # ------------------------------------------------------------------------------
  63. # QUIT:
  64. # ------------------------------------------------------------------------------
  65. function quit {
  66. input=""
  67. while ([ "$input" != "q" ] && [ "$input" != "y" ]); do
  68. echo -ne "> Continue? Enter [${ESC_BOLD}q${ESC_RESET}] to quit, [${ESC_BOLD}y${ESC_RESET}] to continue: ";
  69. read input;
  70. done
  71. # printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
  72. if [ "$input" == "q" ] ; then
  73. printLn
  74. echo -e "> ${ESC_BOLD}Aborting due to user input.${ESC_RESET}"
  75. exit
  76. fi
  77. }
  78. # ------------------------------------------------------------------------------
  79. # BANNER:
  80. # ------------------------------------------------------------------------------
  81. function printBanner {
  82. figlet -w 180 "/${MODULE_NAME}:>>>${SCRIPT_NAME}..." 2> /dev/null
  83. if [ $? -ne 0 ]; then
  84. banner "${SCRIPT_NAME}..." 2> /dev/null
  85. if [ $? -ne 0 ]; then
  86. echo -e "> ${SCRIPT_NAME}:" | tr a-z A-Z
  87. fi
  88. fi
  89. }
  90. printBanner
  91. # ------------------------------------------------------------------------------
  92. # HELP:
  93. # ------------------------------------------------------------------------------
  94. function printHelp {
  95. printLn
  96. echo -e "Usage: ${ESC_BOLD}${SCRIPT_NAME}${ESC_RESET}.sh -h"
  97. printLn
  98. echo -e "Creates an MSI (*.msi) installer including a JRE for Microsoft boxes."
  99. printLn
  100. echo -e "${ESC_BOLD}-h${ESC_RESET}: Print this help"
  101. printLn
  102. }
  103. if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
  104. printHelp
  105. exit 0
  106. fi
  107. # ------------------------------------------------------------------------------
  108. # MAIN:
  109. # ------------------------------------------------------------------------------
  110. targetPath="${SCRIPT_PATH}/target"
  111. moduleName=$(xml2 < "${SCRIPT_PATH}/pom.xml" 2>/dev/null | grep "/project/artifactId=")
  112. moduleName="${moduleName#/project/artifactId=}"
  113. if [ -z "${moduleName}" ]; then
  114. moduleName=$(mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.artifactId -q -DforceStdout)
  115. fi
  116. if [ ! -e "${targetPath}" ] ; then
  117. echo -e "> ${ESC_BOLD}Folder <${targetPath}> does not exist, aborting!${ESC_RESET}" 1>&2;
  118. exit 1
  119. fi
  120. cd "${targetPath}"
  121. jarFile=$(find . -name "${moduleName}*.jar" ! -name "*tests.jar" ! -name "*sources.jar")
  122. binName="$1"
  123. if [ -z "${binName}" ]; then
  124. binName="$(echo -e "${moduleName}" | cut -d- -f2- )"
  125. if [ -z "${binName}" ]; then
  126. binName="${moduleName}"
  127. fi
  128. fi
  129. version="$(xml2 <"${SCRIPT_PATH}/pom.xml" | grep "/project/version=")"
  130. version="${version#/project/version=}"
  131. version="${version%-SNAPSHOT}"
  132. version="${version%-RELEASE}"
  133. if [ -z "${version}" ]; then
  134. version="0.0.1"
  135. fi
  136. if [ ! -e "${jarFile}" ] ; then
  137. echo -e "> ${ESC_BOLD}No JAR file found for module <${moduleName}> in folder <${targetPath}>, aborting!${ESC_RESET}" 1>&2;
  138. exit 1
  139. fi
  140. isExecutable=$(unzip -q -c ${jarFile} META-INF/MANIFEST.MF | grep "Main-Class:")
  141. if [ -z "${isExecutable}" ] ; then
  142. echo -e "> ${ESC_BOLD}JAR file at <${jarFile}> is not executable, aborting!${ESC_RESET}" 1>&2;
  143. exit 1
  144. fi
  145. echo -e "> Creating <${ESC_BOLD}${binName}${ESC_RESET}> installer with version <${ESC_BOLD}${version}${ESC_RESET}>..."
  146. # echo -e "> Invoking <${ESC_BOLD}jpackage --win-dir-chooser --win-shortcut --win-console --input "." --name "${binName}" --app-version "${version}" --icon "../src/main/resources/application.ico" --main-jar "${jarFile}" --type msi${ESC_RESET}>"
  147. result=$(jpackage --win-dir-chooser --win-shortcut --win-console --input "." --name "${binName}" --app-version "${version}" --icon "../src/main/resources/application.ico" --main-jar "${jarFile}" --type msi 2>&1)
  148. if (($? != 0)); then
  149. echo ""
  150. echo "${result}"
  151. echo ""
  152. echo -e "> ${ESC_BOLD}Cannot create installer, aborting!${ESC_RESET}"
  153. else
  154. echo -e "> Created MSI installer <${ESC_BOLD}${binName}-${version}.msi${ESC_RESET}> at <${ESC_BOLD}${targetPath}${ESC_RESET}>"
  155. fi
  156. cd "${CURRENT_PATH}"