diff --git a/README.md b/README.md index ad3f719..725df5c 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ Users can choose their preferred login method on the login page. - **Processing Requirements**: All five pieces of student information must be present for the PDF to be processed - **Error Handling**: Files without the required information or with extraction errors will be skipped with detailed error messages - **Security**: All processing happens server-side with temporary file storage +- **File Storage**: Processed ZIP files are stored in the `processed/` folder within the application directory - **Limits**: Maximum upload size is limited to 500MB - **Output**: Creates a structured folder hierarchy within the downloaded ZIP (Episode/School/Grade/Gender) diff --git a/__pycache__/pdf_renamer.cpython-313.pyc b/__pycache__/pdf_renamer.cpython-313.pyc index 48d88f8..6778704 100644 Binary files a/__pycache__/pdf_renamer.cpython-313.pyc and b/__pycache__/pdf_renamer.cpython-313.pyc differ diff --git a/pdf_renamer.py b/pdf_renamer.py index d6b6007..f52a563 100644 --- a/pdf_renamer.py +++ b/pdf_renamer.py @@ -11,7 +11,8 @@ from PyPDF2 import PdfReader from authlib.integrations.flask_client import OAuth app = Flask(__name__) -app.config['UPLOAD_FOLDER'] = tempfile.mkdtemp() +app.config['UPLOAD_FOLDER'] = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'processed') +os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024 # 500MB limit app.secret_key = os.getenv('SECRET_KEY', 'dev-secret-key-change-in-production') diff --git a/ubuntu-install.sh b/ubuntu-install.sh index bff6654..df264a2 100644 --- a/ubuntu-install.sh +++ b/ubuntu-install.sh @@ -7,6 +7,21 @@ set -e echo "Starting installation of PDF Renamer Flask App..." +# Check if already installed +if systemctl is-active --quiet pdf-renamer 2>/dev/null; then + echo "WARNING: PDF Renamer service is already running." + echo "This will reinstall/update the application." + echo "Press Ctrl+C to cancel or Enter to continue..." + read -r || exit 1 +fi + +# Check if running with sudo +if [ "$EUID" -ne 0 ]; then + echo "ERROR: This script must be run with sudo privileges" + echo "Usage: sudo ./ubuntu-install.sh" + exit 1 +fi + # Update system packages echo "Updating system packages..." sudo apt update && sudo apt upgrade -y @@ -17,8 +32,25 @@ sudo apt install -y python3 python3-pip python3-venv nginx git # Clone the repository (replace with your actual repo URL if different) echo "Cloning the repository..." -git clone https://gitlab.com/trbc-dev/pdf-rename-sort.git -cd pdf-rename-sort +# Check if we're already in the repository directory +if [ -d ".git" ]; then + echo "Already in repository directory, skipping clone..." +else + # Try HTTPS first, fallback to SSH if available + if git clone https://gitlab.com/trbc-dev/pdf-rename-sort.git 2>/dev/null; then + echo "Cloned via HTTPS" + cd pdf-rename-sort + elif git clone git@gitlab.com:trbc-dev/pdf-rename-sort.git 2>/dev/null; then + echo "Cloned via SSH" + cd pdf-rename-sort + else + echo "ERROR: Could not clone repository. Please check:" + echo "1. Repository URL is correct" + echo "2. SSH keys are configured (for SSH clone)" + echo "3. Internet connection is working" + exit 1 + fi +fi # Create virtual environment and install dependencies echo "Setting up Python virtual environment..." @@ -34,6 +66,10 @@ mkdir -p static # Copy logo if it exists in repo, otherwise you'll need to add it # cp path/to/trbc-logo-full.png static/ # Uncomment and adjust if needed +# Get the current user (fallback to ubuntu if not detected) +CURRENT_USER=${USER:-ubuntu} +echo "Installing for user: $CURRENT_USER" + # Create systemd service file echo "Creating systemd service..." sudo tee /etc/systemd/system/pdf-renamer.service > /dev/null <