39 lines
848 B
Bash
39 lines
848 B
Bash
#!/bin/sh
|
|
|
|
USAGE="USAGE: $0 <gitdir> <user>"
|
|
|
|
ok_msg() { echo "\033[32m$1\033[0m"; }
|
|
info_msg() { echo "\033[36m$1\033[0m"; }
|
|
exit_msg() { echo "\033[31m$1\033[0m"; exit 1; }
|
|
|
|
is_clean()
|
|
{
|
|
local IFS=$'\n'
|
|
status="$(git status -s -uno)"
|
|
if [ -z "$status" ]; then
|
|
return 0
|
|
else
|
|
echo "$status"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
[ ! -z "$2" ] || exit_msg "$USAGE"
|
|
|
|
DIR="$1"
|
|
USER="$2"
|
|
CUSTOM_UPDATE=./deploy/update
|
|
|
|
cd "$DIR" || exit_msg "Not a directory: $DIR"
|
|
[ -d .git ] || exit_msg "Not a Git repository: $DIR"
|
|
|
|
info_msg "Deploying to $DIR $(cat .git/HEAD) ..."
|
|
is_clean || exit_msg "Directory not clean!"
|
|
git fetch || exit_msg "Fetch failed!"
|
|
git reset --hard FETCH_HEAD || exit_msg "Checkout failed!"
|
|
if [ -x $CUSTOM_UPDATE ]; then
|
|
info_msg "Running custom update ..."
|
|
$CUSTOM_UPDATE
|
|
fi
|
|
chown -R $USER . || info_msg "chown $USER failed!"
|
|
ok_msg "Done!"
|