Shell scripts
These are some of my favorite utility shell scripts. Many of them include detail that needs to be edited before you use them. Contribute your own, or your improvements.
reload
Reload a locahost service installed with brew. usage: reload php
# Reload php, sql, or nginx if [ $1 == 'php' ] then launchctl unload -w /Users/linc/Library/LaunchAgents/org.php.php-fpm.plist launchctl load -w /Users/linc/Library/LaunchAgents/org.php.php-fpm.plist # Could also be something like: #launchctl unload -w /usr/local/Cellar/php55/5.5.18/homebrew.mxcl.php55.plist #launchctl load -w /usr/local/Cellar/php55/5.5.18/homebrew.mxcl.php55.plist echo "PHP 5.5 restarted"; fi if [ $1 == 'sql' ] then launchctl unload -w /Users/linc/Library/LaunchAgents/homebrew.mxcl.percona-server.plist launchctl load -w /Users/linc/Library/LaunchAgents/homebrew.mxcl.percona-server.plist echo "Percona restarted"; fi if [ $1 = 'nginx' ] then sudo nginx -s stop sudo nginx echo "Nginx restarted"; fi
wtf
Echos x last lines of php error log. usage: wtf 30
#!/bin/sh tail -$1 /www/vanilla/php_error.log
call
ssh to a remote server & color-code the terminal background. usage: call cl400
#!/bin/sh
#
# Adapted from ssh_host - JD Smith, Copyright (2005)
host=${1:-${0##*/}}
########################################################################
# Configure custom host colors here, adding new host cases as necessary
# Color Format: "R, G, B, A" for red, green, blue, and opacity (0-65535)
#
# Example line to add:
# foobar.baz.com*) host_color="20000, 20000, 10000, 65535";;
#
case "$host" in
# CL1 "primary" - PINK
primar*) host_color="40000, 20000, 20000, 10000";;
# Dev & Stage - GREEN
cl1*) host_color="5000, 20000, 5000, 65535";;
cl2*) host_color="5000, 20000, 5000, 65535";;
# Standard - ORANGE
cl3*) host_color="40000, 20000, 0, 65535";;
# Priority - RED
cl4*) host_color="20000, 2000, 2000, 65535";;
# VIP - PURPLE
cl5*) host_color="10000, 0, 15000, 65535";;
# Other colors
# DK BLUE host_color="2000, 2000, 20000, 65535";;
# LT BLUE host_color="2000, 2000, 20000, 65535";;
# GRAY host_color="25000, 25000, 25000, 10000";;
# PINK host_color="40000, 20000, 20000, 10000";;
# Personal - ELECTRIC BLUE
spence*) host_color="10000, 10000, 50000, 62000";;
esac
# The default color which will be used when not connected to any host.
default_color="0, 0, 0, 60000"
########################################################################
window_name="${host}_SSH_$$"
trap cleanup 1 2 3 6
function cleanup() {
set_color "$default_color"
echo ""
tput sgr0
}
function set_color() {
echo ""
tput setaf 7
osascript -e 'tell application "Terminal" to tell (first window whose name contains "'$window_name'") to set background color to {'"$1"'}'
}
set_color "$host_color"
if [[ $host =~ ^cl ]]; then
ssh -l linc -p 4028 data.${host}.vanilladev.com
else
ssh -l linc $host
fi
cleanup
port
Shortcut for invoking porter from anywhere. usage: port -h
# Path to your porter repo's index file php /git/porter/index.php $@
mkdev
Create a new localhost site at {name}.dev. usage: mkdev
read -p "Name: " SITE
#/etc/hosts
sudo cp /etc/hosts /etc/hosts.original
echo -e "127.0.0.1\t${SITE}.dev" | sudo tee -a /etc/hosts
# copy files
sudo cp -R /www/_copy /www/${SITE}
sudo chown -R linc /www/${SITE}
# database
sudo echo "create database ${SITE}" | mysql -u root
# forum setup - hardcode form values here
curl -s http://${SITE}.dev/index.php?p=/dashboard/setup > /dev/null
curl -d "Database-dot-Host=localhost" -d "Database-dot-Name=${SITE}" -d "Database-dot-User=root" -d "Database-dot-Password=" -d "Garden-dot-Title=${SITE}" -d "Email=lincoln%40vanillaforums.com" -d "Name=admin" -d "Password=admin" -d "PasswordMatch=admin" http://${SITE}.dev/index.php?p=/dashboard/setup
# go there
open -a Firefox.app http://${SITE}.dev/entry
Comments
-
bigpull
This pulls entire classes of repos in 1 step. Note you'll need to customize some paths; I keep VIP repos and infrastructure repos each within their own subfolder so my
/gitdirectory isn't a mile long.#!/bin/sh # Safely stash work, checkout branch, and pull said branch on a collection of repos. ### Usage: bigpull [group] [branch] # Groups of repos we can pull. declare -a options=(product ops vip release) # Repo groups. declare -a release=(vanilla addons internal multisite) declare -a product=(addons internal porter multisite locales lithe clients community analytics docs wp-vanilla gdncli gdnhttp) declare -a ops=(vfcom inf jarvis vcon website stats) declare -a vip=(hobsons kixeye gazillion edmunds zenimax xogroup amplify adobe ea glu goodgames myfitnesspal oculus sega pennyarcade unknownworlds marykay capitalone enmasse aeria perfectworld digitalspy) declare ran="0" # Get branch. if [ "$2" != "" ]; then branch="$2"; else branch="master"; fi for i in ${options[@]} do if [ "$1" == $i ]; then echo ">>> Hang onto your butts. Pulling $i." ran="1"; repoArray="$i[@]" for k in ${!repoArray} do if [[ $i == "product" || $i == "release" ]]; then cd /git/$k else # ops and vip are in subfolders. cd /git/$i/$k fi echo "### $k ###" git stash git fetch vf git checkout $branch git pull vf $branch done echo "### FINISHED BIGPULL. ###" fi done # Output some help if we got nothing. if [ $ran == "0" ]; then echo "No repos selected. Options:" for i in ${options[@]} do echo "$i" done echo "Usage: bigpull option [branch]" fi0 -
reposync
This requires the github-sync tool. I run it between sprints to put everything into sync again (milestones & labels).
# Product declare -a repos=(addons internal multisite lithe analytics porter locales) repos+=(migrations roadmap docs standards wordpress-vanilla vanillicon vanillastatsapp) repos+=(vanilla-patches addons-patches wordpress-patches vanillainfrastructure vanillaforumscom) repos+=(garden garden-cli garden-http garden-container vanilla-jobber legacy-passwords) repos+=(htmlawed nbbc) for i in ${repos[@]} do github-sync labels -q -f vanilla/vanilla -t vanilla/$i github-sync milestones -q -f vanilla/vanilla -t vanilla/$i --autoclose done echo "Product repos synced" # Non-VIP repos declare -a customers=(vanilla-clients gazillion pennyarcade unknownworlds) for i in ${customers[@]} do github-sync labels -q -f vanilla/vanilla -t vanillaforums/$i github-sync milestones -q -f vanilla/vanilla -t vanillaforums/$i --autoclose done echo "Customer repos synced" # VIP repos declare -a vips=(adobe myfitnesspal amplify edmunds kixeye xogroup zenimax roadtripnation) vips+=(ea capitalone mmorpg sega oxford glu goodgames oculus perfectworld) vips+=(digitalspy enmasse aeriagames golfworx purestorage marykay) for i in ${vips[@]} do github-sync labels -q -f vanillaforums/vip-template -t vanillaforums/$i github-sync milestones -q -f vanillaforums/vip-template -t vanillaforums/$i --autoclose done echo "VIP repos synced" echo "Sync complete"0