Building debian package for shell script
Asked Answered
C

5

7

What: I've a shell script that I'd like to distribute to my LUG. I believe that a debian package will be the easiest way to distribute it. I want to create a .deb file for the script in this repository

Where: I want it to be placed in some directory like /usr/local/bin so that it is easy to execute and maybe create some symbolic links

Problem: How to write make file for it and/or other files and folders required to do that. I researched a lot when I tried to do it couple of months ago but no luck then. Here are the files from my previous attempt Now I'm trying to pack this for a tutorial on shell script in my LUG and facing similar situation again.

I'll be really glad if someone can be patient enough to guide me through it.

Any kind of resources or details will be much appreciated.

PS: I also intend to port the script to perl soon.

Castellany answered 6/1, 2014 at 21:31 Comment(0)
R
7

As mirabilos said, you should at least have a look to the packaging-tutorial written by Lucas Nussbaum, the current Debian Project Leader. You can install it directly from a Debian repository:

# apt-get install packaging-tutorial

Then, open and skim the PDF located at /usr/share/doc/packaging-tutorial/packaging-tutorial.pdf. After skimming it you'll have the basic knowledge needed to understand the structure of a Debian package.

Now let's get our hands dirty. mv your script to a new directory. The name of the directory must follow the nomenclature upstreamname-*version*.

rul@helicon:/tmp/a$ mkdir script-0.1
rul@helicon:/tmp/a$ mv script.sh script-0.1

cd to the directory where your script is and run dh_make --createorig. Choose single binary. You'll now have a debian/ directory with lots of file in it. This files are the ones you need to make your package. In your case, most, if not all, of the *.ex files are safe to be removed. Read and modify when needed the remaining files.

Now let's write the core of our package. You want to install a script in /usr/local/bin. The good news is that there is already a program that does that for you. You just have to specify the file name and where to put it. This program is dh_install. It has a very complete man page. After reading it, you should now understand that you have to create a install file in the debian/ directory.

rul@helicon:/tmp/a/script-0.1$ echo "script.sh usr/local/bin/" > debian/install

Here you have a real example of this file usage.

That's it! You have all you need to build your package. cd to the root directory of your package and run dpkg-buildpackage. If all went well, you'll have your fresh new .deb in ../.

Rustication answered 8/1, 2014 at 21:22 Comment(4)
dh_usrlocal: debian/universal/usr/local/bin/chaudhary.sh is not a directory rmdir: failed to remove ‘debian/universal/usr/local/bin’: Directory not empty dh_usrlocal: rmdir debian/universal/usr/local/bin returned exit code 1 make: *** [binary] Error 1 Well apparantly you can't move a file into /usr/local/, only directories can be created. But anyway thanks a lot man. I changed it to /usr/bin and it works perfectly fine. Awesome :)Castellany
Oh, you're right. Please, take a look the dh_installdirs command.Rustication
Actually the problem here is that placing files under /usr/local/ is against the policy, and that's why "official" tools (in this case, dh_usrlocal) fail. To override dh_usrlocal behavior, just add a new rule at the bottom of debian/rules file called override_dh_usrlocal:.Rustication
Except, don't install to /usr/local. It is reserved for local files created by the system administrator.Resilient
R
2

If your package will only have a single file (or small number of files) in it, going through the full Debian toolchain might be overkill.

For packaging single files, I recommend you use the equivs tool. Install the equivs package, then run equivs-control to create a template file.

Edit the template file (give your package a name, version number etc.).

Add the name of your script to the Files: attribute in the template, for example:

Package: my-awesome-script
Version: 4.2
Files: my-awesome-script.sh /usr/local/bin
Section: misc
Priority: optional
Standards-Version: 3.9.2
Maintainer: Me <[email protected]>
Description: An awesome script doing stuff
 Lorem ipsum etc. pp.

Put the script file alongside the template file.

Run equivs-build which will create your Debian package.

This is much easier for these simple cases than anything else – and the package that you get is standards compliant without resorting to any hacks or jumping through hoops.

Recalcitrant answered 27/4, 2014 at 3:58 Comment(0)
E
1

You really should have a look at, in this order, the inofficial packaging tutorial, the Debian New Maintainers' Guide, Debian Developer's Reference and Policy. (The order is also increasingly dry, and reversed for formalness.)

It may take two days or so, but is really worth it.

Also, look at other small packages shipping only scripts, or other mere “file installers” (like php-htmlpurifier, first example I remembered while writing this).

Eigenvalue answered 7/1, 2014 at 0:8 Comment(1)
No idea why this was down-voted, it's the correct approach. For example, to avoid "create a package" and "/usr/local" combined in one sentence in the future.Resilient
A
1

Use checkinstall or fpm to build your packages in minutes not hours or days!:

sudo checkinstall --fstrans=yes --install=no -D --pkgname=script \
    --maintainer='Name <[email protected]>' --pkgarch=all --pkgversion=0.1 \
    --nodoc cp script.sh /usr/local/bin

fpm -s dir -t deb --prefix /usr/local/bin -n script -v 0.1 -a all ./script.sh

Note: checkinstall requires dpkg/dpkg-deb (only works on Debian/Ubuntu), fpm is platform independent but requires ruby.

Appall answered 22/5, 2015 at 4:24 Comment(4)
Could anyone who has down-voted this answer please explain why? Thanks.Catenary
It's a good answer, I don't see why it should be downvoted, either.Recalcitrant
Using fpm (and presumably checkinstall) is correlated with producing a problematic package (e.g. run lintian on a fpm package, and you will see the problems). If you are planning on distributing packages for Debian/Ubuntu or their derivatives, using the correct tool chain will save time and effort over the long term.Rickrickard
This doesn't stop you using fpm if you just need to quickly deploy something, but an fpm package should not be seen as an alternative to a correctly packaged deb (or debs, as the case may be).Rickrickard
S
1

for pre install, write your script in file DEBAIN/preinst;

for post install, write your script in file DEBAIN/postinst;

Safelight answered 21/12, 2020 at 7:34 Comment(2)
Could you give more details for each path, and some link to doc?Deportee
Hello and welcome to SO! Please read the tour, and How do I write a good answer?Dismissal

© 2022 - 2024 — McMap. All rights reserved.