|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +##################### |
| 4 | +# bash only |
| 5 | +# usage ./package.sh |
| 6 | +##################### |
| 7 | + |
| 8 | +#declare -a: define an array |
| 9 | +#declare -i: define an integer |
| 10 | +declare -i index=1 |
| 11 | +declare -a envMap |
| 12 | +declare -a formatMap=(["1"]="docker" ["2"]="springboot") |
| 13 | + |
| 14 | +#GET THE URL OF CURRENT PATH |
| 15 | +CURRENT_DIR=`dirname $0` |
| 16 | +cd $CURRENT_DIR |
| 17 | + |
| 18 | +######################### |
| 19 | +# confirm the env |
| 20 | +######################### |
| 21 | +index=1 |
| 22 | +#scan the envs from conf/* |
| 23 | +for i in env/* ; do |
| 24 | + if [ -d ${i} ]; then |
| 25 | + envMap["${index}"]="`basename ${i}`" |
| 26 | + index=index+1 |
| 27 | + fi |
| 28 | +done |
| 29 | + |
| 30 | +#Print the choice |
| 31 | +env=1 |
| 32 | +echo "Please choose the environment by typing the number [default ${env}]" |
| 33 | +for i in ${!envMap[@]} ;do |
| 34 | + echo [${i}]:${envMap[${i}]} |
| 35 | +done |
| 36 | + |
| 37 | +#Read the envTmp . Set The finalEnv. Pay Attention 'read' NOT 'Read' |
| 38 | +read envTmp |
| 39 | +# echo "${envTmp}" |
| 40 | +if [ "${envTmp}" != "" ]; then |
| 41 | + env=${envTmp} |
| 42 | +fi |
| 43 | +# echo "${env}" |
| 44 | +finalEnv=${envMap[${env}]} |
| 45 | +echo "${finalEnv}" |
| 46 | +echo "[INFO] You are choosing environment: ${finalEnv}" |
| 47 | +echo "[INFO] Set the env properties by env/${finalEnv}/env.properties" |
| 48 | + |
| 49 | +#Load the env/${finalEnv}/env.properties |
| 50 | +. env/${finalEnv}/env.properties |
| 51 | +echo "" |
| 52 | +echo "" |
| 53 | + |
| 54 | +######################### |
| 55 | +# confirm the format |
| 56 | +######################### |
| 57 | +format=1 |
| 58 | +for i in ${!formatMap[@]};do |
| 59 | + echo [${i}]: ${formatMap[${i}]} |
| 60 | +done |
| 61 | +read formatTmp |
| 62 | +if [ "${formatTmp}" != "" ]; then |
| 63 | + format=${formatTmp} |
| 64 | +fi |
| 65 | +finalFormat=${formatMap[${format}]} |
| 66 | +######################### |
| 67 | +# confirm the package |
| 68 | +######################### |
| 69 | +finalPackage=${prop_package} |
| 70 | +echo "[INFO] You are choosing package version: ${finalPackage}" |
| 71 | +echo "" |
| 72 | +echo "" |
| 73 | + |
| 74 | +######################### |
| 75 | +# confirm the version |
| 76 | +######################### |
| 77 | +finalPackageVersion=${prop_packageVersion} |
| 78 | +echo "[INFO] You are choosing package version: ${finalPackageVersion}" |
| 79 | +echo "" |
| 80 | +echo "" |
| 81 | + |
| 82 | +###################### |
| 83 | +# begin packing |
| 84 | +###################### |
| 85 | +if [ -n "${finalFormat}" ] && [ "${finalFormat}" = "springboot" ]; then |
| 86 | + ############################## |
| 87 | + # generate executable war file |
| 88 | + ############################## |
| 89 | + |
| 90 | + #noneed.properties The .properties is outside the war . So it is no need any more. |
| 91 | + theCommand="./war-it.sh ${finalPackage} ${finalPackageVersion} ${finalEnv} 'noneed.properties'" |
| 92 | + echo [INFO] ${theCommand} |
| 93 | + eval ${theCommand} || exit 1 |
| 94 | +else |
| 95 | + ############################## |
| 96 | + # generate executable war file |
| 97 | + ############################## |
| 98 | + theCommand="./war-it.sh ${finalPackage} ${finalPackageVersion} ${finalEnv} 'noneed.properties'" |
| 99 | + echo [INFO] ${theCommand} |
| 100 | + eval ${theCommand} || exit 1 |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + ##################################### |
| 105 | + # generate docker image and export it |
| 106 | + ##################################### |
| 107 | + theCommand="./docker-it.sh ${finalPackage} ${finalPackageVersion} ${prop_dockerDestFolder} ${finalEnv}" |
| 108 | + echo [INFO] ${theCommand} |
| 109 | + eval ${theCommand} || exit 1 |
| 110 | +fi |
| 111 | + |
| 112 | +theCommand="./tar-it.sh ${finalEnv} ${finalPackage} ${finalPackageVersion} ${finalFormat}" |
| 113 | +echo [INFO] ${theCommand} |
| 114 | +eval ${theCommand} || exit 1 |
| 115 | + |
| 116 | +echo "[INFO] package is done successfully" |
| 117 | + |
0 commit comments