Search code examples
shellbuildpackagedebiandpkg

Building debian package for shell script


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.


Solution

  • 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 ../.