| 
									
										
										
										
											2022-06-01 21:46:53 +03:00
										 |  |  | #!/bin/bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ${MYSQL_PORT:=3306} | 
					
						
							| 
									
										
										
										
											2025-01-09 14:32:18 -06:00
										 |  |  | : ${MYSQL_ARGS:=--ssl=0} | 
					
						
							| 
									
										
										
										
											2025-10-02 04:53:31 +05:30
										 |  |  | : ${CDC_MCL_PROCESSING_ENABLED:=false} | 
					
						
							|  |  |  | : ${CDC_USER:=datahub_cdc} | 
					
						
							|  |  |  | : ${CDC_PASSWORD:=datahub_cdc} | 
					
						
							| 
									
										
										
										
											2021-04-13 08:03:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-02 04:53:31 +05:30
										 |  |  | # Process main init script | 
					
						
							| 
									
										
										
										
											2021-04-14 19:07:50 -07:00
										 |  |  | sed -e "s/DATAHUB_DB_NAME/${DATAHUB_DB_NAME}/g" /init.sql | tee -a /tmp/init-final.sql | 
					
						
							| 
									
										
										
										
											2025-10-02 04:53:31 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | # Run main init script with regular user | 
					
						
							|  |  |  | mariadb -u $MYSQL_USERNAME -p"$MYSQL_PASSWORD" -h $MYSQL_HOST -P $MYSQL_PORT $MYSQL_ARGS < /tmp/init-final.sql | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Conditionally create CDC user with root privileges if enabled | 
					
						
							|  |  |  | if [[ "${CDC_MCL_PROCESSING_ENABLED}" == "true" ]]; then | 
					
						
							|  |  |  |     echo "CDC MCL processing is enabled. Creating CDC user with root privileges..." | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if [[ -z "${MYSQL_ROOT_PASSWORD}" ]]; then | 
					
						
							|  |  |  |         echo "ERROR: MYSQL_ROOT_PASSWORD must be set when CDC_MCL_PROCESSING_ENABLED=true" | 
					
						
							|  |  |  |         exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create CDC user script with root privileges | 
					
						
							|  |  |  |     sed -e "s/DATAHUB_DB_NAME/${DATAHUB_DB_NAME}/g" \
 | 
					
						
							|  |  |  |         -e "s/CDC_USER/${CDC_USER}/g" \
 | 
					
						
							|  |  |  |         -e "s/CDC_PASSWORD/${CDC_PASSWORD}/g" /init-cdc.sql > /tmp/init-cdc-final.sql | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Execute CDC user creation with root user | 
					
						
							|  |  |  |     mariadb -u root -p"$MYSQL_ROOT_PASSWORD" -h $MYSQL_HOST -P $MYSQL_PORT $MYSQL_ARGS < /tmp/init-cdc-final.sql | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     echo "CDC user '$CDC_USER' created successfully." | 
					
						
							|  |  |  | fi |