Install a port from the ports tree. Installs using ``BATCH=yes`` for
    non-interactive building. To set config options for a given port, use
    :mod:`ports.config <salt.modules.freebsdports.config>`.

    clean : True
        If ``True``, cleans after installation. Equivalent to running ``make
        install clean BATCH=yes``.

    .. note::

        It may be helpful to run this function using the ``-t`` option to set a
        higher timeout, since compiling a port may cause the Salt command to
        exceed the default timeout.

    CLI Example:

    .. code-block:: bash

        salt -t 1200 '*' ports.install security/nmap

def install(name, clean=True):
    '''
    Install a port from the ports tree. Installs using ``BATCH=yes`` for
    non-interactive building. To set config options for a given port, use
    :mod:`ports.config <salt.modules.freebsdports.config>`.

    clean : True
        If ``True``, cleans after installation. Equivalent to running ``make
        install clean BATCH=yes``.

    .. note::

        It may be helpful to run this function using the ``-t`` option to set a
        higher timeout, since compiling a port may cause the Salt command to
        exceed the default timeout.

    CLI Example:

    .. code-block:: bash

        salt -t 1200 '*' ports.install security/nmap
    '''
    portpath = _check_portname(name)
    old = __salt__['pkg.list_pkgs']()
    if old.get(name.rsplit('/')[-1]):
        deinstall(name)
    cmd = ['make', 'install']
    if clean:
        cmd.append('clean')
    cmd.append('BATCH=yes')
    result = __salt__['cmd.run_all'](
        cmd,
        cwd=portpath,
        reset_system_locale=False,
        python_shell=False
    )
    if result['retcode'] != 0:
        __context__['ports.install_error'] = result['stderr']
    __context__.pop('pkg.list_pkgs', None)
    new = __salt__['pkg.list_pkgs']()
    ret = salt.utils.data.compare_dicts(old, new)
    if not ret and result['retcode'] == 0:
        # No change in package list, but the make install was successful.
        # Assume that the installation was a recompile with new options, and
        # set return dict so that changes are detected by the ports.installed
        # state.
        ret = {name: {'old': old.get(name, ''),
                      'new': new.get(name, '')}}
    return ret