Files @ 934e1c727136
Branch filter:

Location: rattail-project/rattail/fabfile.py - annotation

lance
Make `~/.ssh` by default, when bootstrapping rattail
cb0cb5abcb0e
ce10ee7d7ef8
ce10ee7d7ef8
ce10ee7d7ef8
180c9314d848
ce10ee7d7ef8
ce10ee7d7ef8
ce10ee7d7ef8
ce10ee7d7ef8
180c9314d848
180c9314d848
180c9314d848
ce10ee7d7ef8
ce10ee7d7ef8
ce10ee7d7ef8
180c9314d848
180c9314d848
ce10ee7d7ef8
180c9314d848
180c9314d848
ce10ee7d7ef8
ce10ee7d7ef8
c0f7f52edce0
c0f7f52edce0
c0f7f52edce0
ce10ee7d7ef8
d367272919e2
cb0cb5abcb0e
c0f7f52edce0
b24cd9b8fac0
ce10ee7d7ef8
ce10ee7d7ef8
331f775512a6
ce10ee7d7ef8
d367272919e2
d367272919e2
ce10ee7d7ef8
0bd512b7f502
add25f9c1b9c
0bd512b7f502
0bd512b7f502
0bd512b7f502
0bd512b7f502
e1f5452f36b2
0bd512b7f502
c0f7f52edce0
add25f9c1b9c
add25f9c1b9c
add25f9c1b9c
add25f9c1b9c
add25f9c1b9c
add25f9c1b9c
c0f7f52edce0
0bd512b7f502
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
0128177a4f14
331f775512a6
0128177a4f14
0128177a4f14
0128177a4f14
0128177a4f14
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
710ef746644d
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
331f775512a6
665457257332
331f775512a6
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
710ef746644d
665457257332
# -*- coding: utf-8 -*-
################################################################################
#
#  Rattail -- Retail Software Framework
#  Copyright © 2010-2017 Lance Edgar
#
#  This file is part of Rattail.
#
#  Rattail is free software: you can redistribute it and/or modify it under the
#  terms of the GNU General Public License as published by the Free Software
#  Foundation, either version 3 of the License, or (at your option) any later
#  version.
#
#  Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
#  details.
#
#  You should have received a copy of the GNU General Public License along with
#  Rattail.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Fabric script for 'rattail' package
"""

from __future__ import unicode_literals, absolute_import

import os
import shutil

from fabric.api import *
from fabric.contrib.files import exists, upload_template

from rattail.util import prettify


@task
def release(docs='false'):
    """
    Release a new version of `rattail`.
    """
    shutil.rmtree('rattail.egg-info')
    local('python setup.py sdist --formats=gztar upload')

    # docs
    if docs.lower() == 'true':
        os.chdir('docs')
        local('make clean')
        local('make html')
        os.chdir(os.pardir)
        local('python setup.py upload_docs')


def get_overwrite(overwrite=None):
    """
    Obtain a canonical "overwrite" directive.
    """

    if overwrite in (True, False):
        return overwrite

    if overwrite is None:
        overwrite = raw_input("Overwrite as needed? [y/N]: ")
        overwrite = overwrite.strip().lower()
    else:
        overwrite = overwrite.lower()
    return overwrite.startswith('y')


@task
def create_user(overwrite=None):
    """
    Create the 'rattail' user account.
    """

    overwrite = get_overwrite(overwrite)

    with settings(warn_only=True):
        result = run('id rattail')

    if result.return_code: # user doesn't exist
        sudo('adduser --system --home /var/lib/rattail --group rattail')

    elif overwrite:
        sudo('usermod --home /var/lib/rattail --move-home --shell /bin/false rattail')


def configure_rattail_lib(overwrite=None):
    """
    Configure basic Rattail "library" files.
    """

    overwrite = get_overwrite(overwrite)

    if not exists('/etc/default/rattail') or overwrite:
        put('data/etc/default/rattail', '/etc/default', use_sudo=True)
        sudo('chown root: /etc/default/rattail')

    if not exists('/var/lib/rattail'):
        create_user(overwrite=True)

    if not exists('/var/lib/rattail/init.d'):
        sudo('mkdir /var/lib/rattail/init.d', user='rattail')

    if not exists('/var/run/rattail'):
        sudo('mkdir /var/run/rattail')
        sudo('chown rattail: /var/run/rattail')


@task
def configure_filemon(name=None, desc=None, envdir=None, overwrite=None):
    """
    Configure a Rattail File Monitor daemon.
    """

    if name is None:
        default_name = 'rattail-filemon'
        name = raw_input("Enter a name for the service [{0}]: ".format(default_name))
        name = name.strip() or default_name

    if desc is None:
        default_desc = prettify(name.replace('filemon', 'file-monitor'))
        desc = raw_input("Enter a description [{0}]: ".format(default_desc))
        desc = desc.strip() or default_desc

    if envdir is None:
        default_envdir = name.replace('-filemon', '')
        default_envdir = default_envdir.replace('-', '.')
        default_envdir = '/srv/envs/{0}'.format(default_envdir)
        envdir = raw_input("Enter a virtual environment path [{0}]: ".format(default_envdir))
        envdir = envdir.strip() or default_envdir

    overwrite = get_overwrite(overwrite)
    configure_rattail_lib(overwrite)

    if not exists('/var/lib/rattail/init.d/filemon') or overwrite:
        put('data/var/lib/rattail/init.d/filemon', '/var/lib/rattail/init.d', use_sudo=True)
        sudo('chown rattail: /var/lib/rattail/init.d/filemon')

    script = '/etc/init.d/{0}'.format(name)
    if not exists(script) or overwrite:
        upload_template('data/etc/init.d/rattail-filemon_tmpl', script,
                        context=locals(), use_sudo=True, mode=0755)
        sudo('chown root: {0}'.format(script))
        sudo('update-rc.d {0} defaults'.format(script))


@task
def configure_dbsync(name=None, desc=None, envdir=None, overwrite=None):
    """
    Configure a Rattail Database Synchonizer daemon.
    """

    if name is None:
        default_name = 'rattail-dbsync'
        name = raw_input("Enter a name for the service [{0}]: ".format(default_name))
        name = name.strip() or default_name

    if desc is None:
        default_desc = prettify(name.replace('dbsync', 'database-synchronizer'))
        desc = raw_input("Enter a description [{0}]: ".format(default_desc))
        desc = desc.strip() or default_desc

    if envdir is None:
        default_envdir = name.replace('-dbsync', '')
        default_envdir = default_envdir.replace('-', '.')
        default_envdir = '/srv/envs/{0}'.format(default_envdir)
        envdir = raw_input("Enter a virtual environment path [{0}]: ".format(default_envdir))
        envdir = envdir.strip() or default_envdir

    overwrite = get_overwrite(overwrite)
    configure_rattail_lib(overwrite)

    if not exists('/var/lib/rattail/init.d/dbsync') or overwrite:
        put('data/var/lib/rattail/init.d/dbsync', '/var/lib/rattail/init.d', use_sudo=True)
        sudo('chown rattail: /var/lib/rattail/init.d/dbsync')

    script = '/etc/init.d/{0}'.format(name)
    if not exists(script) or overwrite:
        upload_template('data/etc/init.d/rattail-dbsync_tmpl', script,
                        context=locals(), use_sudo=True, mode=0755)
        sudo('chown root: {0}'.format(script))
        sudo('update-rc.d {0} defaults'.format(script))