diff --git a/script/bin/init_check_network.sh b/script/bin/init_check_network.sh index 92335059a9..3502143c7c 100644 --- a/script/bin/init_check_network.sh +++ b/script/bin/init_check_network.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e EXTERNAL_CONNECTIVITY_CHECK_URL="www.baidu.com" diff --git a/script/bin/init_db.sh b/script/bin/init_db.sh index 6c706dd4fc..6e518dc2f8 100644 --- a/script/bin/init_db.sh +++ b/script/bin/init_db.sh @@ -1,62 +1,79 @@ #!/bin/bash +set -e -DINKY_HOME=$1 +DINKY_HOME_PARAMS=$1 +DB_ENV_FILE=$2 echo -e "${GREEN}====================== The database configuration file is initialized ======================${RESET}" -if [ -z "$DINKY_HOME" ]; then +if [ -z "$DINKY_HOME_PARAMS" ]; then echo -e "${RED}The parameter is wrong, please check!${RESET}" exit 1 fi while true; do - read -p "Please select a database type (1.MySQL 2.PostgresSQL):" db_type - read -p "Please enter the database address (hostname or IP, default localhost): " -i "localhost" db_host - read -p "Please enter the database port (default 3306): " -i 3306 db_port - read -p "Please enter a database name (default dinky): " -i "dinky" db_name - read -p "Please enter the database username (default dinky):" -i "dinky" db_username - read -s -p "Please enter the database password (default dinky):" -i "dinky" db_password + read -e -p "Please select a database type (1.MySQL 2.PostgresSQL):" db_type + while [ -z "$db_type" ]; do + read -e -p "Please select a database type (1.MySQL 2.PostgresSQL):" db_type + done + read -e -p "Please enter the database address (hostname or IP, default localhost): " -i "localhost" db_host + read -p "Please enter the database port : " db_port + read -e -p "Please enter a database name (default dinky): " -i "dinky" db_name + read -e -p "Please enter the database username (default dinky):" -i "dinky" db_username + read -s -p "Please enter the database password (default dinky):" db_password echo - db_type=$(echo "$db_type" | tr -d '[:space:]') - db_host=$(echo "$db_host" | tr -d '[:space:]') - db_port=$(echo "$db_port" | tr -d '[:space:]') - db_name=$(echo "$db_name" | tr -d '[:space:]') - db_username=$(echo "$db_username" | tr -d '[:space:]') - db_password=$(echo "$db_password" | tr -d '[:space:]') + + db_type=$(echo ${db_type} | tr -d '[:space:]') + db_host=$(echo ${db_host:-"localhost"} | tr -d '[:space:]') + db_name=$(echo ${db_name:-"dinky"}| tr -d '[:space:]') + db_username=$(echo ${db_username:-"dinky"} | tr -d '[:space:]') + db_password=$(echo ${db_password:-"dinky"} | tr -d '[:space:]') + if [ "$db_type" == 1 ]; then + db_port=$(echo ${db_port:-"3306"} | tr -d '[:space:]') + else + db_port=$(echo ${db_port:-"5432"} | tr -d '[:space:]') + fi + case $db_type in 1) echo -e "${YELLOW}Configuring MySQL database related information...${RESET}" - config_file="${DINKY_HOME}/config/application-mysql.yml" + config_file="${DINKY_HOME_PARAMS}/config/application-mysql.yml" echo -e "${GREEN} The automatic initialization script uses the export environment variable method to support the loading of environment variables of the data source. The configuration file is:${config_file} ${RESET}" - echo "export DB_ACTIVE=mysql" >> /etc/profile - echo "export MYSQL_ADDR=${db_host}:${db_port}" >> /etc/profile - echo "export MYSQL_DATABASE=${db_name}" >> /etc/profile - echo "export MYSQL_USERNAME=${db_username}" >> /etc/profile - echo "export MYSQL_PASSWORD=${db_password}" >> /etc/profile - source /etc/profile + + add_to_env "DB_ACTIVE" "mysql" "$DB_ENV_FILE" + add_to_env "MYSQL_ADDR" "${db_host}:${db_port}" "$DB_ENV_FILE" + add_to_env "MYSQL_DATABASE" "${db_name}" "$DB_ENV_FILE" + add_to_env "MYSQL_USERNAME" "${db_username}" "$DB_ENV_FILE" + add_to_env "MYSQL_PASSWORD" "${db_password}" "$DB_ENV_FILE" + + + sleep 2 + source "$DB_ENV_FILE" echo -e "${GREEN}MySQLThe configuration of database related information is completed. Please confirm whether the following configuration is correct:${RESET}" - grep -E '^(export DB_ACTIVE|export MYSQL_ADDR|export MYSQL_DATABASE|export MYSQL_USERNAME|export MYSQL_PASSWORD)' /etc/profile | grep -v "^#" | grep -v "^$" + grep -E '^(export DB_ACTIVE|export MYSQL_ADDR|export MYSQL_DATABASE|export MYSQL_USERNAME|export MYSQL_PASSWORD)' $DB_ENV_FILE | grep -v "^#" | grep -v "^$" break ;; 2) - echo -e "${YELLOW}Configuring PostgresSQL database related information...${RESET}" - config_file="${DINKY_HOME}/config/application-pgsql.yml" + echo -e "${YELLOW}Configuring PostgresSQL database related information...${RESET}" + config_file="${DINKY_HOME_PARAMS}/config/application-postgresql.yml" - echo -e "${GREEN}The automatic initialization script uses the export environment variable method to support the loading of environment variables from the data source configuration file. The configuration file is:${config_file} ${RESET}" + echo -e "${GREEN}The automatic initialization script uses the export environment variable method to support the loading of environment variables from the data source configuration file. The configuration file is:${config_file} ${RESET}" - echo "export DB_ACTIVE=pgsql" >> /etc/profile - echo "export POSTGRES_ADDR=${db_host}:${db_port}" >> /etc/profile - echo "export POSTGRES_DB=${db_name}" >> /etc/profile - echo "export POSTGRES_USER=${db_username}" >> /etc/profile - echo "export POSTGRES_PASSWORD=${db_password}" >> /etc/profile - source /etc/profile + add_to_env "DB_ACTIVE" "postgresql" "$DB_ENV_FILE" + add_to_env "POSTGRES_ADDR" "${db_host}:${db_port}" "$DB_ENV_FILE" + add_to_env "POSTGRES_DB" "${db_name}" "$DB_ENV_FILE" + add_to_env "POSTGRES_USER" "${db_username}" "$DB_ENV_FILE" + add_to_env "POSTGRES_PASSWORD" "${db_password}" "$DB_ENV_FILE" + sleep 2 + source $DB_ENV_FILE - echo -e "${GREEN}PostgresSQL The configuration of database related information is completed. Please confirm whether the following configuration is correct:${RESET}" - grep -E '^(export DB_ACTIVE|export POSTGRES_ADDR|export POSTGRES_DB|export POSTGRES_USER|export POSTGRES_PASSWORD)' /etc/profile | grep -v "^#" | grep -v "^$" - break + echo -e "${GREEN}PostgresSQL The configuration of database related information is completed. Please confirm whether the following configuration is correct:${RESET}" + grep -E '^(export DB_ACTIVE|export POSTGRES_ADDR|export POSTGRES_DB|export POSTGRES_USER|export POSTGRES_PASSWORD)' $DB_ENV_FILE | grep -v "^#" | grep -v "^$" + + break ;; *) echo -e "${RED}The entered database type is incorrect, please select the correct database type again.${RESET}" diff --git a/script/bin/init_env.sh b/script/bin/init_env.sh new file mode 100644 index 0000000000..f500fa06f8 --- /dev/null +++ b/script/bin/init_env.sh @@ -0,0 +1,53 @@ +#!/bin/bash +set -e + +DINKY_HOME_PARAMS=$1 +ENV_FILE=$2 + + +echo -e "${GREEN}Start configuring DINKY_HOME environment variable...${RESET}" + +echo -e "${GREEN}DINKY_HOME environment variable has not been configured, please choose whether to configure.${RESET}" +echo -e "${GREEN}1. Use the automatically obtained DINKY_HOME environment variable${RESET}" +echo -e "${GREEN}2. Manually enter the path of DINKY_HOME${RESET}" +echo -e "${GREEN}3. Cancel configuration${RESET}" +while true; do + read -p "Please enter your choice(1/2/3):" DINKY_HOME_CHOICE + case $DINKY_HOME_CHOICE in + 1) + echo -e "${GREEN}Use the automatically obtained DINKY_HOME environment variable${RESET}" + echo -e "${GREEN} The currently obtained path is: $DINKY_HOME_PARAMS to perform automatic configuration${RESET}" + add_to_env "DINKY_HOME" "$DINKY_HOME_PARAMS" "$ENV_FILE" + add_to_env "PATH" "\$DINKY_HOME/bin" "$ENV_FILE" + sleep 2 + source $ENV_FILE + echo -e "${GREEN}DINKY_HOME environment variable configuration completed. Please confirm whether the following configuration is correct:${RESET}" + grep -E '^(export DINKY_HOME)' $ENV_FILE | grep -v "^#" | grep -v "^$" + break + ;; + 2) + read -p "Please enter the path of DINKY_HOME:" dinky_home_path + dinky_home_path=$(echo "$dinky_home_path" | tr -d '[:space:]') + if [ ! -d "$dinky_home_path" ]; then + echo -e "${RED}The path does not exist, please re-enter${RESET}" + read -p "Please enter the path of DINKY_HOME:" dinky_home_path + else + echo -e "${GREEN}The path you entered is: $dinky_home_path${RESET}" + add_to_env "DINKY_HOME" "$dinky_home_path" "$ENV_FILE" + add_to_env "PATH" "\$DINKY_HOME/bin" "$ENV_FILE" + sleep 2 + source $ENV_FILE + echo -e "${GREEN}DINKY_HOME environment variable configuration completed. Please confirm whether the following configuration is correct:${RESET}" + grep -E '^(export DINKY_HOME)' $ENV_FILE | grep -v "^#" | grep -v "^$" + fi + break + ;; + 3) + echo -e "${GREEN}Cancel configuration${RESET}" + break + ;; + *) + echo -e "${RED}Invalid input, please re-run the script to select the correct option.${RESET}" + ;; + esac +done \ No newline at end of file diff --git a/script/bin/init_flink_dependences.sh b/script/bin/init_flink_dependences.sh index 4b7092e93f..4f5b3d7501 100644 --- a/script/bin/init_flink_dependences.sh +++ b/script/bin/init_flink_dependences.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e CURRENT_FLINK_FULL_VERSION=$1 FLINK_VERSION_SCAN=$2 diff --git a/script/bin/init_hadoop_dependences.sh b/script/bin/init_hadoop_dependences.sh index e61526413c..261760e50c 100644 --- a/script/bin/init_hadoop_dependences.sh +++ b/script/bin/init_hadoop_dependences.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e EXTENDS_HOME=$1 @@ -31,5 +32,3 @@ case $hadoop_uber_version in echo -e "${RED}The entered version number is incorrect, please re-run the script to select the correct version.${RESET}" ;; esac - -echo -e "${GREEN}After the download is completed, subsequent installation and configuration operations can be performed as needed.${RESET}" \ No newline at end of file diff --git a/script/bin/init_jdbc_driver.sh b/script/bin/init_jdbc_driver.sh new file mode 100644 index 0000000000..732d03fc93 --- /dev/null +++ b/script/bin/init_jdbc_driver.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +DINKY_LIB_DIR=$1 + +echo -e "${GREEN}Start downloading the mysql driver package...${RESET}" +if [ -f "${DINKY_LIB_DIR}/mysql-connector-j-8.4.0.jar" ]; then + echo -e "${YELLOW}mysql The driver package already exists, no need to download it again. Skip this step。${RESET}" +else + download_file https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.4.0/mysql-connector-j-8.4.0.jar "${DINKY_LIB}" + echo -e "${GREEN}Download is complete, please verify. The downloaded file storage address is: ${DINKY_LIB_DIR}/mysql-connector-j-8.4.0.jar${RESET}" + if [ -f "${DINKY_LIB_DIR}/mysql-connector-j-8.4.0.jar" ]; then + echo -e "${GREEN}mysql driver package downloaded successfully。${RESET}" + else + echo -e "${RED}Mysql driver package download failed, please check the network or download manually。${RESET}" + exit 1 + fi + echo -e "${GREEN}After the verification is completed, subsequent installation and configuration operations can be performed as needed.。${RESET}" +fi \ No newline at end of file diff --git a/script/bin/init_tools_main.sh b/script/bin/init_tools_main.sh index dea59e73ac..f48f02bfcf 100644 --- a/script/bin/init_tools_main.sh +++ b/script/bin/init_tools_main.sh @@ -1,4 +1,26 @@ #!/bin/bash +set -e + +ENV_FILE="/etc/profile.d/dinky_env" +if [ -f "${ENV_FILE}" ]; then + source "${ENV_FILE}" +else + echo "" > "${ENV_FILE}" + source "${ENV_FILE}" +fi + +DB_ENV_FILE="/etc/profile.d/dinky_db" +if [ -f "${DB_ENV_FILE}" ]; then + source "${DB_ENV_FILE}" +else + echo "" > "${DB_ENV_FILE}" + source "${DB_ENV_FILE}" +fi +chmod 755 $ENV_FILE +chmod 755 $DB_ENV_FILE + +source /etc/profile + export RED='\033[31m' export GREEN='\033[32m' @@ -15,7 +37,6 @@ echo -e "${GREEN}=============================================================== echo -e "${GREEN}======================================================================${RESET}" APP_HOME=${DINKY_HOME:-$(cd "$(dirname "$0")"; cd ..; pwd)} -export DINKY_HOME=${APP_HOME} sudo chmod +x "${APP_HOME}"/bin/init_*.sh @@ -82,6 +103,56 @@ function download_file() { export -f download_file +add_to_env() { + local var_name=$1 + local var_value=$2 + local file=$3 + echo "Adding $var_name to $file" + echo "export $var_name=\"$var_value\"" >> "$file" +# +# if ! grep -q "^export $var_name=" "$file"; then +# echo "Adding $var_name to $file" +# echo "export $var_name=\"$var_value\"" >> "$file" +# else +# echo "$var_name already exists in $file, skipping." +# fi +} +export -f add_to_env + + + +echo +echo + +echo -e "${GREEN} ====================== Environment variable initialization script -> Start ====================== ${RESET}" +DINKY_HOME_TMP=$(echo $DINKY_HOME) +if [ -z "$DINKY_HOME_TMP" ]; then + while true; do + read -p "Do you need to configure the DINKY_HOME environment variable? (yes/no):" is_init_dinky_home + is_init_dinky_home=$(echo "$is_init_dinky_home" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]') + case $is_init_dinky_home in + yes | y) + sh "${APP_HOME}"/bin/init_env.sh ${APP_HOME} ${ENV_FILE} + echo -e "${GREEN}DINKY_HOME environment variable configuration completed. the configuration file is:${ENV_FILE} ${RESET}" + break + ;; + no | n) + echo -e "${GREEN}Skip DINKY_HOME environment variable configuration.${RESET}" + break + ;; + *) + echo -e "${RED}The entered value is incorrect, please rerun the script to select the correct value.${RESET}" + ;; + esac + done +else + echo -e "${GREEN}DINKY_HOME environment variable has been configured at ${DINKY_HOME_TMP},Skip configuration.${RESET}" +fi + + +echo -e "${GREEN} ====================== Environment variable initialization script -> End ====================== ${RESET}" + + echo echo echo -e "${GREEN} ====================== Data source driver initialization script -> Start ====================== ${RESET}" @@ -97,20 +168,7 @@ while true; do read -p "Please enter your database type:" db_type case $db_type in 1) - echo -e "${GREEN}Start downloading the mysql driver package...${RESET}" - if [ -f "${DINKY_LIB}/mysql-connector-j-8.4.0.jar" ]; then - echo -e "${GREEN}mysql The driver package already exists, no need to download it again. Skip this step。${RESET}" - else - download_file https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.4.0/mysql-connector-j-8.4.0.jar "${DINKY_LIB}" - echo -e "${GREEN}Download is complete, please verify. The downloaded file storage address is: ${DINKY_LIB}/mysql-connector-j-8.4.0.jar${RESET}" - if [ -f "${DINKY_LIB}/mysql-connector-j-8.4.0.jar" ]; then - echo -e "${GREEN}mysql driver package downloaded successfully。${RESET}" - else - echo -e "${RED}Mysql driver package download failed, please check the network or download manually。${RESET}" - exit 1 - fi - echo -e "${GREEN}After the verification is completed, subsequent installation and configuration operations can be performed as needed.。${RESET}" - fi + sh "${APP_HOME}"/bin/init_jdbc_driver.sh "${DINKY_LIB}" break ;; 2) @@ -219,15 +277,16 @@ while true; do is_init_db=$(echo "$is_init_db" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]') case $is_init_db in yes | y ) - sh "${APP_HOME}/bin/init_db.sh" "${DINKY_HOME}" + sh "${APP_HOME}/bin/init_db.sh" "${DINKY_HOME}" "${DB_ENV_FILE}" + echo -e "${GREEN}The database configuration file initialization script has been executed successfully the configuration file is:${DB_ENV_FILE} ${RESET}" break ;; no | n ) - echo -e "${GREEN}The database initialization operation has been skipped, please manually configure the database ${DINKY_HOME}/config/application.yml file and ${DINKY_HOME}/config/application-[mysql/pgsql].yml file。${RESET}" + echo -e "${GREEN}The database initialization operation has been skipped, please manually configure the database ${APP_HOME}/config/application.yml file and ${DINKY_HOME}/config/application-[mysql/postgresql].yml file。${RESET}" break ;; exit | e ) - echo -e "${GREEN}The script has exited, please manually configure the database ${DINKY_HOME}/config/application.yml file and ${DINKY_HOME}/config/application-[mysql/pgsql].yml file。${RESET}" + echo -e "${GREEN}The script has exited, please manually configure the database ${APP_HOME}/config/application.yml file and ${APP_HOME}/config/application-[mysql/postgresql].yml file。${RESET}" exit 0 ;; *) @@ -235,4 +294,10 @@ while true; do ;; esac done -echo -e "${GREEN} ====================== Database configuration file initialization script -> End ====================== ${RESET}" \ No newline at end of file +echo -e "${GREEN} ====================== Database configuration file initialization script -> End ====================== ${RESET}" +echo +echo +echo -e "${RED}Note: To make these changes permanent, you may need to restart your terminal or run 'source $DB_ENV_FILE && source $ENV_FILE' ${RESET}" +echo -e "${RED}Note: To make these changes permanent, you may need to restart your terminal or run 'source $DB_ENV_FILE && source $ENV_FILE' ${RESET}" +echo -e "${RED}Note: To make these changes permanent, you may need to restart your terminal or run 'source $DB_ENV_FILE && source $ENV_FILE' ${RESET}" +echo