#!/bin/bash
TARGET="/var/www/html/uber_direct/application/models/Base_model.php"
SNIPPET="/tmp/uber_snippets.php"

# Find the last line with a closing brace
LAST_BRACE_LINE=$(grep -n "}" "$TARGET" | tail -n 1 | cut -d: -f1)

# Split the file, insert the snippet, and reassemble
head -n $((LAST_BRACE_LINE - 1)) "$TARGET" > /tmp/base_model_new.php
cat "$SNIPPET" >> /tmp/base_model_new.php
echo "}" >> /tmp/base_model_new.php

# Move back to original
mv /tmp/base_model_new.php "$TARGET"
chown www-data:www-data "$TARGET"
