Update traversal from AJSC 2 to Spring Boot
[aai/traversal.git] / aai-traversal / src / main / scripts / common_functions.sh
1 #!/bin/ksh
2
3 # Common functions that can be used throughout multiple scripts
4 # In order to call these functions, this file needs to be sourced
5
6 # Checks if the user that is currently running is aaiadmin
7 check_user(){
8
9     userid=$( id | cut -f2 -d"(" | cut -f1 -d")" )
10
11     if [ "${userid}" != "aaiadmin" ]; then
12         echo "You must be aaiadmin to run $0. The id used $userid."
13         exit 1
14     fi
15 }
16
17 # Sources the profile and sets the project home
18 source_profile(){
19     . /etc/profile.d/aai.sh
20     PROJECT_HOME=/opt/app/aai-traversal
21 }
22
23 # Runs the spring boot jar based on which main class
24 # to execute and which logback file to use for that class
25 execute_spring_jar(){
26
27     className=$1;
28     logbackFile=$2;
29
30     shift 2;
31
32     EXECUTABLE_JAR=$(ls ${PROJECT_HOME}/lib/aai-traversal-*SNAPSHOT.jar);
33
34     JAVA_OPTS="${JAVA_PRE_OPTS}";
35     JAVA_OPTS="-DAJSC_HOME=$PROJECT_HOME";
36     JAVA_OPTS="$JAVA_OPTS -DBUNDLECONFIG_DIR=resources";
37     JAVA_OPTS="$JAVA_OPTS -Daai.home=$PROJECT_HOME ";
38     JAVA_OPTS="$JAVA_OPTS -Dhttps.protocols=TLSv1.1,TLSv1.2";
39     JAVA_OPTS="$JAVA_OPTS -Dloader.main=${className}";
40     JAVA_OPTS="$JAVA_OPTS -Dlogback.configurationFile=${logbackFile}";
41     JAVA_OPTS="${JAVA_OPTS} ${JAVA_POST_OPTS}";
42
43     ${JAVA_HOME}/bin/java ${JVM_OPTS} ${JAVA_OPTS} -jar ${EXECUTABLE_JAR} "$@"
44 }
45
46 # Prints the start date and the script that the user called
47 start_date(){
48     echo
49     echo `date` "   Starting $0"
50 }
51
52 # Prints the end date and the script that the user called
53 end_date(){
54     echo
55     echo `date` "   Done $0"
56 }