|
1 | 1 | #!/bin/bash |
2 | | -set -u |
| 2 | +set -euo pipefail |
3 | 3 |
|
4 | | -echo "🔍 Starting Devcontainer Troubleshooting..." |
5 | | -echo "----------------------------------------" |
| 4 | +# Source shared utilities |
| 5 | +SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" |
| 6 | +# shellcheck source=scripts/utils.sh |
| 7 | +source "$SCRIPT_DIR/utils.sh" |
| 8 | + |
| 9 | +ensure_root |
6 | 10 |
|
7 | | -# Change to the repository root relative to the script's location |
8 | | -cd "$(dirname "${BASH_SOURCE[0]}")/.." || exit |
| 11 | +log_info "Starting Devcontainer Troubleshooting..." |
| 12 | +echo "----------------------------------------" |
9 | 13 |
|
10 | 14 | ISSUE_FOUND=0 |
11 | 15 |
|
12 | 16 | # 1. Check for .env file |
13 | | -echo "Checking for .env file..." |
| 17 | +log_info "Checking for .env file..." |
14 | 18 | if [ ! -f .env ]; then |
15 | | - echo "❌ Error: .env file is missing." |
| 19 | + log_error ".env file is missing." |
16 | 20 | if [ -f .env.example ]; then |
17 | | - echo " -> .env.example found. Creating .env from template..." |
| 21 | + log_info ".env.example found. Creating .env from template..." |
18 | 22 | cp .env.example .env |
19 | | - echo " ✅ .env created. Please run './scripts/setup-env.sh' to populate it." |
| 23 | + log_success ".env created. Please run './scripts/setup-env.sh' to populate it." |
20 | 24 | else |
21 | | - echo " ❌ Error: .env.example is also missing. Cannot create .env block automatically." |
| 25 | + log_error ".env.example is also missing. Cannot create .env block automatically." |
22 | 26 | ISSUE_FOUND=1 |
23 | 27 | fi |
24 | 28 | else |
25 | | - # Basic check to see if .env has been filled out (checking for placeholder values or empty critical values) |
| 29 | + # Basic check to see if .env has been filled out (checking for placeholder values) |
26 | 30 | if grep -q "YOUR_GIT_NAME_HERE" .env || grep -q "YOUR_GIT_EMAIL_HERE" .env; then |
27 | | - echo "⚠️ Warning: .env file contains placeholder values." |
28 | | - echo " -> Please run './scripts/setup-env.sh' to configure your environment variables." |
| 31 | + log_warn ".env file contains placeholder values." |
| 32 | + log_info "Please run './scripts/setup-env.sh' to configure your environment variables." |
29 | 33 | ISSUE_FOUND=1 |
30 | 34 | else |
31 | | - echo "✅ .env file found and appears to be configured." |
| 35 | + log_success ".env file found and appears to be configured." |
32 | 36 | fi |
33 | 37 | fi |
34 | 38 | echo "----------------------------------------" |
35 | 39 |
|
36 | 40 | # 2. Check script permissions |
37 | | -echo "Checking script permissions..." |
| 41 | +log_info "Checking script permissions..." |
38 | 42 | PERM_ISSUE=0 |
39 | | -for script in scripts/*.sh templates/scripts/*.sh; do |
40 | | - if [ -f "$script" ]; then |
41 | | - if [ ! -x "$script" ]; then |
42 | | - echo "❌ Error: $script is missing execute permissions." |
43 | | - PERM_ISSUE=1 |
44 | | - fi |
| 43 | +# Check scripts in current scripts dir |
| 44 | +for script in scripts/*.sh; do |
| 45 | + if [ -f "$script" ] && [ ! -x "$script" ]; then |
| 46 | + log_error "$script is missing execute permissions." |
| 47 | + PERM_ISSUE=1 |
45 | 48 | fi |
46 | 49 | done |
47 | 50 |
|
48 | 51 | if [ $PERM_ISSUE -eq 1 ]; then |
49 | | - echo " -> Attempting to fix permissions..." |
50 | | - chmod +x scripts/*.sh templates/scripts/*.sh 2>/dev/null || true |
51 | | - echo " ✅ Added execute permissions to scripts." |
| 52 | + log_info "Attempting to fix permissions..." |
| 53 | + chmod +x scripts/*.sh 2>/dev/null || true |
| 54 | + log_success "Added execute permissions to scripts." |
52 | 55 | else |
53 | | - echo "✅ All scripts have correct execute permissions." |
| 56 | + log_success "All scripts have correct execute permissions." |
54 | 57 | fi |
55 | 58 | echo "----------------------------------------" |
56 | 59 |
|
57 | | -# 3. Check for specific dependencies (e.g., Make, Git) |
58 | | -echo "Checking dependencies..." |
59 | | -if ! command -v make &> /dev/null; then |
60 | | - echo "❌ Error: 'make' is not installed." |
61 | | - echo " -> Please ensure your Devcontainer has the necessary build tools." |
62 | | - ISSUE_FOUND=1 |
63 | | -else |
64 | | - echo "✅ 'make' is installed." |
65 | | -fi |
| 60 | +# 3. Check for specific dependencies |
| 61 | +log_info "Checking dependencies..." |
| 62 | +check_dep() { |
| 63 | + if ! command -v "$1" &> /dev/null; then |
| 64 | + log_error "'$1' is not installed." |
| 65 | + ISSUE_FOUND=1 |
| 66 | + else |
| 67 | + log_success "'$1' is installed." |
| 68 | + fi |
| 69 | +} |
66 | 70 |
|
67 | | -if ! command -v git &> /dev/null; then |
68 | | - echo "❌ Error: 'git' is not installed." |
69 | | - echo " -> Git is required for this Devcontainer." |
70 | | - ISSUE_FOUND=1 |
71 | | -else |
72 | | - echo "✅ 'git' is installed." |
73 | | -fi |
| 71 | +check_dep "make" |
| 72 | +check_dep "git" |
| 73 | +check_dep "gh" |
74 | 74 | echo "----------------------------------------" |
75 | 75 |
|
76 | 76 | # Final summary |
77 | 77 | if [ $ISSUE_FOUND -eq 1 ]; then |
78 | | - echo "⚠️ Troubleshooting complete, but some issues require your attention." |
79 | | - echo " Please review the warnings and errors above." |
| 78 | + log_warn "Troubleshooting complete, but some issues require your attention." |
80 | 79 | exit 1 |
81 | 80 | else |
82 | | - echo "🚀 Troubleshooting complete. Everything looks good!" |
| 81 | + log_success "Troubleshooting complete. Everything looks good!" |
83 | 82 | exit 0 |
84 | 83 | fi |
0 commit comments