chef removal changes for catalog-be
[sdc.git] / catalog-be / sdc-backend-init / custom-scripts / import_normatives.sh
1 #!/bin/sh
2
3
4 # Set protocol and port based on DISABLE_HTTP
5 if [ "$DISABLE_HTTP" = "true" ]; then
6   protocol="https"
7   be_port=$BE_HTTPS_PORT
8   param="-i $BE_IP -p $be_port --https"
9   
10   # Set TLS flags if certificates are provided
11   if [ -n "$TLS_CERT" ]; then
12     tls_cert="--tls_cert $TLS_CERT"
13   fi
14   if [ -n "$TLS_KEY" ]; then
15     tls_key="--tls_key $TLS_KEY"
16   fi
17   if [ -n "$TLS_KEY_PW" ]; then
18     tls_key_pw="--tls_key_pw $TLS_KEY_PW"
19   fi
20   if [ -n "$CA_CERT" ]; then
21     ca_cert="--ca_cert $CA_CERT"
22   fi
23 else
24   protocol="http"
25   be_port="$BE_HTTP_PORT"
26   param="-i $BE_IP -p $be_port"
27 fi
28
29 # Set basic authentication if enabled
30 if [ "$BASIC_AUTH_ENABLED" = "true" ]; then
31   basic_auth_user="${BASIC_AUTH_USER:-}"
32   basic_auth_pass="${BASIC_AUTH_PASS:-}"
33   
34   if [ -n "$basic_auth_user" ] && [ -n "$basic_auth_pass" ]; then
35     basic_auth_config="--header $(echo -n "$basic_auth_user:$basic_auth_pass" | base64)"
36   else
37     basic_auth_config=""
38   fi
39 else
40   basic_auth_config=""
41 fi
42
43 # Extract normatives tarball and run the initialization command
44 echo "Extracting normatives.tar.gz and initializing SDC..."
45 cd /var/tmp/ || exit 1
46 cp /home/onap/normatives.tar.gz /var/tmp/
47 tar -xvf /var/tmp/normatives.tar.gz
48
49 start_time=$(date +"%Y-%m-%d %H:%M:%S")
50 echo "[$start_time] Starting sdcinit..."
51
52 # Run sdcinit command with the constructed parameters
53 cd /var/tmp/normatives/import/tosca || exit 1
54 sdcinit $param $basic_auth_config $tls_cert $tls_key $tls_key_pw $ca_cert > "/home/onap/logs/init.log" 2>&1
55
56 end_time=$(date +"%Y-%m-%d %H:%M:%S")
57 echo "[$end_time] Done sdcinit."
58
59 start_ts=$(date -d "$start_time" +%s)
60 end_ts=$(date -d "$end_time" +%s)
61 elapsed=$((end_ts - start_ts))
62 echo "Elapsed time: $elapsed seconds"
63
64 echo "SDC initialization Done. Logs can be found at ${ONAP_LOG}/init.log"
65