-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstart-dev.sh
More file actions
executable file
·200 lines (177 loc) · 6.83 KB
/
Copy pathstart-dev.sh
File metadata and controls
executable file
·200 lines (177 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# =============================================================================
# DevelopmentTranslation Bridge - Development Startup Script
# =============================================================================
# Starts the complete development environment with Docker
# Supports: macOS, Linux, Windows (Git Bash/WSL)
# =============================================================================
set -e
# Colors for output (disabled if not a terminal)
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
BLUE=''
NC=''
fi
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} DevelopmentTranslation Bridge${NC}"
echo -e "${BLUE} Development Environment${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# -----------------------------------------------------------------------------
# Detect Platform
# -----------------------------------------------------------------------------
detect_platform() {
case "$(uname -s)" in
Darwin*) echo "macos" ;;
Linux*) echo "linux" ;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
*) echo "unknown" ;;
esac
}
PLATFORM=$(detect_platform)
echo -e "${YELLOW}Platform:${NC} $PLATFORM"
# -----------------------------------------------------------------------------
# Check Docker
# -----------------------------------------------------------------------------
echo -e "${YELLOW}Checking Docker...${NC}"
if ! command -v docker &> /dev/null; then
echo -e "${RED}ERROR: Docker is not installed!${NC}"
echo "Please install Docker Desktop from https://docker.com/get-started"
exit 1
fi
if ! docker info > /dev/null 2>&1; then
echo -e "${RED}ERROR: Docker is not running!${NC}"
echo "Please start Docker Desktop and try again."
exit 1
fi
echo -e "${GREEN}Docker is running${NC}"
# -----------------------------------------------------------------------------
# Setup .env File
# -----------------------------------------------------------------------------
if [ ! -f ".env" ]; then
echo ""
echo -e "${YELLOW}Creating .env file...${NC}"
if [ -f ".env.example" ]; then
cp .env.example .env
echo -e "${GREEN}Created .env from .env.example${NC}"
# Check if keys are still placeholders
if grep -q "put-your-unique-phrase-here" .env; then
echo -e "${YELLOW}Generating security keys...${NC}"
generate_key() {
if command -v openssl &> /dev/null; then
openssl rand -base64 48 | tr -d '\n' | head -c 64
elif [ -r /dev/urandom ]; then
head -c 48 /dev/urandom 2>/dev/null | base64 | tr -d '\n' | head -c 64
else
date +%s%N 2>/dev/null | shasum -a 256 | head -c 64 || \
date +%s | md5sum | head -c 64
fi
}
# Replace placeholder keys
for KEY in AUTH_KEY SECURE_AUTH_KEY LOGGED_IN_KEY NONCE_KEY AUTH_SALT SECURE_AUTH_SALT LOGGED_IN_SALT NONCE_SALT; do
NEW_VALUE=$(generate_key)
if [[ "$PLATFORM" == "macos" ]]; then
sed -i '' "s|${KEY}='put-your-unique-phrase-here'|${KEY}='${NEW_VALUE}'|g" .env
else
sed -i "s|${KEY}='put-your-unique-phrase-here'|${KEY}='${NEW_VALUE}'|g" .env
fi
done
echo -e "${GREEN}Security keys generated${NC}"
fi
# Set Docker mode based on platform
if [[ "$PLATFORM" == "linux" ]]; then
if [[ "$PLATFORM" == "macos" ]]; then
sed -i '' "s|VITE_DOCKER_MODE=false|VITE_DOCKER_MODE=true|g" .env
else
sed -i "s|VITE_DOCKER_MODE=false|VITE_DOCKER_MODE=true|g" .env
fi
fi
else
echo -e "${RED}ERROR: .env.example not found!${NC}"
echo "Please run ./setup.sh first or ensure you have the complete repository."
exit 1
fi
else
echo -e "${GREEN}.env file exists${NC}"
fi
# Load environment variables
set -a
source .env 2>/dev/null || true
set +a
# Use defaults if not set
WORDPRESS_PORT=${WORDPRESS_PORT:-8080}
PHPMYADMIN_PORT=${PHPMYADMIN_PORT:-8081}
VITE_PORT=${VITE_PORT:-3000}
# -----------------------------------------------------------------------------
# Start Docker Containers
# -----------------------------------------------------------------------------
echo ""
echo -e "${YELLOW}Starting Docker containers...${NC}"
docker-compose up -d
# Wait for WordPress
echo ""
echo -e "${YELLOW}Waiting for WordPress to be ready...${NC}"
WORDPRESS_URL="http://localhost:${WORDPRESS_PORT}"
MAX_WAIT=90
WAITED=0
until curl -s "$WORDPRESS_URL" > /dev/null 2>&1; do
if [ $WAITED -ge $MAX_WAIT ]; then
echo -e "${RED}ERROR: WordPress did not start within ${MAX_WAIT} seconds${NC}"
echo "Check Docker logs: docker-compose logs wordpress"
exit 1
fi
printf " Waiting... (%ds)\r" $WAITED
sleep 3
WAITED=$((WAITED + 3))
done
echo ""
echo -e "${GREEN}WordPress is ready!${NC}"
# -----------------------------------------------------------------------------
# Check Node Modules
# -----------------------------------------------------------------------------
if [ -d "admin" ] && [ ! -d "admin/node_modules" ]; then
echo ""
echo -e "${YELLOW}Installing admin interface dependencies...${NC}"
cd admin && npm install && cd ..
echo -e "${GREEN}Admin dependencies installed${NC}"
fi
# -----------------------------------------------------------------------------
# Success Message
# -----------------------------------------------------------------------------
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Development Environment Ready!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "${BLUE}Services:${NC}"
echo " WordPress: http://localhost:${WORDPRESS_PORT}"
echo " WP Admin: http://localhost:${WORDPRESS_PORT}/wp-admin"
echo " phpMyAdmin: http://localhost:${PHPMYADMIN_PORT}"
echo " REST API: http://localhost:${WORDPRESS_PORT}/wp-json/devtb/v2/"
echo ""
echo -e "${BLUE}Next Steps:${NC}"
echo " 1. Complete WordPress install: http://localhost:${WORDPRESS_PORT}"
echo " 2. Activate 'DevelopmentTranslation Bridge' theme"
echo " 3. Start Visual Interface dev server:"
echo " cd admin && npm run dev"
echo " 4. Access 'Visual Interface' in WordPress admin menu"
echo ""
echo -e "${BLUE}Useful Commands:${NC}"
echo " make docker-down # Stop containers"
echo " make docker-logs # View logs"
echo " make test # Run tests"
echo ""
echo -e "${GREEN}Happy coding!${NC}"
echo ""