-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·236 lines (214 loc) · 7.79 KB
/
install.sh
File metadata and controls
executable file
·236 lines (214 loc) · 7.79 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env bash
#
# WP Code Check - Installation Script
# Version: 1.0.0
#
# Quick install for shell users
# Usage: ./install.sh
set -e
# Check if running in interactive mode (TTY available)
# If not interactive, use sensible defaults without prompting
INTERACTIVE=true
if [ ! -t 0 ] || [ ! -t 1 ]; then
INTERACTIVE=false
fi
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Get installation directory (where this script is located)
INSTALL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo ""
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ WP Code Check - Installation Wizard ║"
echo "║ ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
echo -e "${BLUE}Installation directory:${NC} $INSTALL_DIR"
echo ""
# Detect shell
SHELL_RC=""
SHELL_NAME=""
if [ -n "$ZSH_VERSION" ]; then
SHELL_RC="$HOME/.zshrc"
SHELL_NAME="zsh"
elif [ -n "$BASH_VERSION" ]; then
if [ -f "$HOME/.bashrc" ]; then
SHELL_RC="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
SHELL_RC="$HOME/.bash_profile"
fi
SHELL_NAME="bash"
else
# Try to detect from SHELL environment variable
case "$SHELL" in
*/zsh)
SHELL_RC="$HOME/.zshrc"
SHELL_NAME="zsh"
;;
*/bash)
if [ -f "$HOME/.bashrc" ]; then
SHELL_RC="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
SHELL_RC="$HOME/.bash_profile"
fi
SHELL_NAME="bash"
;;
esac
fi
if [ -z "$SHELL_RC" ]; then
echo -e "${YELLOW}⚠ Could not detect shell configuration file${NC}"
echo "Please manually add the alias to your shell configuration."
SHELL_RC="$HOME/.bashrc" # Default fallback
else
echo -e "${GREEN}✓ Detected shell:${NC} $SHELL_NAME ($SHELL_RC)"
fi
echo ""
# Make scripts executable
echo -e "${BLUE}[1/4]${NC} Making scripts executable..."
chmod +x "$INSTALL_DIR/dist/bin/check-performance.sh"
chmod +x "$INSTALL_DIR/dist/bin/json-to-html.py"
chmod +x "$INSTALL_DIR/dist/bin/run"
if [ -f "$INSTALL_DIR/dist/bin/ai-triage.py" ]; then
chmod +x "$INSTALL_DIR/dist/bin/ai-triage.py"
fi
echo -e "${GREEN}✓ Scripts are now executable${NC}"
echo ""
# Offer to add aliases
echo -e "${BLUE}[2/5]${NC} Shell alias configuration"
echo ""
ALIAS_ADDED=false
if [ "$INTERACTIVE" = true ]; then
# Interactive mode - ask user
echo "Would you like to add shell aliases for WP Code Check?"
echo "This will add the following lines to $SHELL_RC:"
echo ""
echo -e "${YELLOW} alias wpcc='$INSTALL_DIR/dist/bin/check-performance.sh --paths'${NC}"
echo -e "${YELLOW} alias wp-check='$INSTALL_DIR/dist/bin/check-performance.sh --paths'${NC}"
echo ""
echo "(wpcc = primary branding, wp-check = legacy compatibility)"
echo ""
read -p "Add aliases? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Check if aliases already exist
if grep -q "alias wpcc=" "$SHELL_RC" 2>/dev/null; then
echo -e "${YELLOW}⚠ Alias 'wpcc' already exists in $SHELL_RC${NC}"
echo "Skipping alias creation."
else
echo "" >> "$SHELL_RC"
echo "# WP Code Check aliases (added by install.sh on $(date +%Y-%m-%d))" >> "$SHELL_RC"
echo "alias wpcc='$INSTALL_DIR/dist/bin/check-performance.sh --paths'" >> "$SHELL_RC"
echo "alias wp-check='$INSTALL_DIR/dist/bin/check-performance.sh --paths'" >> "$SHELL_RC"
echo -e "${GREEN}✓ Aliases added to $SHELL_RC${NC}"
ALIAS_ADDED=true
fi
else
echo "Skipping alias creation."
echo ""
echo "To use WP Code Check, run:"
echo -e "${YELLOW} $INSTALL_DIR/dist/bin/check-performance.sh --paths <directory>${NC}"
fi
else
# Non-interactive mode - auto-add aliases
echo "Non-interactive mode detected. Auto-configuring aliases..."
if grep -q "alias wpcc=" "$SHELL_RC" 2>/dev/null; then
echo -e "${YELLOW}⚠ Alias 'wpcc' already exists in $SHELL_RC${NC}"
else
echo "" >> "$SHELL_RC"
echo "# WP Code Check aliases (added by install.sh on $(date +%Y-%m-%d))" >> "$SHELL_RC"
echo "alias wpcc='$INSTALL_DIR/dist/bin/check-performance.sh --paths'" >> "$SHELL_RC"
echo "alias wp-check='$INSTALL_DIR/dist/bin/check-performance.sh --paths'" >> "$SHELL_RC"
echo -e "${GREEN}✓ Aliases added to $SHELL_RC${NC}"
ALIAS_ADDED=true
fi
fi
echo ""
# Offer to add shell completion
echo -e "${BLUE}[3/5]${NC} Shell completion (tab completion)"
echo ""
if [ "$INTERACTIVE" = true ]; then
# Interactive mode - ask user
echo "Would you like to enable tab completion for wpcc/wp-check?"
echo "This allows you to press TAB to complete options like --format, --paths, --ai-triage, etc."
echo ""
read -p "Enable tab completion? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
if grep -q "wp-check-completion.bash" "$SHELL_RC" 2>/dev/null; then
echo -e "${YELLOW}⚠ Completion already configured in $SHELL_RC${NC}"
else
echo "" >> "$SHELL_RC"
echo "# WP Code Check tab completion (added by install.sh on $(date +%Y-%m-%d))" >> "$SHELL_RC"
echo "source '$INSTALL_DIR/dist/bin/wp-check-completion.bash'" >> "$SHELL_RC"
echo -e "${GREEN}✓ Tab completion added to $SHELL_RC${NC}"
if [ "$ALIAS_ADDED" = true ]; then
echo -e "${YELLOW}Note: Run 'source $SHELL_RC' to enable alias and completion${NC}"
fi
fi
else
echo "Skipping tab completion."
if [ "$ALIAS_ADDED" = true ]; then
echo -e "${YELLOW}Note: Run 'source $SHELL_RC' to enable the alias${NC}"
fi
fi
else
# Non-interactive mode - auto-add completion
echo "Auto-configuring tab completion..."
if grep -q "wp-check-completion.bash" "$SHELL_RC" 2>/dev/null; then
echo -e "${YELLOW}⚠ Completion already configured in $SHELL_RC${NC}"
else
echo "" >> "$SHELL_RC"
echo "# WP Code Check tab completion (added by install.sh on $(date +%Y-%m-%d))" >> "$SHELL_RC"
echo "source '$INSTALL_DIR/dist/bin/wp-check-completion.bash'" >> "$SHELL_RC"
echo -e "${GREEN}✓ Tab completion added to $SHELL_RC${NC}"
fi
fi
echo ""
# Test installation
echo -e "${BLUE}[4/5]${NC} Testing installation..."
if [ -d "$INSTALL_DIR/dist/tests/fixtures" ]; then
TEST_OUTPUT=$("$INSTALL_DIR/dist/bin/check-performance.sh" --paths "$INSTALL_DIR/dist/tests/fixtures" --format json --no-log 2>&1)
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Installation test passed${NC}"
else
echo -e "${RED}✗ Installation test failed${NC}"
echo "Output: $TEST_OUTPUT"
fi
else
echo -e "${YELLOW}⚠ Test fixtures not found, skipping test${NC}"
fi
echo ""
# Show quick start
echo -e "${BLUE}[5/5]${NC} Quick Start Guide"
echo ""
echo -e "${GREEN}Installation complete!${NC}"
echo ""
echo "Quick start examples:"
echo ""
echo -e " ${YELLOW}# Scan a WordPress plugin${NC}"
echo " wp-check ~/path/to/plugin"
echo ""
echo -e " ${YELLOW}# Scan current directory${NC}"
echo " wp-check ."
echo ""
echo -e " ${YELLOW}# Scan with strict mode (fail on warnings)${NC}"
echo " wp-check ~/plugin --strict"
echo ""
echo -e " ${YELLOW}# Generate baseline for legacy code${NC}"
echo " wp-check ~/plugin --generate-baseline"
echo ""
echo "Documentation:"
echo " • User Guide: $INSTALL_DIR/dist/README.md"
echo " • Quick Start: $INSTALL_DIR/SHELL-QUICKSTART.md"
echo " • Templates: $INSTALL_DIR/dist/HOWTO-TEMPLATES.md"
echo " • Changelog: $INSTALL_DIR/CHANGELOG.md"
echo ""
echo "For help:"
echo " wp-check --help"
echo ""
echo -e "${GREEN}Happy scanning! 🚀${NC}"
echo ""