mirror of
https://github.com/deuill/coreos-home-server.git
synced 2024-09-21 13:40:45 +00:00
33 lines
1.0 KiB
Bash
Executable File
33 lines
1.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
# Set up shared variables.
|
|
GIT_REPO="$1"
|
|
GIT_BRANCH="$2"
|
|
|
|
# Ensure correct usage and state.
|
|
if test -z "$GIT_REPO"; then
|
|
echo "Git repository path is empty, please provide a valid path as the first argument."
|
|
exit 1
|
|
elif test -z "$GIT_BRANCH"; then
|
|
echo "Git branch name is empty, please provide a valid branch name as the second argument."
|
|
exit 1
|
|
elif test ! -e "/src/${GIT_REPO}/refs/heads/${GIT_BRANCH}"; then
|
|
echo "Unable to find HEAD reference for '${GIT_REPO}', branch '${GIT_BRANCH}', is this a valid Git repository?"
|
|
exit 2
|
|
fi
|
|
|
|
chown -R hugo:hugo /dest
|
|
gosu hugo git clone --quiet --shared --branch "${GIT_BRANCH}" "/src/${GIT_REPO}" /tmp/src
|
|
|
|
# Wait for updates to watched branch for the given site, and build static content anew.
|
|
(
|
|
cd /tmp/src
|
|
while inotifywait -qq --event modify "/src/${GIT_REPO}/refs/heads/${GIT_BRANCH}"; do
|
|
gosu hugo git fetch origin "${GIT_BRANCH}" && gosu hugo git reset --hard "${GIT_BRANCH}"
|
|
done
|
|
) &
|
|
|
|
gosu hugo hugo --watch --verbose --source /tmp/src --destination /dest
|