Tuesday, 3 May 2016

Packaging python scripts into RPM's

Firstly install the relevent dependancies:

sudo dnf install rpm-build rpmdevtools

cd to a directory within your home folder e.g.:

cd ~/packages

and then run 'rpmdev-setuptree':


The above will generate the folder tree structure for our rpm creation.

Proceed by checking the .rpmmacros file is correct:

cat ~/.rpmmacros

*Note* The "_topdir" variable in the '.rpmmacros' file defines the root path - e.g. if you wanted to deploy the nano utility we might put it in $_topdir/usr/bin.

We should bundle our sources up:

tar czvf myscript_0.1.tar.gz myscript/

and place it in the 'SOURCES' folder:

mv myscript_0.1.tar.gz /home/limited/packages/myscript/SOURCES

We should now create our 'spec' file - which contains the meet of the configuration, defining dependencies, build instructions and so on:

vi ~/packages/myscript/SPECS/myscript.spec

An example .spec file is as follows:

Name: pywinusb
Version: 1
Release: 0
Summary: Allows you to install Windows on a USB drive.
Source0: pywinusb_0.1.tar.gz
License: GPL
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-buildroot

Allows you to install Windows on a USB drive.


%setup -q


mkdir -p $RPM_BUILD_ROOT/usr/share/pywinusb/bin
install -m 0755 pywinusb.py $RPM_BUILD_ROOT/usr/share/pywinusb/bin/pywinusb


ln -sf /usr/share/pywinusb/bin/pywinusb /usr/bin/pywinusb
echo pywinusb has been installed successfully!


%dir /usr/share/pywinusb/bin

Finally we can build the rpm with:

cd ~/rpmbuild
rpmbuild -ba SPECS/myscript.spec


Post a Comment