build.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #!/bin/bash
  2. #echo color
  3. WHITE_COLOR="\E[1;37m";
  4. RED_COLOR="\E[1;31m";
  5. BLUE_COLOR='\E[1;34m';
  6. GREEN_COLOR="\E[1;32m";
  7. YELLOW_COLOR="\E[1;33m";
  8. RES="\E[0m";
  9. printf "${GREEN_COLOR}\n"
  10. cat<<EOT
  11. --------------------------------------------
  12. / \\
  13. / ___ _ __ ___ _ __ ___ _ __ ___ _ __ \\
  14. / / _ \| '_ \ / _ \ '_ \ / __| '__/ _ \| '_ \\ \\
  15. / | (_) | |_) | __/ | | | (__| | | (_) | | | | \\
  16. \\ \___/| .__/ \___|_| |_|\___|_| \___/|_| |_| /
  17. \\ |_| /
  18. \\ /
  19. \\ --opencron,Let's crontab easy! /
  20. --------------------------------------------
  21. EOT
  22. printf "${RES}\n"
  23. echo_r () {
  24. # Color red: Error, Failed
  25. [ $# -ne 1 ] && return 1
  26. printf "[${BLUE_COLOR}opencron${RES}] ${RED_COLOR}$1${RES}\n"
  27. }
  28. echo_g () {
  29. # Color green: Success
  30. [ $# -ne 1 ] && return 1
  31. printf "[${BLUE_COLOR}opencron${RES}] ${GREEN_COLOR}$1${RES}\n"
  32. }
  33. echo_y () {
  34. # Color yellow: Warning
  35. [ $# -ne 1 ] && return 1
  36. printf "[${BLUE_COLOR}opencron${RES}] ${YELLOW_COLOR}$1${RES}\n"
  37. }
  38. echo_w () {
  39. # Color yellow: White
  40. [ $# -ne 1 ] && return 1
  41. printf "[${BLUE_COLOR}opencron${RES}] ${WHITE_COLOR}$1${RES}\n"
  42. }
  43. # Make sure prerequisite environment variables are set
  44. if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
  45. if $darwin; then
  46. # Bugzilla 54390
  47. if [ -x '/usr/libexec/java_home' ] ; then
  48. export JAVA_HOME=`/usr/libexec/java_home`
  49. # Bugzilla 37284 (reviewed).
  50. elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
  51. export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
  52. fi
  53. else
  54. JAVA_PATH=`which java 2>/dev/null`
  55. if [ "x$JAVA_PATH" != "x" ]; then
  56. JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`
  57. JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`
  58. fi
  59. if [ "x$JRE_HOME" = "x" ]; then
  60. # XXX: Should we try other locations?
  61. if [ -x /usr/bin/java ]; then
  62. JRE_HOME=/usr
  63. fi
  64. fi
  65. fi
  66. if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
  67. echo_r "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
  68. echo_r "At least one of these environment variable is needed to run this program"
  69. exit 1
  70. fi
  71. fi
  72. if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then
  73. echo_r "JAVA_HOME should point to a JDK in order to run in debug mode."
  74. exit 1
  75. fi
  76. if [ -z "$JRE_HOME" ]; then
  77. JRE_HOME="$JAVA_HOME"
  78. fi
  79. # If we're running under jdb, we need a full jdk.
  80. if [ "$1" = "debug" ] ; then
  81. if [ "$os400" = "true" ]; then
  82. if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then
  83. echo_r "The JAVA_HOME environment variable is not defined correctly"
  84. echo_r "This environment variable is needed to run this program"
  85. echo_r "NB: JAVA_HOME should point to a JDK not a JRE"
  86. exit 1
  87. fi
  88. else
  89. if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then
  90. echo_r "The JAVA_HOME environment variable is not defined correctly"
  91. echo_r "This environment variable is needed to run this program"
  92. echo_r "NB: JAVA_HOME should point to a JDK not a JRE"
  93. exit 1
  94. fi
  95. fi
  96. fi
  97. # Don't override the endorsed dir if the user has set it previously
  98. if [ -z "$JAVA_ENDORSED_DIRS" ]; then
  99. # Set the default -Djava.endorsed.dirs argument
  100. JAVA_ENDORSED_DIRS="$OPENCRON_HOME"/endorsed
  101. fi
  102. # Set standard commands for invoking Java, if not already set.
  103. if [ -z "$RUNJAVA" ]; then
  104. RUNJAVA="$JRE_HOME"/bin/java
  105. fi
  106. if [ "$os400" != "true" ]; then
  107. if [ -z "$_RUNJDB" ]; then
  108. _RUNJDB="$JAVA_HOME"/bin/jdb
  109. fi
  110. fi
  111. #check java exists.
  112. $RUNJAVA >/dev/null 2>&1
  113. if [ $? -ne 1 ];then
  114. echo_r "ERROR: java is not install,please install java first!"
  115. exit 1;
  116. fi
  117. #check openjdk
  118. if [ "`${RUNJAVA} -version 2>&1 | head -1|grep "openjdk"|wc -l`"x == "1"x ]; then
  119. echo_r "ERROR: please uninstall OpenJDK and install jdk first"
  120. exit 1;
  121. fi
  122. # OS specific support. $var _must_ be set to either true or false.
  123. cygwin=false
  124. darwin=false
  125. os400=false
  126. case "`uname`" in
  127. CYGWIN*) cygwin=true;;
  128. Darwin*) darwin=true;;
  129. OS400*) os400=true;;
  130. esac
  131. # resolve links - $0 may be a softlink
  132. PRG="$0"
  133. while [ -h "$PRG" ]; do
  134. ls=`ls -ld "$PRG"`
  135. link=`expr "$ls" : '.*-> \(.*\)$'`
  136. if expr "$link" : '/.*' > /dev/null; then
  137. PRG="$link"
  138. else
  139. PRG=`dirname "$PRG"`/"$link"
  140. fi
  141. done
  142. # Get standard environment variables
  143. PRGDIR=`dirname "$PRG"`
  144. WORKDIR=`cd "$PRGDIR" >/dev/null; pwd`;
  145. MAVEN_URL="http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gz";
  146. MAVEN_NAME="apache-maven-3.5.2-bin"
  147. UNPKG_MAVEN_NAME="apache-maven-3.5.2";
  148. OPENCRON_VERSION="1.1.0-RELEASE";
  149. MAVEN_PATH="/tmp";
  150. [ ! -d "$MAVEN_PATH" ] && mkdir $MAVEN_PATH;
  151. DIST_HOME="${WORKDIR}/dist"
  152. USER="`id -un`"
  153. LOGNAME="$USER"
  154. if [ $UID -ne 0 ]; then
  155. echo_y "WARNING: Running as a non-root user, \"$LOGNAME\". Functionality may be unavailable. Only root can use some commands or options"
  156. fi
  157. #check maven exists
  158. mvn >/dev/null 2>&1
  159. if [ $? -ne 1 ]; then
  160. echo_y "WARNING:maven is not install!"
  161. if [ -x "/tmp/${UNPKG_MAVEN_NAME}" ] ; then
  162. echo_w "maven is already download,now config setting...";
  163. MVN=/tmp/${UNPKG_MAVEN_NAME}/bin/mvn
  164. else
  165. echo_w "download maven Starting..."
  166. echo_w "checking network connectivity ... "
  167. net_check_ip=114.114.114.114
  168. ping_count=2
  169. ping -c ${ping_count} ${net_check_ip} >/dev/null
  170. retval=$?
  171. if [ ${retval} -eq 0 ] ; then
  172. echo_w "network is connectioned,download maven Starting... "
  173. wget -P "/tmp" $MAVEN_URL && {
  174. echo_g "download maven successful!";
  175. echo_w "install maven Starting"
  176. tar -xzvf /tmp/${MAVEN_NAME}.tar.gz -C /tmp
  177. MVN=/tmp/${UNPKG_MAVEN_NAME}/bin/mvn
  178. }
  179. elif [ ${retval} -ne 0 ]; then
  180. echo_r "ERROR:network is blocked! download maven failed,please check your network!build error! bye!"
  181. exit 1
  182. fi
  183. fi
  184. elif [ "$MVN"x = ""x ]; then
  185. MVN="mvn";
  186. fi
  187. echo_w "build opencron Starting...";
  188. $MVN clean install -Dmaven.test.skip=true;
  189. retval=$?
  190. if [ ${retval} -eq 0 ] ; then
  191. [ ! -d "${DIST_HOME}" ] && mkdir ${DIST_HOME} || rm -rf ${DIST_HOME}/* ;
  192. cp ${WORKDIR}/opencron-agent/target/opencron-agent-${OPENCRON_VERSION}.tar.gz ${DIST_HOME}
  193. cp ${WORKDIR}/opencron-server/target/opencron-server.war ${DIST_HOME}
  194. printf "[${BLUE_COLOR}opencron${RES}] ${WHITE_COLOR}build opencron @Version ${OPENCRON_VERSION} successfully! please goto${RES} ${GREEN_COLOR}${DIST_HOME}${RES}\n"
  195. exit 0
  196. else
  197. echo_r "build opencron failed! please try again "
  198. exit 1
  199. fi