#!/bin/bash

# Check if token is provided
if [ -z "$1" ]; then
    echo "Please provide your GitHub token as an argument"
    echo "Usage: ./init_with_token.sh YOUR_TOKEN"
    exit 1
fi

TOKEN=$1

# Change to the website directory
cd /usr/www/amatsuro/manoktok.com

# Initialize git repository if not already initialized
git init

# Add GitHub repository as remote with token
git remote add origin "https://$TOKEN@github.com/manoktokchicken/manoktok.git"

# Configure Git
git config user.name "Manoktok"
git config user.email "tlacson7@gmail.com"

# Fetch all branches
git fetch origin

# Checkout main branch
git checkout main || git checkout -b main

# Pull latest changes
git pull origin main

# Set proper permissions
chmod -R 755 .
chmod -R 775 uploads images logs

echo "Git repository initialized and synchronized!" 