# Copyright (c) 2012 Mathieu Turcotte
# Licensed under the MIT license.

from fabric.api import *
from fabric.utils import *
from fabric.colors import *
from fabric.contrib.files import exists

LOG_DIR="/var/log/ipupdate"
ETC_DIR="/usr/local/etc"
BIN_DIR="/usr/local/bin"

def add_user(username):
    with settings(hide("warnings"), warn_only=True):
        sudo('adduser --system --no-create-home %s' % username)

def configure_logging():
    sudo("mkdir -p %s" % LOG_DIR)
    sudo("chown -R ipupdate:ipupdate %s" % LOG_DIR)

def install_conf_file(config_file):
    put(config_file, "%s/ipupdate.conf" % ETC_DIR, use_sudo=True, mode=0644)
    sudo("chown ipupdate:ipupdate %s/ipupdate.conf" % ETC_DIR)

def install_init_script(is_fedora):
    if is_fedora:
        put("systemd/ipupdate.service", "/lib/systemd/system/ipupdate.service", use_sudo=True, mode=0644)
    else:
        put("upstart/ipupdate.conf", "/etc/init/ipupdate.conf", use_sudo=True, mode=0644)

def install_script():
    put("ipupdate.py", "%s/ipupdate.py" % BIN_DIR, use_sudo=True, mode=0755)

@task()
def install(config_file):
    is_fedora = exists('/etc/fedora-release')
    add_user("ipupdate")
    install_conf_file(config_file)
    install_init_script(is_fedora)
    configure_logging()
    install_script()

@@ -528,37 +528,34 @@
 def install_conf
-_file
+ig
 (config_file):%0A 
@@ -710,48 +710,55 @@
 all_
-init_script(is_fedora):%0A    if is_fedora
+service():%0A    if exists('/etc/fedora-release')
 :%0A  
@@ -1104,143 +1104,80 @@
     
-is_fedora = exists('/etc/fedora-release')%0A    add_user(%22ipupdate%22)%0A    install_conf_file(config_file)%0A    install_init_script(is_fedora
+add_user(%22ipupdate%22)%0A    install_script()%0A    install_config(config_file
 )%0A  
@@ -1199,28 +1199,29 @@
 ging()%0A    install_s
-cript
+ervice
 ()%0A

Simplify installation steps.