Private
Public Access
1
0

Add colored output and UX improvements to setup.sh

- Config option labels (domain, email, etc.) shown in bold blue
- Errors in red, warnings in yellow, success checkmarks in green
- Password field: note that input won't appear on screen
- SMTP prompt: "if you don't know what this is, press Enter to skip"
- Summary next steps: detailed A record fields (Type, Name, Value, TTL)
  with explanations, dig command with success/failure examples,
  "copy this command into the server terminal" instead of "run"
- Matching color scheme with install.sh (header, section, etc.)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
constantprojects
2026-02-24 08:59:14 -07:00
parent d76c572af8
commit a35569863e

154
setup.sh
View File

@@ -7,18 +7,28 @@ set -eo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
echo ""
echo "═══════════════════════════════════════════════════════════"
echo " WebsiteBox Setup Wizard"
echo "═══════════════════════════════════════════════════════════"
echo ""
# --- Colors and formatting ---
BOLD='\033[1m'
DIM='\033[2m'
RESET='\033[0m'
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
ORANGE='\033[1;38;5;208m'
CYAN='\033[1;36m'
BLUE='\033[1;34m'
WHITE='\033[1;37m'
printf "\n${WHITE}═══════════════════════════════════════════════════════════${RESET}\n"
printf " ${BOLD}WebsiteBox Setup Wizard${RESET}\n"
printf "${WHITE}═══════════════════════════════════════════════════════════${RESET}\n\n"
# --- Prerequisite Checks ---
check_command() {
if ! command -v "$1" &>/dev/null; then
echo "ERROR: $1 is not installed."
echo "$2"
printf "${RED} $1 is not installed.${RESET}\n"
printf "${RED} $2${RESET}\n"
exit 1
fi
}
@@ -26,24 +36,24 @@ check_command() {
check_command docker "Install Docker: https://docs.docker.com/engine/install/"
if ! docker compose version &>/dev/null; then
echo "ERROR: Docker Compose (v2) is not available."
echo "Install it: https://docs.docker.com/compose/install/"
printf "${RED} Docker Compose (v2) is not available.${RESET}\n"
printf "${RED} Install it: https://docs.docker.com/compose/install/${RESET}\n"
exit 1
fi
# Check if Docker is accessible
if ! docker info &>/dev/null; then
echo "ERROR: Cannot connect to Docker daemon."
echo "Make sure Docker is running and your user has permission."
echo "You may need to: sudo usermod -aG docker \$USER && newgrp docker"
printf "${RED} Cannot connect to Docker daemon.${RESET}\n"
printf "${RED} Make sure Docker is running and your user has permission.${RESET}\n"
printf "${RED} You may need to: sudo usermod -aG docker \$USER && newgrp docker${RESET}\n"
exit 1
fi
# Check ports
for port in 80 443; do
if ss -tlnp 2>/dev/null | grep -q ":${port} " || netstat -tlnp 2>/dev/null | grep -q ":${port} "; then
echo "WARNING: Port ${port} is already in use."
echo "Another service may need to be stopped first."
printf "${YELLOW} Port ${port} is already in use.${RESET}\n"
printf "${YELLOW} Another service may need to be stopped first.${RESET}\n"
read -rp "Continue anyway? (y/N) " cont
if [ "$cont" != "y" ] && [ "$cont" != "Y" ]; then
exit 1
@@ -64,31 +74,33 @@ generate_salt() {
# --- Collect Configuration ---
echo "Please provide the following configuration:"
echo ""
printf "Please provide the following configuration:\n\n"
# Domain
while true; do
read -rp "Domain name (e.g., example.com): " DOMAIN
printf "${BLUE}Domain name${RESET} (e.g., example.com): "
read -r DOMAIN
if [[ "$DOMAIN" =~ ^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+$ ]]; then
break
fi
echo "Invalid domain format. Please enter a valid domain (e.g., example.com)"
printf "${RED} Invalid domain format. Please enter a valid domain (e.g., example.com)${RESET}\n"
done
# Site title
read -rp "Site title [My Portfolio]: " SITE_TITLE
printf "${BLUE}Site title${RESET} [My Portfolio]: "
read -r SITE_TITLE
SITE_TITLE="${SITE_TITLE:-My Portfolio}"
# Admin username
while true; do
read -rp "WordPress admin username: " ADMIN_USER
printf "${BLUE}WordPress admin username${RESET}: "
read -r ADMIN_USER
if [ -z "$ADMIN_USER" ]; then
echo "Username cannot be empty."
printf "${RED} Username cannot be empty.${RESET}\n"
continue
fi
if [ "$ADMIN_USER" = "admin" ]; then
echo "For security, please choose a username other than 'admin'."
printf "${YELLOW} For security, please choose a username other than 'admin'.${RESET}\n"
continue
fi
break
@@ -96,75 +108,88 @@ done
# Admin email
while true; do
read -rp "Admin email (used for SSL & WordPress): " ADMIN_EMAIL
printf "${BLUE}Admin email${RESET} (used for SSL & WordPress): "
read -r ADMIN_EMAIL
if [[ "$ADMIN_EMAIL" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
break
fi
echo "Please enter a valid email address."
printf "${RED} Please enter a valid email address.${RESET}\n"
done
# Admin password
echo ""
echo "Set your WordPress admin password."
echo "Press Enter to auto-generate a secure 20-character password."
printf "${BLUE}Set your WordPress admin password.${RESET}\n"
printf "${DIM} Press Enter to auto-generate a secure 20-character password.${RESET}\n"
printf "${DIM} Note: your password won't appear on screen as you type — that's normal.${RESET}\n"
while true; do
read -rsp "Admin password: " ADMIN_PASSWORD
printf "${BLUE}Admin password${RESET}: "
read -rs ADMIN_PASSWORD
echo ""
if [ -z "$ADMIN_PASSWORD" ]; then
ADMIN_PASSWORD=$(generate_password 20)
PASSWORD_AUTO_GENERATED=true
echo "Password auto-generated."
printf "${GREEN}Password auto-generated.${RESET}\n"
break
fi
if [ ${#ADMIN_PASSWORD} -lt 12 ]; then
echo "Password must be at least 12 characters."
printf "${RED} Password must be at least 12 characters.${RESET}\n"
continue
fi
read -rsp "Confirm password: " ADMIN_PASSWORD_CONFIRM
printf "${BLUE}Confirm password${RESET}: "
read -rs ADMIN_PASSWORD_CONFIRM
echo ""
if [ "$ADMIN_PASSWORD" != "$ADMIN_PASSWORD_CONFIRM" ]; then
echo "Passwords do not match. Try again."
printf "${RED} Passwords do not match. Try again.${RESET}\n"
continue
fi
PASSWORD_AUTO_GENERATED=false
printf "${GREEN} ✓ Password set.${RESET}\n"
break
done
# Age Gate
echo ""
read -rp "Enable age verification gate? (Y/n): " AGE_GATE_INPUT
printf "${BLUE}Enable age verification gate?${RESET} (Y/n): "
read -r AGE_GATE_INPUT
if [ "$AGE_GATE_INPUT" = "n" ] || [ "$AGE_GATE_INPUT" = "N" ]; then
AGE_GATE_ENABLED=false
AGE_GATE_MIN_AGE=18
else
AGE_GATE_ENABLED=true
read -rp "Minimum age (18-21) [18]: " AGE_GATE_MIN_AGE
printf "${BLUE}Minimum age${RESET} (18-21) [18]: "
read -r AGE_GATE_MIN_AGE
AGE_GATE_MIN_AGE="${AGE_GATE_MIN_AGE:-18}"
if [ "$AGE_GATE_MIN_AGE" -lt 18 ] 2>/dev/null || [ "$AGE_GATE_MIN_AGE" -gt 21 ] 2>/dev/null; then
echo "Invalid age. Using default: 18"
printf "${YELLOW} Invalid age. Using default: 18${RESET}\n"
AGE_GATE_MIN_AGE=18
fi
fi
# SMTP (optional)
echo ""
read -rp "SMTP server (optional, press Enter to skip): " SMTP_HOST
printf "${BLUE}SMTP server${RESET} (if you don't know what this is, press Enter to skip): "
read -r SMTP_HOST
SMTP_PORT=587
SMTP_USER=""
SMTP_PASS=""
SMTP_FROM=""
if [ -n "$SMTP_HOST" ]; then
read -rp "SMTP port [587]: " SMTP_PORT_INPUT
printf "${BLUE}SMTP port${RESET} [587]: "
read -r SMTP_PORT_INPUT
SMTP_PORT="${SMTP_PORT_INPUT:-587}"
read -rp "SMTP username: " SMTP_USER
read -rsp "SMTP password: " SMTP_PASS
printf "${BLUE}SMTP username${RESET}: "
read -r SMTP_USER
printf "${BLUE}SMTP password${RESET}: "
read -rs SMTP_PASS
echo ""
read -rp "SMTP from address [${ADMIN_EMAIL}]: " SMTP_FROM_INPUT
printf "${BLUE}SMTP from address${RESET} [${ADMIN_EMAIL}]: "
read -r SMTP_FROM_INPUT
SMTP_FROM="${SMTP_FROM_INPUT:-$ADMIN_EMAIL}"
fi
# Backup retention
read -rp "Days to keep local backups (1-365) [30]: " BACKUP_RETENTION_DAYS
printf "${BLUE}Days to keep local backups${RESET} (1-365) [30]: "
read -r BACKUP_RETENTION_DAYS
BACKUP_RETENTION_DAYS="${BACKUP_RETENTION_DAYS:-30}"
# --- Auto-generated Values ---
@@ -246,29 +271,36 @@ SERVER_IP=$(curl -s -4 ifconfig.me 2>/dev/null || curl -s -4 icanhazip.com 2>/de
# --- Print Summary ---
echo ""
echo "═══════════════════════════════════════════════════════════"
echo " WebsiteBox Setup Complete!"
echo "═══════════════════════════════════════════════════════════"
echo ""
echo " Configuration saved to .env"
echo ""
echo " Next steps:"
echo " 1. Point your domain's A record to this server's IP: ${SERVER_IP}"
echo " 2. Wait for DNS propagation (check: dig ${DOMAIN})"
echo " 3. Run: docker compose up -d"
echo " 4. Access your site at: https://${DOMAIN}"
echo " 5. Log in at: https://${DOMAIN}/wp-admin"
echo " Username: ${ADMIN_USER}"
printf "\n${WHITE}═══════════════════════════════════════════════════════════${RESET}\n"
printf " ${GREEN}${BOLD}WebsiteBox Setup Complete!${RESET}\n"
printf "${WHITE}═══════════════════════════════════════════════════════════${RESET}\n\n"
printf " ${GREEN}${RESET} Configuration saved to ${BOLD}.env${RESET}\n\n"
printf " ${BOLD}Next steps:${RESET}\n\n"
printf " ${BLUE}1.${RESET} ${BOLD}Point your domain's A record to this server${RESET}\n"
printf " Log in to your domain registrar and add a DNS record:\n"
printf " ${DIM}Type:${RESET} A\n"
printf " ${DIM}Name:${RESET} @ ${DIM}(this means the root domain, e.g., ${DOMAIN})${RESET}\n"
printf " ${DIM}Value:${RESET} ${BOLD}${SERVER_IP}${RESET} ${DIM}(your server's IP address)${RESET}\n"
printf " ${DIM}TTL:${RESET} Auto ${DIM}(or the lowest option available)${RESET}\n\n"
printf " ${BLUE}2.${RESET} ${BOLD}Wait for DNS propagation, then verify it's working${RESET}\n"
printf " Copy this command into the server terminal:\n\n"
printf " ${CYAN}dig ${DOMAIN} +short${RESET}\n\n"
printf " ${GREEN}✓ Success looks like:${RESET} ${BOLD}${SERVER_IP}${RESET}\n"
printf " ${RED}✗ Not ready yet:${RESET} ${DIM}(blank output or a different IP — wait a few minutes and try again)${RESET}\n\n"
printf " ${BLUE}3.${RESET} ${BOLD}Launch your website${RESET}\n"
printf " Once DNS is working, copy this command into the server terminal:\n\n"
printf " ${CYAN}docker compose up -d${RESET}\n\n"
printf " ${BLUE}4.${RESET} ${BOLD}Visit your site${RESET}\n"
printf " Your website: ${CYAN}https://${DOMAIN}${RESET}\n"
printf " Admin login: ${CYAN}https://${DOMAIN}/wp-admin${RESET}\n"
printf " Username: ${BOLD}${ADMIN_USER}${RESET}\n"
if [ "$PASSWORD_AUTO_GENERATED" = true ]; then
echo " Password: ${ADMIN_PASSWORD}"
echo ""
echo " WARNING: Your auto-generated password has also been saved to: .credentials"
echo " Delete this file after recording your password somewhere secure."
printf " Password: ${BOLD}${ADMIN_PASSWORD}${RESET}\n\n"
printf " ${YELLOW}${RESET} Your auto-generated password has also been saved to: ${BOLD}.credentials${RESET}\n"
printf " Delete this file after recording your password somewhere secure.\n"
else
echo " Password: ******* (the password you set during setup)"
printf " Password: ${DIM}(the password you set during setup)${RESET}\n"
fi
echo ""
echo "═══════════════════════════════════════════════════════════"
printf "\n${WHITE}═══════════════════════════════════════════════════════════${RESET}\n"