Skip to content

Instantly share code, notes, and snippets.

@rigelk

rigelk/dockhand.sh

Created Jan 13, 2015
Embed
What would you like to do?
docker, docker-enter installer + installs a wordpress dev instance
#!/bin/bash
# Wordpress dev env installer for dummies.
command_exists() {
command -v "$@" > /dev/null 2>&1
}
user="$(id -un 2>/dev/null || true)"
sh_c='sh -c'
if [ "$user" != 'root' ]; then
if command_exists sudo; then
sh_c='sudo -E sh -c'
elif command_exists su; then
sh_c='su -c'
else
echo >&2 'Error: this installer needs the ability to run commands as root.'
echo >&2 'We are unable to find either "sudo" or "su" available to make this happen.'
exit 1
fi
fi
curl=''
if command_exists curl; then
curl='curl -sSL'
elif command_exists wget; then
curl='wget -qO-'
elif command_exists busybox && busybox --list-modules | grep -q wget; then
curl='busybox wget -qO-'
fi
# Install latest docker version (not the outdated docker.io package)
# -> does not support Archlinux yet
curl http://get.docker.com/ | sudo sh
# Taking care of the local copy of wordpress...
if [ -d wordpress ]; then
rm -rf wordpress
fi
# Actually downloading it...
curl -sSL http://wordpress.org/latest.tar.gz | tar xzC .
curl -sS http://wpcandy.s3.amazonaws.com/resources/postsxml.zip > file.zip ; unzip -j file.zip posts.xml -d wordpress/wp-content/ ; rm file.zip
# Install docker-enter
curl -o /usr/local/bin/docker-enter https://raw.githubusercontent.com/jpetazzo/nsenter/master/docker-enter
chmod 755 /usr/local/bin/docker-enter
# Run docker commands
if command_exists docker && [ -e /var/run/docker.sock ]; then
(
set -x
$sh_c 'docker run -d -p 80:80 --name wordpress -v $(pwd)/wordpress/wp-content/:/var/www/wordpress/wp-content rigelk/pressgang'
) || true
fi
# Self destruct :)
rm -- "$0"
# Enter the newly created container
if command_exists docker && [ -e /var/run/docker.sock ]; then
(
set -x
$sh_c 'docker-enter wordpress'
) || true
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.