Skip to content

Commit fc9869a

Browse files
committed
[deploy] Fixed password authentication failure #562
Prevents credential mismatch when reinstalling without clearing volumes. The script now detects existing postgres_data volumes and aborts with a clear warning instead of silently generating new credentials that break database connectivity. Fixes #562
1 parent 8f378f3 commit fc9869a

1 file changed

Lines changed: 36 additions & 3 deletions

File tree

deploy/auto-install.sh

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,32 @@ setup_docker_openwisp() {
103103
echo -ne ${GRN}"Do you have .env file? Enter filepath (leave blank for ad-hoc configuration): "${NON}
104104
read env_path
105105
if [[ ! -f "$env_path" ]]; then
106+
if [[ ! -f "$INSTALL_PATH/.env" ]] && [[ ! -f "$ENV_BACKUP" ]] && docker volume inspect "docker-openwisp_postgres_data" &>/dev/null; then
107+
{
108+
echo -e "${RED}CRITICAL: Existing database volume detected!${NON}"
109+
echo ""
110+
echo "The Docker volume \"docker-openwisp_postgres_data\" already exists on this system."
111+
echo "This likely means there is database data from a previous OpenWISP installation."
112+
echo ""
113+
echo "The auto-install script generates new database credentials during fresh installations."
114+
echo "If it proceeds while this volume exists, the newly generated credentials will not"
115+
echo "match the credentials stored in the existing database, making the database"
116+
echo "inaccessible to OpenWISP."
117+
echo ""
118+
echo -e "${RED}⚠️ WARNING: The commands below will permanently delete the database volume and all"
119+
echo -e "stored data. Run them only if you intentionally want to wipe the previous installation"
120+
echo -e "or have a verified backup. Proceed at your own discretion.${NON}"
121+
echo ""
122+
echo "Cleanup commands:"
123+
echo -e " ${YLW}cd /opt/openwisp/docker-openwisp && docker compose down --volumes${NON}"
124+
echo "or"
125+
echo -e " ${YLW}docker volume rm docker-openwisp_postgres_data${NON}"
126+
echo ""
127+
echo "Aborting installation to prevent credential mismatch."
128+
echo -e "${RED}Check logs at $LOG_FILE${NON}"
129+
} | tee -a "$LOG_FILE"
130+
exit 1
131+
fi
106132
# Dashboard Domain
107133
echo -ne ${GRN}"(1/5) Enter dashboard domain: "${NON}
108134
read dashboard_domain
@@ -157,9 +183,16 @@ setup_docker_openwisp() {
157183
fi
158184
# Site manager email
159185
set_env "EMAIL_DJANGO_DEFAULT" "$django_default_email"
160-
# Set random secret values
161-
python3 $INSTALL_PATH/build.py change-secret-key >/dev/null
162-
python3 $INSTALL_PATH/build.py change-database-credentials >/dev/null
186+
# Set random secret values only if no previous credentials exist
187+
if [[ ! -f "$ENV_BACKUP" ]]; then
188+
python3 $INSTALL_PATH/build.py change-secret-key >/dev/null
189+
python3 $INSTALL_PATH/build.py change-database-credentials >/dev/null
190+
else
191+
for config in DB_USER DB_PASS DJANGO_SECRET_KEY; do
192+
value=$(get_env "$config" "$ENV_BACKUP")
193+
set_env "$config" "$value"
194+
done
195+
fi
163196
# SSL Configuration
164197
use_letsencrypt_lower=$(echo "$use_letsencrypt" | tr '[:upper:]' '[:lower:]')
165198
if [[ "$use_letsencrypt_lower" == "y" || "$use_letsencrypt_lower" == "yes" ]]; then

0 commit comments

Comments
 (0)