0

I have a setup.py and I use fpm on that setup.py to create my python packages (debs and rpms). It works really well for upstart and systemd distros, but for systemv (debian7 specifically) I run into an issue with file permissions.

I need the /etc/init.d/ltsense script to be executable. Is this something I can do with data_files in the setup.py, or is this something I need to do with a post-install script passed to fpm?

Here is part of my setup.py:

...

from setuptools import setup, find_packages
import os
import platform
import math


def init_system():
    """
    Returns a tuple of init data files and a version suffix (deb only).
    Example: (('/etc/init/', ['scripts/upstart/ltsense.conf']),'~upstart')
    """
    distro = os.getenv('DISTRO', platform.linux_distribution()[0])
    release = os.getenv('RELEASE', platform.linux_distribution()[1])
    if distro == 'Ubuntu':
        return (('/etc/init/', ['scripts/upstart/ltsense.conf']),
                '~upstart')
    elif distro in ['debian']:
        release_int = int(math.floor(float(release)))
        if release_int == 7:
            return (('/etc/init.d/', ['scripts/systemv/ltsense']),
                   '~systemv')
        elif release_int == 8:
            return (('/lib/systemd/system/', ['scripts/systemd/ltsense.service']),
                   '~systemd')
    elif distro in ['centos', 'redhat', 'fedora']:
        return (('/lib/systemd/system/', ['scripts/systemd/ltsense.service']),'')

setup(
    name='ltsense',
    version='{}{}'.format(os.popen('git describe --dirty').readlines()[0].strip(),init_system()[1]),
    packages=find_packages(),
    author='Sumit Khanna',
    author_email='[email protected]',
    maintainer='Sumit Khanna',
    maintainer_email='[email protected]',
    url='http://bigsense.io',
    license='GNU General Public License v3',
    description='ltsense sensor collection and relay service',
    long_description=open('README').read(),
    data_files=[init_system()[0],
                ('/etc/ltsense/examples', ['etc/virtual-ltsense.conf',
                                           'etc/onewire-ltsense.conf'])
                ],
    entry_points={'console_scripts': ['ltsense=ltsense.__main__:main']},

...

EDIT: Not a Duplicate: This was marked a possible duplicate. My question deals with making packages via fpm, not setting permissions directly with the python setup script. I feel my solution is much cleaner than the linked duplicate for my particular use case.

1

1 Answer 1

0

I decided to do this in a post-install script instead which I pass to fpm using --after-install. It works for both the rpms and debs:

#!/bin/sh

if [ -f /etc/init.d/ltsense ]; then
  chmod 755 /etc/init.d/ltsense
fi
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.