blob: 3ee898d9d5b2f7be1adf42940966a41a18cbea94 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#!/bin/bash
#
# Sample git post-receive hook for /srv/git/prism-v2.git on the VPS.
#
# Install:
# sudo cp /var/www/prism-v2/scripts/post-receive.sample /srv/git/prism-v2.git/hooks/post-receive
# sudo chmod +x /srv/git/prism-v2.git/hooks/post-receive
#
# Required sudoers entry so the git user can restart services without a password.
# Adjust GIT_USER if your git is owned by a different account.
# GIT_USER ALL=(root) NOPASSWD: /var/www/prism-v2/scripts/deploy.sh
set -euo pipefail
BRANCH="master"
WEB_DIR="/var/www/prism-v2"
GIT_DIR="/srv/git/prism-v2.git"
LOG="/var/log/git-deploy.log"
exec >> "$LOG" 2>&1
while read -r oldrev newrev refname; do
if [ "$refname" = "refs/heads/$BRANCH" ]; then
echo "$(date -Is): Checking out $BRANCH to $WEB_DIR"
sudo -u www-data git --work-tree="$WEB_DIR" --git-dir="$GIT_DIR" checkout -f "$BRANCH"
echo "$(date -Is): Running deploy.sh"
sudo "$WEB_DIR/scripts/deploy.sh"
echo "$(date -Is): Done."
fi
done
|