|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# ============================================================================= |
| 4 | +# New Certification Setup Script |
| 5 | +# Creates a new certification folder with all template files |
| 6 | +# ============================================================================= |
| 7 | + |
| 8 | +set -e |
| 9 | + |
| 10 | +# Colors for output |
| 11 | +RED='\033[0;31m' |
| 12 | +GREEN='\033[0;32m' |
| 13 | +YELLOW='\033[1;33m' |
| 14 | +BLUE='\033[0;34m' |
| 15 | +NC='\033[0m' # No Color |
| 16 | + |
| 17 | +# Get script directory and project root |
| 18 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 19 | +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" |
| 20 | +TEMPLATES_DIR="$PROJECT_ROOT/.templates" |
| 21 | +CERTS_DIR="$PROJECT_ROOT/certifications" |
| 22 | + |
| 23 | +# Function to print colored output |
| 24 | +print_info() { echo -e "${BLUE}ℹ${NC} $1"; } |
| 25 | +print_success() { echo -e "${GREEN}✓${NC} $1"; } |
| 26 | +print_warning() { echo -e "${YELLOW}⚠${NC} $1"; } |
| 27 | +print_error() { echo -e "${RED}✗${NC} $1"; } |
| 28 | + |
| 29 | +# Function to show usage |
| 30 | +show_usage() { |
| 31 | + echo "" |
| 32 | + echo "Usage: $0 <provider> <exam-code> <certification-name>" |
| 33 | + echo "" |
| 34 | + echo "Arguments:" |
| 35 | + echo " provider Provider folder name (e.g., aws, github, google-cloud, microsoft)" |
| 36 | + echo " exam-code Exam code folder name (e.g., saa-c03, az-900, gh-200)" |
| 37 | + echo " certification-name Full certification name in quotes" |
| 38 | + echo "" |
| 39 | + echo "Examples:" |
| 40 | + echo " $0 aws saa-c03 \"AWS Solutions Architect Associate\"" |
| 41 | + echo " $0 microsoft az-900 \"Azure Fundamentals\"" |
| 42 | + echo " $0 google-cloud ace \"Associate Cloud Engineer\"" |
| 43 | + echo "" |
| 44 | + exit 1 |
| 45 | +} |
| 46 | + |
| 47 | +# Check arguments |
| 48 | +if [ $# -lt 3 ]; then |
| 49 | + print_error "Missing required arguments" |
| 50 | + show_usage |
| 51 | +fi |
| 52 | + |
| 53 | +PROVIDER="$1" |
| 54 | +EXAM_CODE="$2" |
| 55 | +CERT_NAME="$3" |
| 56 | + |
| 57 | +# Derive values |
| 58 | +EXAM_CODE_UPPER=$(echo "$EXAM_CODE" | tr '[:lower:]' '[:upper:]') |
| 59 | +EXAM_CODE_LOWER=$(echo "$EXAM_CODE" | tr '[:upper:]' '[:lower:]') |
| 60 | +CURRENT_DATE=$(date +%Y-%m-%d) |
| 61 | +CURRENT_MONTH_YEAR=$(date +"%B %Y") |
| 62 | + |
| 63 | +# Target directory |
| 64 | +TARGET_DIR="$CERTS_DIR/$PROVIDER/$EXAM_CODE_LOWER" |
| 65 | + |
| 66 | +echo "" |
| 67 | +echo "==============================================" |
| 68 | +echo " New Certification Setup" |
| 69 | +echo "==============================================" |
| 70 | +echo "" |
| 71 | +print_info "Provider: $PROVIDER" |
| 72 | +print_info "Exam Code: $EXAM_CODE_UPPER" |
| 73 | +print_info "Certification: $CERT_NAME" |
| 74 | +print_info "Target Directory: $TARGET_DIR" |
| 75 | +echo "" |
| 76 | + |
| 77 | +# Check if templates directory exists |
| 78 | +if [ ! -d "$TEMPLATES_DIR" ]; then |
| 79 | + print_error "Templates directory not found: $TEMPLATES_DIR" |
| 80 | + exit 1 |
| 81 | +fi |
| 82 | + |
| 83 | +# Check if target already exists |
| 84 | +if [ -d "$TARGET_DIR" ]; then |
| 85 | + print_warning "Directory already exists: $TARGET_DIR" |
| 86 | + read -p "Overwrite existing files? (y/N): " -n 1 -r |
| 87 | + echo |
| 88 | + if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 89 | + print_info "Aborted." |
| 90 | + exit 0 |
| 91 | + fi |
| 92 | +fi |
| 93 | + |
| 94 | +# Create directory |
| 95 | +print_info "Creating directory structure..." |
| 96 | +mkdir -p "$TARGET_DIR" |
| 97 | +print_success "Created: $TARGET_DIR" |
| 98 | + |
| 99 | +# Copy template files |
| 100 | +print_info "Copying template files..." |
| 101 | + |
| 102 | +cp "$TEMPLATES_DIR/index-template.md" "$TARGET_DIR/index.md" |
| 103 | +print_success "Created: index.md" |
| 104 | + |
| 105 | +cp "$TEMPLATES_DIR/objectives-template.md" "$TARGET_DIR/objectives.md" |
| 106 | +print_success "Created: objectives.md" |
| 107 | + |
| 108 | +cp "$TEMPLATES_DIR/notes-template.md" "$TARGET_DIR/notes.md" |
| 109 | +print_success "Created: notes.md" |
| 110 | + |
| 111 | +cp "$TEMPLATES_DIR/quick-refresher-template.md" "$TARGET_DIR/quick-refresher.md" |
| 112 | +print_success "Created: quick-refresher.md" |
| 113 | + |
| 114 | +cp "$TEMPLATES_DIR/exam-tips-template.md" "$TARGET_DIR/exam-tips.md" |
| 115 | +print_success "Created: exam-tips.md" |
| 116 | + |
| 117 | +# Replace common placeholders |
| 118 | +print_info "Replacing placeholders..." |
| 119 | + |
| 120 | +# Function to replace in all files |
| 121 | +replace_in_files() { |
| 122 | + local search="$1" |
| 123 | + local replace="$2" |
| 124 | + for file in "$TARGET_DIR"/*.md; do |
| 125 | + if [[ "$OSTYPE" == "darwin"* ]]; then |
| 126 | + # macOS |
| 127 | + sed -i '' "s|$search|$replace|g" "$file" |
| 128 | + else |
| 129 | + # Linux |
| 130 | + sed -i "s|$search|$replace|g" "$file" |
| 131 | + fi |
| 132 | + done |
| 133 | +} |
| 134 | + |
| 135 | +replace_in_files '\[CERT-CODE\]' "$EXAM_CODE_UPPER" |
| 136 | +replace_in_files '\[cert-code\]' "$EXAM_CODE_LOWER" |
| 137 | +replace_in_files '\[Certification Name\]' "$CERT_NAME" |
| 138 | +replace_in_files '\[Provider Name\]' "$PROVIDER" |
| 139 | +replace_in_files '\[YYYY-MM-DD\]' "$CURRENT_DATE" |
| 140 | +replace_in_files '\[Month Year\]' "$CURRENT_MONTH_YEAR" |
| 141 | + |
| 142 | +print_success "Placeholders replaced" |
| 143 | + |
| 144 | +echo "" |
| 145 | +echo "==============================================" |
| 146 | +print_success "Certification created successfully!" |
| 147 | +echo "==============================================" |
| 148 | +echo "" |
| 149 | +echo "Next steps:" |
| 150 | +echo "" |
| 151 | +echo " 1. Edit the files in: $TARGET_DIR" |
| 152 | +echo " - index.md (exam info, overview)" |
| 153 | +echo " - objectives.md (exam domains)" |
| 154 | +echo " - notes.md (study content)" |
| 155 | +echo " - quick-refresher.md (cram sheet)" |
| 156 | +echo " - exam-tips.md (strategies)" |
| 157 | +echo "" |
| 158 | +echo " 2. Update .vitepress/config.mts:" |
| 159 | +echo " - Add to nav dropdown" |
| 160 | +echo " - Add to sidebar" |
| 161 | +echo "" |
| 162 | +echo " 3. Update certifications/index.md" |
| 163 | +echo "" |
| 164 | +echo " 4. Update index.md (home page)" |
| 165 | +echo "" |
| 166 | +echo " 5. Run: npm run docs:dev" |
| 167 | +echo "" |
| 168 | +print_info "See ADDING_CERTIFICATIONS.md for detailed instructions" |
| 169 | +echo "" |
0 commit comments