Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions bin/pull-template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
set -e

TEMPLATE_GIT_URL="https://github.com/b-hayes/php-apache-template.git"
TEMPLATE_DIRS=("$HOME/repo/php-apache-template" "$HOME/repo/b-hayes/php-apache-template" "../php-apache-template")
TEMPLATE_DIR=""

# Check for directory argument
if [ -n "$1" ]; then
if [ -d "$1" ]; then
TEMPLATE_DIR="$1"
echo "Using specified directory: $TEMPLATE_DIR"
# If the specified directory is a git repo, exclude git-ignored files
if [ -d "$TEMPLATE_DIR/.git" ]; then
echo "Files to be copied from $TEMPLATE_DIR (excluding .git, README.md, and git-ignored):" >&2
git -C "$TEMPLATE_DIR" ls-files --others --ignored --exclude-standard --directory | sed "s|^|IGNORED: |" >&2
files_to_copy=$(git -C "$TEMPLATE_DIR" ls-files --cached --others --exclude-standard | grep -vE '^README.md$')
echo "$files_to_copy" >&2
read -p "Are you sure you want to copy these files and overwrite existing ones? (y/N): " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 1
fi
# Copy only tracked and untracked (not ignored) files, excluding .git and README.md
(cd "$TEMPLATE_DIR" && tar --exclude=.git --exclude=README.md -cf - $files_to_copy) | tar -xf -
else
echo "Files to be copied from $TEMPLATE_DIR:" >&2
find "$TEMPLATE_DIR" -type f ! -path "$TEMPLATE_DIR/.git/*" ! -name 'README.md' | sed "s|^$TEMPLATE_DIR/||" >&2
read -p "Are you sure you want to copy these files and overwrite existing ones? (y/N): " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 1
fi
# Copy files from specified directory
rsync -av --exclude='.git' --exclude='README.md' "$TEMPLATE_DIR"/ ./
fi
if git diff --quiet; then
echo "No changes detected."
else
git --no-pager diff
fi
exit 0
fi
fi

# Determine possible template directories
for dir in "${TEMPLATE_DIRS[@]}"; do
if [ -d "$dir/.git" ]; then
TEMPLATE_DIR="$dir"
break
fi
done
if [ -z "$TEMPLATE_DIR" ]; then
TEMPLATE_DIR="${TEMPLATE_DIRS[0]}"
git clone "$TEMPLATE_GIT_URL" "$TEMPLATE_DIR"
fi

# Pull latest changes from master
cd "$TEMPLATE_DIR"
git checkout master
git pull origin master
cd - > /dev/null

# Copy files from template to current project (excluding .git and README.md)
rsync -av --exclude='.git' --exclude='README.md' "$TEMPLATE_DIR"/ ./

# Show git diff
if git diff --quiet; then
echo "No changes detected."
else
git --no-pager diff
fi
135 changes: 135 additions & 0 deletions bin/update-template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/bash

set -e

TEMPLATE_GIT_URL="https://github.com/b-hayes/php-apache-template.git"
# Possible locations for the template directory based on my usual workflows
TEMPLATE_DIRS=("$HOME/repo/php-apache-template" "$HOME/repo/b-hayes/php-apache-template" "../php-apache-template")
TEMPLATE_DIR=""

# Determine possible template directories
for dir in "${TEMPLATE_DIRS[@]}"; do
if [ -d "$dir/.git" ]; then
TEMPLATE_DIR="$dir"
break
fi
done
if [ -z "$TEMPLATE_DIR" ]; then
TEMPLATE_DIR="${TEMPLATE_DIRS[0]}"
git clone "$TEMPLATE_GIT_URL" "$TEMPLATE_DIR"
fi

if [[ "$1" == "--add" ]]; then
shift
if [ $# -eq 0 ]; then
echo "No files specified to add."
exit 1
fi
FILES_TO_UPDATE=("$@")
elif [[ "$1" == "--add-changed" ]]; then
mapfile -t FILES_TO_UPDATE < <(git status --porcelain | awk '{print $2}' | grep -v '^README.md$')
if [ ${#FILES_TO_UPDATE[@]} -eq 0 ]; then
echo "No changed or new files to add."
exit 0
fi
elif [[ "$1" == "--all-template-files" ]]; then
cd "$TEMPLATE_DIR"
FILES_TO_UPDATE=( $(git ls-files --others --exclude-standard --cached | grep -v -i '^README.md$') )
cd - > /dev/null
else
echo "Usage: $0 [--add <files...> | --add-changed | --all-template-files]"
echo " --add <files...> Add specific files to the template repo."
echo " --add-changed Add new/modified files in the current repo (excluding README.md)."
echo " --all-template-files Add all template files (excluding README.md)."
exit 0
fi

# Copy updated files
for file in "${FILES_TO_UPDATE[@]}"; do
src_file="$(pwd)/$file"
dest_file="$TEMPLATE_DIR/$file"
mkdir -p "$(dirname "$dest_file")"
cp -v "$src_file" "$dest_file"
done

# Commit and push changes
cd "$TEMPLATE_DIR"

# Intelligent commit message generation
status_output=$(git status --porcelain)
added_files=($(echo "$status_output" | awk '$1 ~ /^A/ {print $2}'))
modified_files=($(echo "$status_output" | awk '$1 ~ /^M/ {print $2}'))
deleted_files=($(echo "$status_output" | awk '$1 ~ /^D/ {print $2}'))

commit_msg=""
if [ ${#added_files[@]} -gt 0 ]; then
if [ ${#added_files[@]} -eq 1 ]; then
commit_msg="Added ${added_files[0]}"
else
commit_msg="Added ${added_files[0]} and others"
fi
fi
if [ ${#modified_files[@]} -gt 0 ]; then
if [ -n "$commit_msg" ]; then
commit_msg+="; "
fi
if [ ${#modified_files[@]} -eq 1 ]; then
commit_msg+="Updated ${modified_files[0]}"
else
commit_msg+="Updated ${modified_files[0]} and others"
fi
fi
if [ ${#deleted_files[@]} -gt 0 ]; then
if [ -n "$commit_msg" ]; then
commit_msg+="; "
fi
if [ ${#deleted_files[@]} -eq 1 ]; then
commit_msg+="Removed ${deleted_files[0]}"
else
commit_msg+="Removed ${deleted_files[0]} and others"
fi
fi
if [ -z "$commit_msg" ]; then
commit_msg="Update from $CURR_FOLDER_NAME"
fi

# Get current folder name for branch
CURR_FOLDER_NAME=$(basename "$(git rev-parse --show-toplevel)")
BRANCH_NAME="update-from-$CURR_FOLDER_NAME"

git fetch origin
if git ls-remote --exit-code --heads origin "$BRANCH_NAME" > /dev/null; then
git checkout "$BRANCH_NAME"
git pull origin "$BRANCH_NAME"
else
git checkout -b "$BRANCH_NAME"
fi

git add .

# Show staged changes and confirm before committing
if ! git diff --cached --quiet; then
echo -e "\033[0;32mThe following files are staged for commit:\033[0m" >&2
git diff --cached --name-status | sed $'s/^/\033[0;32m/;s/$/\033[0m/' >&2
# Use the intelligent commit_msg as the default
echo -e "\033[1;33mEnter commit message (default: '$commit_msg'):\033[0m" >&2
read -e -i "$commit_msg" user_commit_msg
commit_msg=${user_commit_msg:-$commit_msg}
git commit -m "$commit_msg"
PUSH_OUTPUT=$(git push --set-upstream origin "$BRANCH_NAME" 2>&1)
# Look for PR link in push output and open if present
PR_LINK=$(echo "$PUSH_OUTPUT" | grep -oE 'https://github.com/[^ ]+/pull/new/[^ ]+')
if [ -n "$PR_LINK" ]; then
if command -v xdg-open >/dev/null 2>&1; then
xdg-open "$PR_LINK" >/dev/null 2>&1 &
elif command -v open >/dev/null 2>&1; then
open "$PR_LINK" >/dev/null 2>&1 &
elif command -v explorer.exe >/dev/null 2>&1; then
explorer.exe "$PR_LINK" >/dev/null 2>&1 &
else
echo "Please open: $PR_LINK"
fi
fi
else
echo "No changes to commit."
fi
15 changes: 15 additions & 0 deletions public/403.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
http_response_code(403);
?>
<div style="width: 100%;text-align: center;">
<p style="font-size: xxx-large"><?=http_response_code()?></p>
<p style="font-size: xxx-large;">🤨🤚</p>
<h1>Sorry mate you cant be here.</h1>
</div>
<style>
body {
display: flex;
align-items: center; /* Vertical center alignment */
justify-content: center; /* Horizontal center alignment */
}
</style>
17 changes: 14 additions & 3 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,20 @@
'trace' => $error->getTrace(),
' http' => $_SERVER['REQUEST_METHOD'] . ': ' . $_SERVER['REQUEST_URI']
];
if ($error->getPrevious()) {
$errorInfo['cause'] = $error->getPrevious()->getTraceAsString();
// Collect all previous exceptions recursively
$causes = [];
$prev = $error->getPrevious();
while ($prev) {
$causes[] = [
'message' => $prev->getMessage(),
'file' => $prev->getFile(),
'line' => $prev->getLine(),
'trace' => $prev->getTraceAsString()
];
$prev = $prev->getPrevious();
}
if ($causes) {
$errorInfo['causes'] = $causes;
}

//log the error
Expand Down Expand Up @@ -71,7 +83,6 @@
echo "</pre>";
}
}

?>
<style>
<?php
Expand Down