Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Last active October 9, 2015 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziadoz/3559314 to your computer and use it in GitHub Desktop.
Save ziadoz/3559314 to your computer and use it in GitHub Desktop.
Web Development Setup (Bash, SSH, Ruby)
# Bash Profile
# File: ~/.bash_profile
# Set $WEB_DIR and $SCRIPTS_DIR to the appropriate directories.
export PATH="./vendor/bin:$PATH"
export EDITOR=nano
export WEB_DIR="/var/www/vhosts"
export SCRIPTS_DIR="~/.web"
alias reloadhosts="dscacheutil -flushcache"
alias reloadbash="source ~/.bash_profile"
alias editbash="subl ~/.bash_profile"
alias webdir="cd $WEB_DIR"
alias webvhosts="subl $WEB_DIR/vhosts.conf"
alias webstart="sudo apachectl start"
alias webstop="sudo apachectl stop"
alias webrestart="sudo apachectl restart"
alias webconfigtest="sudo apachectl configtest"
alias webupdate="ruby $SCRIPTS_DIR/webupdate.rb"
alias webpull="ruby $SCRIPTS_DIR/hgupdate.rb"
# Mercurial Deployment
# File: /path/to/repository/.hg/hgrc
# $ hg push staging
# $ hg push live
[paths]
live = ssh://<username>@<server>//var/www/vhosts/<live-website>
staging = ssh://<username>@<server>//var/www/vhosts/<staging-website>
[hooks]
changegroup = hg update
# SSH Config Example
# File: ~/.ssh/config
# Usage: $ ssh foobar
# SSH Identities:
# $ ssh-keygen -f ~/.ssh/<identity> -C "<identity>"
# $ ssh-add ~/.ssh/<identity>
# $ ssh-add -l
Host foobar
Compression yes
HostName 127.0.0.1
User username
Port 22
#! /usr/bin/env ruby
# Mercurial Update
# File: ~/.web/hgupdate.rb
$VERBOSE = nil
VHOST_DIRECTORY = ENV['WEB_DIR'] ||= "/var/www/vhosts"
DIR_PATTERN = File.join(VHOST_DIRECTORY, "/**")
require "shellwords"
Dir.glob(DIR_PATTERN).each do |dir|
hg = File.join(dir, ".hg")
dir = Shellwords.escape(dir)
system("cd #{dir} && hg pull -u") if File.exists?(hg)
end
#! /usr/bin/env ruby
# Web Udpate
# File: ~/.web/webupdate.rb
$VERBOSE = nil
VHOST_DIRECTORY = ENV['WEB_DIR'] ||= "/var/www/vhosts"
VHOST_PATTERN = File.join(VHOST_DIRECTORY, "/**/dev.conf")
VHOST_FILE = File.join(VHOST_DIRECTORY, "vhosts.conf")
confs = Dir.glob(VHOST_PATTERN)
open(VHOST_FILE, "w") do |file|
includes = confs.map{ |conf| "Include #{conf}" }.join("\n")
file.write(includes)
end
system("sudo apachectl configtest")
system("sudo apachectl restart")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment