Skip to content

Instantly share code, notes, and snippets.

@brouberol
Created January 24, 2015 13:39
Show Gist options
  • Save brouberol/29cef38baf600cd009b8 to your computer and use it in GitHub Desktop.
Save brouberol/29cef38baf600cd009b8 to your computer and use it in GitHub Desktop.
#!/bin/bash
PAGE_DIR=/var/www/
TMP_PAGE_CLONE=$HOME/page-tmp
PAGE_GIT=/home/git/page.git
PAGE=$TMP_PAGE_CLONE/index.html
CURRENT_AGE=`python -c 'from datetime import date;print(date.today() - date(1990, 11, 4)).days / 365'`
CURRENT_YEAR=`date +%Y`
function template_replace {
echo "Replacing '{{$1}}' by '$2'";
sed -i "s/{{$1}}/$2/" $PAGE;
}
git clone $PAGE_GIT $TMP_PAGE_CLONE
# Replace placeholders by computed values
template_replace age $CURRENT_AGE
template_replace year $CURRENT_YEAR
cp -rvu --preserve=mode,ownership $TMP_PAGE_CLONE/* $PAGE_DIR
rm -rf $TMP_PAGE_CLONE
echo "Temporary repository removed"
echo "Deployment complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment