build.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #!/bin/bash
  2. function copy() {
  3. echo -e "Creating configuration directory under /etc/cas"
  4. mkdir -p /etc/cas/config
  5. echo -e "Copying configuration files from etc/cas to /etc/cas"
  6. cp -rfv etc/cas/* /etc/cas
  7. }
  8. function help() {
  9. echo "Usage: build.sh [copy|clean|package|run|debug|bootrun|gencert]"
  10. echo " copy: Copy config from ./etc/cas/config to /etc/cas/config"
  11. echo " clean: Clean Maven build directory"
  12. echo " package: Clean and build CAS war"
  13. echo " run: Build and run cas.war via Java (i.e. java -jar target/cas.war)"
  14. echo " runalone: Build and run cas.war on its own as a standalone executable (target/cas.war)"
  15. echo " debug: Run CAS.war and listen for Java debugger on port 5000"
  16. echo " bootrun: Run with maven spring boot plugin"
  17. echo " listviews: List all CAS views that ship with the web application and can be customized in the overlay"
  18. echo " getview: Ask for a view name to be included in the overlay for customizations"
  19. echo " gencert: Create keystore with SSL certificate in location where CAS looks by default"
  20. echo " cli: Run the CAS command line shell and pass commands"
  21. }
  22. function clean() {
  23. shift
  24. ./mvnw clean "$@"
  25. }
  26. function package() {
  27. shift
  28. ./mvnw clean package -T 5 "$@"
  29. # copy
  30. }
  31. function bootrun() {
  32. shift
  33. ./mvnw clean package spring-boot:run -P bootiful -T 5 "$@"
  34. }
  35. function debug() {
  36. package && java -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar target/cas.war
  37. }
  38. function run() {
  39. package && java -jar target/cas.war
  40. }
  41. function runalone() {
  42. shift
  43. ./mvnw clean package -P default,exec "$@"
  44. chmod +x target/cas.war
  45. target/cas.war
  46. }
  47. function listviews() {
  48. shift
  49. explodeapp
  50. find $PWD/target/cas -type f -name "*.html" | xargs -n 1 basename | sort | more
  51. }
  52. function explodeapp() {
  53. if [ ! -d $PWD/target/cas ];then
  54. echo "Building the CAS web application and exploding the final war file..."
  55. ./mvnw clean package war:exploded "$@"
  56. fi
  57. echo "Exploded the CAS web application file."
  58. }
  59. function getview() {
  60. shift
  61. explodeapp
  62. echo "Searching for view name $@..."
  63. results=`find $PWD/target/cas -type f -name "*.html" | grep -i "$@"`
  64. echo -e "Found view(s): \n$results"
  65. count=`wc -w <<< "$results"`
  66. if [ "$count" -eq 1 ];then
  67. # echo "Found view $results to include in the overlay"
  68. firststring="target/cas/WEB-INF/classes"
  69. secondstring="src/main/resources"
  70. overlayfile=`echo "${results/$firststring/$secondstring}"`
  71. overlaypath=`dirname "${overlayfile}"`
  72. # echo "Overlay file is $overlayfile to be created at $overlaypath"
  73. mkdir -p $overlaypath
  74. cp $results $overlaypath
  75. echo "Created view at $overlayfile"
  76. ls $overlayfile
  77. else
  78. echo "More than one view file is found. Narrow down the search query..."
  79. fi
  80. }
  81. function gencert() {
  82. if [[ ! -d /etc/cas ]] ; then
  83. copy
  84. fi
  85. which keytool
  86. if [[ $? -ne 0 ]] ; then
  87. echo Error: Java JDK \'keytool\' is not installed or is not in the path
  88. exit 1
  89. fi
  90. # override DNAME and CERT_SUBJ_ALT_NAMES before calling or use dummy values
  91. DNAME="${DNAME:-CN=cas.example.org,OU=Example,OU=Org,C=US}"
  92. CERT_SUBJ_ALT_NAMES="${CERT_SUBJ_ALT_NAMES:-dns:example.org,dns:localhost,ip:127.0.0.1}"
  93. echo "Generating keystore for CAS with DN ${DNAME}"
  94. keytool -genkeypair -alias cas -keyalg RSA -keypass changeit -storepass changeit -keystore /etc/cas/thekeystore -dname ${DNAME} -ext SAN=${CERT_SUBJ_ALT_NAMES}
  95. keytool -exportcert -alias cas -storepass changeit -keystore /etc/cas/thekeystore -file /etc/cas/cas.cer
  96. }
  97. function cli() {
  98. CAS_VERSION=$(./mvnw -q -Dexec.executable="echo" -Dexec.args='${cas.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec 2>/dev/null)
  99. # echo "CAS version: $CAS_VERSION"
  100. JAR_FILE_NAME="cas-server-support-shell-${CAS_VERSION}.jar"
  101. # echo "JAR name: $JAR_FILE_NAME"
  102. JAR_PATH="org/apereo/cas/cas-server-support-shell/${CAS_VERSION}/${JAR_FILE_NAME}"
  103. # echo "JAR path: $JAR_PATH"
  104. JAR_FILE_LOCAL="$HOME/.m2/repository/$JAR_PATH";
  105. # echo "Local JAR file path: $JAR_FILE_LOCAL";
  106. if [ -f "$JAR_FILE_LOCAL" ]; then
  107. # echo "Using JAR file locally at $JAR_FILE_LOCAL"
  108. java -jar $JAR_FILE_LOCAL "$@"
  109. exit 0;
  110. fi
  111. DOWNLOAD_DIR=./target
  112. COMMAND_FILE="${DOWNLOAD_DIR}/${JAR_FILE_NAME}"
  113. if [ ! -f "$COMMAND_FILE" ]; then
  114. mkdir -p $DOWNLOAD_DIR
  115. ./mvnw org.apache.maven.plugins:maven-dependency-plugin:3.0.2:get -DgroupId=org.apereo.cas -DartifactId=cas-server-support-shell -Dversion=$CAS_VERSION -Dpackaging=jar -DartifactItem.outputDirectory=$DOWNLOAD_DIR -DremoteRepositories=central::default::http://repo1.maven.apache.org/maven2,snapshots::::https://oss.sonatype.org/content/repositories/snapshots -Dtransitive=false
  116. ./mvnw org.apache.maven.plugins:maven-dependency-plugin:3.0.2:copy -Dmdep.useBaseVersion=true -Dartifact=org.apereo.cas:cas-server-support-shell:$CAS_VERSION:jar -DoutputDirectory=$DOWNLOAD_DIR
  117. fi
  118. java -jar $COMMAND_FILE "$@"
  119. exit 0;
  120. }
  121. if [ $# -eq 0 ]; then
  122. echo -e "No commands provided. Defaulting to [run]\n"
  123. run
  124. exit 0
  125. fi
  126. case "$1" in
  127. "copy")
  128. copy
  129. ;;
  130. "clean")
  131. shift
  132. clean "$@"
  133. ;;
  134. "package")
  135. shift
  136. package "$@"
  137. ;;
  138. "bootrun")
  139. shift
  140. bootrun "$@"
  141. ;;
  142. "debug")
  143. debug "$@"
  144. ;;
  145. "run")
  146. run "$@"
  147. ;;
  148. "runalone")
  149. runalone "$@"
  150. ;;
  151. "listviews")
  152. listviews "$@"
  153. ;;
  154. "gencert")
  155. gencert "$@"
  156. ;;
  157. "getview")
  158. getview "$@"
  159. ;;
  160. "cli")
  161. shift
  162. cli "$@"
  163. ;;
  164. *)
  165. help
  166. ;;
  167. esac