@@ -53,28 +53,50 @@ elif ls "$BMA_ROOT/lib/"*.jar &>/dev/null; then
5353 echo " [*] JARs copied from lib/ to WEB-INF/lib/"
5454fi
5555
56- # Ensure db.properties exists — prompt if missing
56+ # Ensure db.properties exists — use .nwe-credentials or prompt if interactive
5757DB_PROPS=" $DEPLOY_DIR /WEB-INF/db.properties"
58- if [ ! -f " $DB_PROPS " ] || ! grep -q " db.password=." " $DB_PROPS " 2> /dev/null; then
59- echo " "
60- echo " [*] db.properties needs MySQL credentials for JSP pages."
61- read -rp " MySQL user [root]: " DB_USER
62- DB_USER=" ${DB_USER:- root} "
63- read -rsp " MySQL password: " DB_PASS
64- echo " "
65- read -rp " MySQL host [localhost]: " DB_HOST
66- DB_HOST=" ${DB_HOST:- localhost} "
67- read -rp " MySQL port [3306]: " DB_PORT
68- DB_PORT=" ${DB_PORT:- 3306} "
69- cat > " $DB_PROPS " << EOF
58+ if [ ! -f " $DB_PROPS " ] || ! grep -q " db.password=." " $DB_PROPS " 2> /dev/null || grep -q " CHANGE_ME" " $DB_PROPS " 2> /dev/null; then
59+ # Try .nwe-credentials first (non-interactive safe)
60+ NWE_ROOT=" $( cd " $SCRIPT_DIR /../../../.." 2> /dev/null && pwd) "
61+ if [ -f " $NWE_ROOT /.nwe-credentials" ]; then
62+ source " $NWE_ROOT /.nwe-credentials"
63+ mkdir -p " $DEPLOY_DIR /WEB-INF"
64+ cat > " $DB_PROPS " << EOF
65+ # BMA Database Configuration — auto-generated from .nwe-credentials
66+ db.driver=com.mysql.cj.jdbc.Driver
67+ db.url=jdbc:mysql://${NWE_DB_HOST:- 127.0.0.1} :${NWE_DB_PORT:- 3306} /BrarnerScience
68+ db.user=${NWE_DB_USER:- root}
69+ db.password=${NWE_DB_PASS}
70+ EOF
71+ chmod 600 " $DB_PROPS "
72+ echo " [*] db.properties generated from .nwe-credentials"
73+ elif [ -t 0 ]; then
74+ # Interactive terminal — prompt for credentials
75+ echo " "
76+ echo " [*] db.properties needs MySQL credentials for JSP pages."
77+ read -rp " MySQL user [root]: " DB_USER
78+ DB_USER=" ${DB_USER:- root} "
79+ read -rsp " MySQL password: " DB_PASS
80+ echo " "
81+ read -rp " MySQL host [localhost]: " DB_HOST
82+ DB_HOST=" ${DB_HOST:- localhost} "
83+ read -rp " MySQL port [3306]: " DB_PORT
84+ DB_PORT=" ${DB_PORT:- 3306} "
85+ mkdir -p " $DEPLOY_DIR /WEB-INF"
86+ cat > " $DB_PROPS " << EOF
7087# BMA Database Configuration — written by deploy-local.sh
7188db.driver=com.mysql.cj.jdbc.Driver
7289db.url=jdbc:mysql://${DB_HOST} :${DB_PORT} /BrarnerScience
7390db.user=${DB_USER}
7491db.password=${DB_PASS}
7592EOF
76- chmod 600 " $DB_PROPS "
77- echo " [*] db.properties written"
93+ chmod 600 " $DB_PROPS "
94+ echo " [*] db.properties written"
95+ else
96+ # Non-interactive and no credentials file — skip (don't hang)
97+ echo " [!] db.properties missing and no .nwe-credentials found (non-interactive)"
98+ echo " JSP database pages will fail. Create .nwe-credentials and redeploy."
99+ fi
78100else
79101 echo " [*] db.properties present (user=$( grep ' ^db.user=' " $DB_PROPS " | cut -d= -f2-) )"
80102fi
0 commit comments