Scripts - Ubuntu: Questions and Answers (2014)

Ubuntu: Questions and Answers (2014)

Scripts

Skip to questions, Wiki by user kris-harper

Shell scripting with a common shell language like Bash, Perl, or PHP. Scripting in Python or other scripting languages are also appropriate topics.


Questions

Q: How do I create a deb package for a single python script?

Tags: scripts python (Next Q), packaging (Next Q)

I have a single python script that I want to distribute as a deb package. It is a indicator which shows local date in Unity panel. I did follow create a .deb Package from scripts or binaries but I could not create a deb package because it fails.

Can someone give me a step-by-step instruction on what I should do? As far as I know this script depends on python-appindicator.

NOTE:
I do not want any links to Debian/Ubuntu packaging instructions. I have seen most of them. I don't find them beginner friendly.

Tags: scripts python (Next Q), packaging (Next Q)

User: sagarchalise


Answer by andrewsomething

What follows is a basic example of how a source package for a python script might look. While most of the packaging tutorials are a bit complex, they can really help if you hit a problem. That said, I first learned the basics of Debian packaging by simply looking at Debian packages. apt-get source something similar and learn by example.

Here's your basic source package layout:

my-script/

-- myScript

-- debian/

-- changelog

-- copyright

-- compat

-- rules

-- control

-- install

Run dch --create in the directory to create a properly formatted debian/changelog entry.

debian/copyright should look like:

Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/

Upstream-Name: myScript

Upstream-Contact: Name, <email@address>

Files: *

Copyright: 2011, Name, <email@address>

License: (GPL-2+ | LGPL-2 | GPL-3 | whatever)

Full text of licence.

.

Unless there is a it can be found in /usr/share/common-licenses

debian/compat can just be: 7

debian/rules:

#!/usr/bin/make -f

%:

dh $@ --with python2

debian/control:

Skip code block

Source: my-script

Section: python

Priority: optional

Maintainer: Name, <email@address>

Build-Depends: debhelper (>= 7),

python (>= 2.6.6-3~)

Standards-Version: 3.9.2

X-Python-Version: >= 2.6

Package: my-script

Architecture: all

Section: python

Depends: python-appindicator, ${misc:Depends}, ${python:Depends}

Description: short description

A long description goes here.

.

It can contain multiple paragraphss

debian/install:

myScript usr/bin/

Now build it with debuild --no-tgz-check

This will create a functional deb package. Lintian is going to throw a few warnings regarding the lack of an orig.tar.gz, but unless you plan on creating a proper upstream project that makes tarball releases you'll probably just want to ignore that for now.


Answer by st-alfas

1. create a folder with any name on your home eg: mypyscript

2. Open the folder and create two folders with names 'DEBIAN' and 'usr'

3. Open the folder DEBIAN. Create a text file (without extension) with name 'control' there.

4. Open 'control' and type as follows and save it on DEBIAN

5. Package: mypyscript

6. Version: 0.01

7. Architecture: all

8. Maintainer: your name<your mail id>

9. Installed-Size: 2

10.Depends: python-appindicator

11.Section: extras

12.Priority: optional

13.Homepage: your homepage

14.Description: describe

5. Back to the folder named mypyscript. Open 'usr'. Create a folder named 'bin'. Open 'bin' and paste your pythonscript file there.

6. You can also make a menu entry. But that is not essential.

7. Back to the home folder where the folder 'mypyscript' lies or close the file browser.

8. Open terminal. Be sure that terminal is in the home folder. type dpkg -b mypyscript .Then press enter. In seconds your deb package is ready

note: please fill the 'control' file properly. Don't use apostrophes. It is only for indicating the names.


Tags: scripts python (Next Q), packaging (Next Q)


Q: What is the difference between ./ and sh to run a script?


Q: How do I create a deb package for a single python script?


Q: How can I get a list of all repositories and PPAs from the command line?


Q: Is #!/bin/sh read by the interpreter?


Q: Differences between /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin