u915

Daniel Cano Merchán - Hacking & Tech

Shell script to push content to Github pages

This post is about how to make a simple shell script to push content to Github.

The goal is to automate the process of posting into my blog on Github pages.

Note: This script assumes that the git folder contains an already init git.

Creating a new file named pusher.sh

Permissions:

chmod +x pusher.sh
#!/bin/bash
PATH_BLOG=/awesome/path/*
PATH_GIT=/awesome/path
TIMESTAMP=`date +'%Y-%m-%d %H:%M:%S'`
USER="awesomeUser"
REPO="awesomeRepo"
BRANCH="master"

cp -R ${PATH_BLOG} ${PATH_GIT}
cd ${PATH_GIT}
git add --all .
git commit -m "Blog updated ${TIMESTAMP}"
git push https://github.com/${USER}/${REPO}.git ${BRANCH}

Little Description:

This script copies all the files indicated on the var PATH_BLOG using the parameter -R, so the copy is recursive and using the wildcard * all files are copied to the path PATH_GIT.

After that, it adds all the files, sets a commit with a timestamp and finally pushes all the content to the branch indicated on the var BRANCH.

You can find the script here too.

https://github.com/u915/githubPusher