Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions deploy/auto-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ check_status() {
fi
}

# Returns true if the backup .env exists and contains app secrets
has_backup_with_secrets() {
[[ -f "$ENV_BACKUP" ]] && \
[[ -n "$(get_env "DB_USER" "$ENV_BACKUP")" ]] && \
[[ -n "$(get_env "DB_PASS" "$ENV_BACKUP")" ]] && \
[[ -n "$(get_env "DJANGO_SECRET_KEY" "$ENV_BACKUP")" ]]
}

error_msg() {
report_error
echo -e ${RED}${1}${NON}
Expand Down Expand Up @@ -103,6 +111,19 @@ setup_docker_openwisp() {
echo -ne ${GRN}"Do you have .env file? Enter filepath (leave blank for ad-hoc configuration): "${NON}
read env_path
if [[ ! -f "$env_path" ]]; then
# Prevent issues when users reinstall carelessly
if [[ ! -f "$INSTALL_PATH/.env" ]] && ! has_backup_with_secrets && docker volume inspect "docker-openwisp_postgres_data" &>/dev/null; then
{
echo -e "${RED}ERROR: Database volume exists but .env is missing.${NON}"
echo ""
echo "Generating new credentials would break access to the existing database."
echo ""
echo "Option 1 - Restore your previous .env and re-run this script."
echo "Option 2 - Wipe the database and start fresh (ALL DATA WILL BE LOST), e.g.:"
echo -e " ${YLW}cd $INSTALL_PATH && docker compose down --volumes${NON}"
} | tee -a "$LOG_FILE"
Copy link
Copy Markdown

@kilo-code-bot kilo-code-bot bot Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: ANSI escape codes will be written to the log file

The tee -a "$LOG_FILE" call pipes the raw output — including ANSI color codes (\033[1;31m, \033[1;33m, \033[0m) — directly into the log file. When users inspect the log with tail -n 50 -f /opt/openwisp/autoinstall.log (as documented in docs/user/quickstart.rst), they will see garbled escape sequences instead of readable text.

Strip the color codes before writing to the log:

Suggested change
} | tee -a "$LOG_FILE"
} | tee >(sed 's/\x1b\[[0-9;]*m//g' >> "$LOG_FILE") # strips ANSI color codes

Alternatively, use script -q -c or simply write a plain-text version to the log separately.

exit 1
fi
# Dashboard Domain
echo -ne ${GRN}"(1/5) Enter dashboard domain: "${NON}
read dashboard_domain
Expand Down Expand Up @@ -157,9 +178,16 @@ setup_docker_openwisp() {
fi
# Site manager email
set_env "EMAIL_DJANGO_DEFAULT" "$django_default_email"
# Set random secret values
python3 $INSTALL_PATH/build.py change-secret-key >/dev/null
python3 $INSTALL_PATH/build.py change-database-credentials >/dev/null
# Set new secrets only if not previously set
if has_backup_with_secrets; then
for config in DB_USER DB_PASS DJANGO_SECRET_KEY; do
value=$(get_env "$config" "$ENV_BACKUP")
set_env "$config" "$value"
done
else
python3 $INSTALL_PATH/build.py change-secret-key >/dev/null
python3 $INSTALL_PATH/build.py change-database-credentials >/dev/null
fi
# SSL Configuration
use_letsencrypt_lower=$(echo "$use_letsencrypt" | tr '[:upper:]' '[:lower:]')
if [[ "$use_letsencrypt_lower" == "y" || "$use_letsencrypt_lower" == "yes" ]]; then
Expand Down