Files
qr-code_manager/clean_data.sh

102 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
"""
QR Code Manager - Quick Data Cleanup Script (Shell Version)
A simple shell script to clean all persistent data for deployment.
"""
echo "🧹 QR Code Manager - Quick Data Cleanup"
echo "======================================"
echo ""
# Get script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd "$SCRIPT_DIR"
echo "📂 Working directory: $(pwd)"
echo ""
echo "⚠️ WARNING: This will delete ALL persistent data!"
echo " - All QR codes and their images"
echo " - All dynamic link pages"
echo " - All short URLs"
echo " - All Flask sessions"
echo ""
read -p "Are you sure you want to continue? Type 'YES' to confirm: " confirm
if [ "$confirm" != "YES" ]; then
echo "❌ Cleanup cancelled."
exit 0
fi
echo ""
echo "🚀 Starting cleanup process..."
echo ""
# Clean JSON data files
echo "🗑️ Cleaning JSON data files..."
if [ -d "data" ]; then
echo '{}' > data/qr_codes.json 2>/dev/null && echo " ✅ Cleared qr_codes.json" || echo " ⚠️ qr_codes.json not found"
echo '{}' > data/link_pages.json 2>/dev/null && echo " ✅ Cleared link_pages.json" || echo " ⚠️ link_pages.json not found"
echo '{}' > data/short_urls.json 2>/dev/null && echo " ✅ Cleared short_urls.json" || echo " ⚠️ short_urls.json not found"
else
echo " ⚠️ Data directory not found"
fi
echo ""
# Clean QR code images
echo "🖼️ Cleaning QR code images..."
if [ -d "app/static/qr_codes" ]; then
COUNT=$(find app/static/qr_codes -name "*.png" | wc -l)
find app/static/qr_codes -name "*.png" -delete
echo " ✅ Deleted $COUNT QR code images"
else
echo " ⚠️ QR codes directory not found"
fi
echo ""
# Clean Flask sessions
echo "🔐 Cleaning Flask sessions..."
if [ -d "flask_session" ]; then
COUNT=$(find flask_session -type f | wc -l)
find flask_session -type f -delete
echo " ✅ Deleted $COUNT session files"
else
echo " ⚠️ Flask session directory not found"
fi
echo ""
# Clean log files
echo "📝 Cleaning log files..."
LOG_COUNT=$(find . -maxdepth 1 -name "*.log*" | wc -l)
if [ $LOG_COUNT -gt 0 ]; then
find . -maxdepth 1 -name "*.log*" -delete
echo " ✅ Deleted $LOG_COUNT log files"
else
echo " ✅ No log files found"
fi
echo ""
# Clean Python cache
echo "🐍 Cleaning Python cache..."
CACHE_COUNT=$(find . -name "__pycache__" -o -name "*.pyc" | wc -l)
find . -name "__pycache__" -exec rm -rf {} + 2>/dev/null
find . -name "*.pyc" -delete 2>/dev/null
echo " ✅ Cleaned $CACHE_COUNT cache files/directories"
echo ""
# Create fresh directories
echo "📁 Creating fresh directories..."
mkdir -p data app/static/qr_codes app/static/logos flask_session
echo " ✅ Ensured all directories exist"
echo ""
echo "✅ Cleanup completed successfully!"
echo ""
echo "🎉 Your QR Code Manager is now ready for a fresh deployment!"
echo " Next steps:"
echo " 1. Start the application: python main.py"
echo " 2. Login with: admin / admin123"
echo " 3. Change the default password"