stagehand / install /

Full commit

Install nginx using apt (default) or from source.
Requires a working fabric installation on the installing host.

Copyright 2010-2012 Van Lindberg. Released under the BSD license.

The exported API consists of the following functions:

- nginx_installed(): Test to see whether nginx has been installed
  and is available on the $PATH. Return True or False.

  install_nginx(use_src=False): Try to install the latest nginx 
  provided by apt. The precise packages installed are 
  controlled by constants.NGINX_APT_PACKAGES. Exposed as a task.
# stdlib imports
import re
import urllib

# Third party imports
from fabric.api import *

# Package imports
from .. import constants
from ..utils import report, which
from .tools import add_apt_repository, apt_install, update_packages 

__all__ = ['nginx_installed', 'install_nginx']

def add_nginx_archive(archive=constants.NGINX_PPA):
  Add the archive for nginx.

def nginx_installed():
  Test to see whether nginx has been installed.
  Return True or False.
  return bool(which('nginx'))

def install_nginx(upgrade=False):
  Install the latest nginx provided by apt (default) or by
  the source downloads on  
  if nginx_installed() and not upgrade:
    report('Nginx already installed. Skipping...')
    # Make sure that we have the latest
    apt_install(constants.NGINX_APT_PACKAGES, warn_only=True)
    if not nginx_installed(): 
      abort('Could not install nginx.')
      report('Nginx installed.')