#!/bin/sh
# ideas used from https://gist.github.com/motemen/8595451

# abort the script if there is a non-zero error
set -e

pwd

# remote=$(git config remote.origin.url)
#
# siteSource="$1"
#
# if [ ! -d "$siteSource" ]
# then
#     echo "Usage: $0 <site source dir>"
#     exit 1
# fi
#
# # make a directory to put the gp-pages branch
# mkdir gh-pages-branch
# cd gh-pages-branch
# # now lets setup a new repo so we can update the gh-pages branch
# git init
# git remote add --fetch origin "$remote"
#
# # switch into the the gh-pages branch
# if git rev-parse --verify origin/gh-pages > /dev/null 2>&1
# then
#     git checkout gh-pages
# else
#     git checkout --orphan gh-pages
# fi
#
# # delete any old site as we are going to replace it
# git rm -rf .
# # copy over or recompile the new site
# cp -a "../${siteSource}/." .
#
# # stage any changes and new files
# git add -A
# # now commit
# git commit -m "Deploy to GitHub pages"
# # and push, but send any output to /dev/null to hide anything sensitive
# git push --force --quiet origin gh-pages > /dev/null 2>&1
#
# # go back to where we started and remove the gh-pages git repo we made and used
# # for deployment
# cd ..
# rm -rf gh-pages-branch

#!/bin/sh
# ideas used from https://gist.github.com/motemen/8595451

# abort the script if there is a non-zero error
set -e

pwd

remote=$(git config remote.origin.url)

siteSource="$1"

if [ ! -d "$siteSource" ]
then
    echo "Usage: $0 <site source dir>"
    exit 1
fi

# make a directory to put the gp-pages branch
mkdir gh-pages-branch
cd gh-pages-branch
# now lets setup a new repo so we can update the gh-pages branch
git init
git remote add --fetch origin "$remote"

# switch into the the gh-pages branch
if git rev-parse --verify origin/gh-pages > /dev/null 2>&1
then
    git checkout gh-pages
else
    git checkout --orphan gh-pages
fi

# delete any old site as we are going to replace it
git rm -rf .
# copy over or recompile the new site
cp -a "../${siteSource}/." .

# stage any changes and new files
git add -A
# now commit
git commit -m "Deploy to GitHub pages"
# and push, but send any output to /dev/null to hide anything sensitive
git push --force --quiet origin gh-pages > /dev/null 2>&1

# go back to where we started and remove the gh-pages git repo we made and used
# for deployment
cd ..
rm -rf gh-pages-branch

Switch it back on with a machine user and see if it works
Switch it back on with a machine user and see if it works
