Last active
August 29, 2015 13:56
-
-
Save grampelberg/8946379 to your computer and use it in GitHub Desktop.
auto-deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o errexit -o nounset -o pipefail | |
function -h { | |
cat <<USAGE | |
USAGE: deploy.bash | |
This will bootstrap a git checkout of the repo and then try to deploy it. | |
USAGE | |
}; function --help { -h ;} # A nice way to handle -h and --help | |
export LC_ALL=en_US.UTF-8 # A locale that works consistently | |
function main { | |
export GIT_SSH="$(pwd -P)/.git_ssh.site" | |
[[ -f tmp/README.md ]] || bootstrap | |
while sleep 60 | |
do deploy | |
done | |
} | |
# Write functions for all script actions. Change main to call one of them. | |
function bootstrap { | |
if [[ ! -f .git_ssh.site ]] | |
then | |
ssh_options=( -i "$(pwd -P)"/"${KEY:-deploy.key}" | |
-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ) | |
( printf 'ssh' | |
printf ' %q' "${ssh_options[@]}" | |
printf ' "$@"' ) > .git_ssh.site | |
chmod +x .git_ssh.site | |
fi | |
git clone "${REPO}" site | |
gem install bundler | |
} | |
function deploy {( | |
cd website | |
bundle install | |
git remote update | |
git checkout "${BRANCH:-gh-pages}" | |
[[ $(git status -uno) == *branch\ is\ behind* ]] || return | |
git rebase origin/"${BRANCH:-gh-pages}" | |
bundle exec jekyll build | |
bundle exec rake deploy | |
)} | |
function msg { out "$*" >&2 ;} | |
function err { local x=$? ; msg "$*" ; return $(( $x == 0 ? 1 : $x )) ;} | |
function out { printf '%s\n' "$*" ;} | |
######################### Delegates to subcommands or runs main, as appropriate | |
if [[ ${1:-} ]] && declare -F | cut -d' ' -f3 | fgrep -qx -- "${1:-}" | |
then "$@" | |
else main "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment