48 lines
1.1 KiB
Bash
Executable file
48 lines
1.1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
IFS=$'\n\t'
|
|
|
|
# --- Configurable variables ---
|
|
SRC_FILE="/var/www/html/banned.txt"
|
|
REPO_DIR="/git/repository"
|
|
DEST_FILE="banned.txt"
|
|
|
|
# --- Functions ---
|
|
usage() {
|
|
echo "Usage: $0 [-s source_file] [-d repo_dir] [-f dest_file]"
|
|
echo " -s Source file path (default: $SRC_FILE)"
|
|
echo " -d Git repo directory (default: $REPO_DIR)"
|
|
echo " -f Destination filename inside repo (default: $DEST_FILE)"
|
|
exit 1
|
|
}
|
|
|
|
# --- Parse arguments ---
|
|
while getopts ":s:d:f:h" opt; do
|
|
case $opt in
|
|
s) SRC_FILE="$OPTARG" ;;
|
|
d) REPO_DIR="$OPTARG" ;;
|
|
f) DEST_FILE="$OPTARG" ;;
|
|
h) usage ;;
|
|
\?) echo "Invalid option: -$OPTARG" >&2; usage ;;
|
|
esac
|
|
done
|
|
|
|
# --- Main logic ---
|
|
if [[ ! -f "$SRC_FILE" ]]; then
|
|
echo "Error: Source file '$SRC_FILE' not found." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -d "$REPO_DIR/.git" ]]; then
|
|
echo "Error: '$REPO_DIR' is not a git repository." >&2
|
|
exit 1
|
|
fi
|
|
|
|
cd "$REPO_DIR"
|
|
cp "$SRC_FILE" "$DEST_FILE"
|
|
|
|
git add "$DEST_FILE"
|
|
COMMIT_MSG="Update banned IP list — $(date '+%Y-%m-%d %H:%M:%S %Z')"
|
|
git commit -m "$COMMIT_MSG" || echo "No changes to commit."
|
|
git push
|