Hacker Public Radio

HPR4342: How I use Git to blog on the web and gopherspace


Listen Later

This show has been flagged as Clean by the host.

First, I create a Git repository some place on the server. This

is the Git repo that's going to be populated with your content,
but it doesn't have to be in a world-viewable location on your
server. Instead, you can place this anywhere, and then use a Git
hook or a cronjob to copy files from it to a world-viewable
directory. I don't cover that here. I refer to this location as
the staging directory.

Next, create a bare repository on your server. In its hooks

directory, create a shell script called post-receive:

#!/usr/bin/bash
#
while read oldrev newrev refname
do
BR=`git rev-parse --symbolic --abbrev-ref $refname`
if [ "$BR" == "master" ]; then
WEB_DIR="/my/staging/dir"
export GIT_DIR="$WEB_DIR/.git"
pushd $WEB_DIR > /dev/null
git pull
popd > /dev/null
fi
done
Now when you push to your bare repository, you are triggering the
post-receive script to run, which in turn triggers a git pull in
your staging directory.

Once your staging directory contains the content you want to

distribute, you can copy them to live directories, or you could
make your staging directory live (remember to exclude the .git
directory though), or whatever you want.

For gopher, I create a file listing by date using a shell

script:

#!/usr/bin/bash
SED=/usr/bin/sed
DIR_BASE=/my/live/dir
DIR_LIVE=blog
DIR_STAGING=staging
DATE=${DATE:-`date --rfc-3339=date`}
for POST in `find "$DIR_BASE"/"$DIR_STAGING" \
-type f -name "item.md" -exec grep -Hl "$DATE" {} \;`;
do
POSTDIR=`dirname "$POST"`
cp "$POST" "$DIR_BASE"/"$DIR_LIVE"/`basename $POSTDIR`.txt
echo -e 0Latest'\t'../"$DIR_LIVE"/`basename $POSTDIR`.txt > /tmp/updater.tmp
echo -e 0"$DATE" `basename $POSTDIR`'\t'../"$DIR_LIVE"/`basename $POSTDIR`.txt \
>> /tmp/updater.tmp
"${SED}" -i "/0Latest/ r /tmp/updater.tmp" "$DIR_BASE"/date/gophermap
"${SED}" -i '0,/0Latest/{/0Latest/d;}' "$DIR_BASE"/date/gophermap
/usr/bin/rm /tmp/updater.tmp
done

Provide feedback on this episode.

...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

289 Listeners

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec by Jerry Bell and Andrew Kalat

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec

370 Listeners

LINUX Unplugged by Jupiter Broadcasting

LINUX Unplugged

268 Listeners

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast) by Johannes B. Ullrich

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast)

651 Listeners

Curious Cases by BBC Radio 4

Curious Cases

829 Listeners

The Strong Towns Podcast by Strong Towns

The Strong Towns Podcast

421 Listeners

Late Night Linux by The Late Night Linux Family

Late Night Linux

164 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,048 Listeners

Cybersecurity Today by Jim Love

Cybersecurity Today

181 Listeners

CISO Series Podcast by David Spark, Mike Johnson, and Andy Ellis

CISO Series Podcast

189 Listeners

TechCrunch Daily Crunch by TechCrunch

TechCrunch Daily Crunch

42 Listeners

Strict Scrutiny by Crooked Media

Strict Scrutiny

5,800 Listeners

2.5 Admins by The Late Night Linux Family

2.5 Admins

98 Listeners

Cyber Security Headlines by CISO Series

Cyber Security Headlines

138 Listeners

What the Hack? by DeleteMe

What the Hack?

221 Listeners