Skip to content

Instantly share code, notes, and snippets.

View stephencroberts's full-sized avatar

Stephen Roberts stephencroberts

View GitHub Profile
@stephencroberts
stephencroberts / log.sh
Last active May 15, 2019 18:35
Shell script function for logging with log levels and custom formatting (POSIX compatible)
##############################################################################
# Logs messages with a configurable logging level and format, accepting input
# from either stdin (such as a pipe) or as arguments
#
# Author: Stephen Roberts <stephenroberts@gmail.com>
#
# Globals:
# LOGLEVEL - arbitrary integer for desired log output level (default: 0)
#
# Arguments:
@stephencroberts
stephencroberts / twto.sh
Last active May 4, 2019 01:03
Shell script to time a command with a timeout (POSIX compliant)
#!/bin/sh
#
# Time a command with a timeout
#
# Author: Stephen Roberts <stephenroberts@gmail.com>
# Version: 1
#
# Usage: twto [OPTIONS] TIMEOUT COMMAND
#
@stephencroberts
stephencroberts / build.xml
Last active May 25, 2017 13:55
Phing build file for Joomla! extensions
<?xml version="1.0" encoding="UTF-8"?>
<project name="digitollsoftware" default="dist">
<tstamp />
<!-- Load local properties -->
<property file="./build.properties" override="true" />
<!-- Get package version from the latest tag in git -->
@stephencroberts
stephencroberts / dev-git-post-checkout
Created November 25, 2013 03:01
Updates the local database to reflect which branch was checked out
#!/bin/sh
# If checking out a branch
if [ $3 -eq 1 ]; then
# Get the new branch
branch=`git rev-parse --abbrev-ref HEAD`
# Run dev site setup
php -f setup.php "$branch"
@stephencroberts
stephencroberts / pushtotesting
Last active December 29, 2015 04:58
Pushes source site to destination testing site
#!/bin/bash
#
# Usage: pushtotesting.sh <source> <destination>
# Summary: Pushes source site to destination testing site
# Description: Assuming the source site updates from the master branch, and
# the testing site the develop branch, this script will:
#
# 1. Fetch updates from the remote repo
# 2. Discard all local changes
# 3. Checkout and pull the develop branch
@stephencroberts
stephencroberts / post-update
Last active December 27, 2015 17:39
Updates the database and files of a staging server from git repo and set proper permissions
#!/bin/bash
# Get the branch that was pushed
branch=$(git rev-parse --symbolic --abbrev-ref $1)
# Move to root of git repo
cd ..
unset GIT_DIR
# Save working directory for later
@stephencroberts
stephencroberts / pre-receive
Last active December 27, 2015 17:29
Checks that staging has no modified or untracked files before allowing a push
#!/bin/bash
cd ../
unset GIT_DIR
read rev_old rev_new refname
if [[ "$refname" == *master* ]]
then
echo "Checking staging for modified/untracked files..."
@stephencroberts
stephencroberts / post-merge
Last active December 27, 2015 17:09
Dev git post-merge
#!/bin/bash
# Apply stash to restore local develop.sql (or other changes)
git stash apply
git stash drop
# Which branch are we on?
branch=`git rev-parse --abbrev-ref HEAD`
php -f setup.php "$branch"
@stephencroberts
stephencroberts / setup.php
Last active December 27, 2015 16:59
Setup dev Joomla! site after pulling database from somewhere else
<?php
// Load Joomla! config
if (!file_exists('httpdocs/configuration.php')) {
echo "Couldn't find configuration.php!\n";
exit();
}
include('httpdocs/configuration.php');
$config = new JConfig();
@stephencroberts
stephencroberts / pre-push
Last active December 27, 2015 14:58
Development pre-push git hook that creates a versioned database patch if pushing to the staging server
#!/bin/bash
# Rename develop.sql to <version>.sql
# Exit if develop.sql is empty
if [ -s database/develop.sql ]; then exit 0; fi
# Get version tag from the latest commit
VER=`git tag --contains HEAD`