#!/bin/bash # Simple Server Setup Script - Run this ON YOUR SERVER after git push # Usage: ./setup-server.sh set -e echo "๐Ÿš€ Bizoni Server Setup Script" echo "============================" # Configuration - UPDATE THESE IF NEEDED BLOG_DIR="/var/www/bizoni/blog" IMG_DIR="/var/www/bizoni/img/blog" BACKUP_DIR="/var/backups/bizoni" echo "๐Ÿ“ Blog directory: $BLOG_DIR" echo "๐Ÿ–ผ๏ธ Image directory: $IMG_DIR" echo "" # Check if directories exist if [ ! -d "$BLOG_DIR" ]; then echo "โŒ Blog directory not found: $BLOG_DIR" echo "Please update BLOG_DIR in this script" exit 1 fi if [ ! -d "$IMG_DIR" ]; then echo "โŒ Image directory not found: $IMG_DIR" echo "Please update IMG_DIR in this script" exit 1 fi echo "โœ… Directories found" echo "" # Create backup echo "๐Ÿ“ฆ Creating backup..." mkdir -p "$BACKUP_DIR" timestamp=$(date +%Y%m%d_%H%M%S) tar -czf "$BACKUP_DIR/blogs_backup_$timestamp.tar.gz" -C "$(dirname "$BLOG_DIR")" "$(basename "$BLOG_DIR")" echo "โœ… Backup created: $BACKUP_DIR/blogs_backup_$timestamp.tar.gz" echo "" # Count existing blogs total_blogs=$(ls "$BLOG_DIR"/*.html 2>/dev/null | wc -l) numeric_blogs=$(ls "$BLOG_DIR"/[0-9][0-9][0-9][0-9].html 2>/dev/null | wc -l) slug_blogs=$(ls "$BLOG_DIR"/[a-z]*.html 2>/dev/null | wc -l) echo "๐Ÿ“Š Current blog status:" echo " Total blogs: $total_blogs" echo " Numeric files: $numeric_blogs" echo " Slug files: $slug_blogs" echo "" # Function to generate slug from title generate_slug() { local title="$1" echo "$title" | tr '[:upper:]' '[:lower:]' | \ sed 's/รก/a/g; s/รค/a/g; s/ฤ/c/g; s/ฤ/d/g; s/รฉ/e/g; s/ฤ›/e/g; s/รญ/i/g; s/ฤพ/l/g; s/ลˆ/n/g; s/รณ/o/g; s/รถ/o/g; s/รด/o/g; s/ล™/r/g; s/ลก/s/g; s/ลฅ/t/g; s/รบ/u/g; s/ลฏ/u/g; s/รฝ/y/g; s/ลพ/z/g' | \ sed 's/ร/a/g; s/ร„/a/g; s/ฤŒ/c/g; s/ฤŽ/d/g; s/ร‰/e/g; s/ฤš/e/g; s/ร/i/g; s/ฤฝ/l/g; s/ล‡/n/g; s/ร“/o/g; s/ร–/o/g; s/ร”/o/g; s/ล˜/r/g; s/ล /s/g; s/ลค/t/g; s/รš/u/g; s/ลฎ/u/g; s/ร/y/g; s/ลฝ/z/g' | \ iconv -c -f utf-8 -t ascii//TRANSLIT | \ sed 's/\s\+/-/g' | \ sed 's/[^a-z0-9\-]//g' | \ sed 's/-\+/-/g' | \ sed 's/^\-\|\-$//g' } # Function to extract title from HTML extract_title() { local file="$1" grep -o ']*class="[^"]*lte-header[^"]*"[^>]*>.*' "$file" | sed 's/<[^>]*>//g' | xargs || echo "" } # Function to check if slug exists slug_exists() { local slug="$1" [ -f "$BLOG_DIR/$slug.html" ] } # Process numeric blogs that don't have slugs yet echo "๐Ÿ”„ Processing blogs without slugs..." processed=0 for blog_file in "$BLOG_DIR"/[0-9][0-9][0-9][0-9].html; do if [ ! -f "$blog_file" ]; then continue fi filename=$(basename "$blog_file") blog_id="${filename%.html}" # Check if slug meta tag already exists if grep -q ' sed -i "s||\n|" "$blog_file" # Create slug file (copy of original) cp "$blog_file" "$BLOG_DIR/$slug.html" ((processed++)) done echo "" echo "โœ… Migration completed!" echo "๐Ÿ“Š Processed $processed blogs" echo "" # Show final status total_blogs=$(ls "$BLOG_DIR"/*.html 2>/dev/null | wc -l) numeric_blogs=$(ls "$BLOG_DIR"/[0-9][0-9][0-9][0-9].html 2>/dev/null | wc -l) slug_blogs=$(ls "$BLOG_DIR"/[a-z]*.html 2>/dev/null | wc -l) echo "๐Ÿ“Š Final blog status:" echo " Total blogs: $total_blogs" echo " Numeric files: $numeric_blogs" echo " Slug files: $slug_blogs" echo "" # Show some example URLs echo "๐ŸŒ Example URLs now available:" echo " /blog/$(ls "$BLOG_DIR"/[a-z]*.html 2>/dev/null | head -1 | xargs basename -s .html || echo 'jdeme-do-finale')" echo " /blog/$(ls "$BLOG_DIR"/[a-z]*.html 2>/dev/null | head -2 | tail -1 | xargs basename -s .html || echo '1-zapas-final-score')" echo "" echo "๐ŸŽ‰ Setup complete! Your blogs now support:" echo " โœ… Clean URLs (slugs)" echo " โœ… SEO meta tags" echo " โœ… Backward compatibility" echo " โœ… New admin features" echo "" echo "๐Ÿ“ Next steps:" echo " 1. Restart your backend service" echo " 2. Test new URLs in browser" echo " 3. Try admin interface with new features"