Problem creating a .deb packet

New to Debian (Or Linux in general)? Ask your questions here!

Problem creating a .deb packet

Postby loopin » 2010-03-24 14:23

First hello to everybody, i'm a new user of this forum, who has just begun to work with linux.

I have to do a .deb packet which will be placed in the repositories of the company.When this packet is installed, it only have to copy a plain text archive i've wrote before, to a path where it's being installed.
The other requisite is that it have to watch if there's a program (vim) installed, if it's not installed, then the packet i have created shouldn't install.

example:

# ls /home/loopin (as we see, this directory is empty)
.
..

# apt-get install mypacket
...
...
(checking if VIM is installed... OK!)
...
...

# ls /home/loopin (now this directory have a textarchive that i wrote)
.
..
textarchive.txt

I've searched at howtos and tutorials, but everything i read was aimed to people who wants to make big packets who install applications, and i just want to copy a text file :P

Thanks in advance, and sorry but my english is not very good (that's whay i used a "graphic example" :P )
loopin
 
Posts: 7
Joined: 2010-03-24 13:53

Re: Problem creating a .deb packet

Postby barriehie » 2010-03-24 18:46

With the directory requirement you mentioned a script will have to be run to initiate/cancel the install. Does /home/loopin have to exist AND be empty? (is loopin a USER or do you mean /home/USER/loopin)


Code: Select all
if [ -d /home/loopin ]; then  # Check if directory exists
...do whatever... # Maybe check if already installed???
else  # Directory doesn't exist
...do whatever...
fi
barriehie
 

Re: Problem creating a .deb packet

Postby loopin » 2010-03-24 22:24

well, i said /home/loopin but it was only an example, it could be /var/log or anywhere else, and there's no need for the directory to be empty, it can be full of archives and i'm sure that directory exists before i install this .deb, the packet will just check if an application (in the example, VIM) is installed (i think something like a dependence)

that code would be ok if the condition for the "if" was a check for the "vim" app...

besides i don't know what to do with that script to make it a .deb packet for our repository, i think it have to be something far easier than tutorials i've read because they use makefile, gcc...

Thanks!

PD: the plain text archive i want to copy to the machine is going to be into the .deb packet too.
loopin
 
Posts: 7
Joined: 2010-03-24 13:53

Re: Problem creating a .deb packet

Postby barriehie » 2010-03-24 22:30

loopin wrote:well, i said /home/loopin but it was only an example, it could be /var/log or anywhere else, and there's no need for the directory to be empty, it can be full of archives and i'm sure that directory exists before i install this .deb, the packet will just check if an application (in the example, VIM) is installed (i think something like a dependence)

that code would be ok if the condition for the "if" was a check for the "vim" app...

besides i don't know what to do with that script to make it a .deb packet for our repository.

Thanks!


So basically then all we need to do is check if vim is installed and if so then proceed with installing your text file, assuming the dir. exists. Where do we get the directory to be installed in? Will it be the same everytime? And you still need to turn your .txt file into something.deb?
barriehie
 

Re: Problem creating a .deb packet

Postby bugsbunny » 2010-03-24 23:23

Where do we get the directory to be installed in? Will it be the same everytime?

This is the key question.

As far as vim goes you can either check if it's installed in a pre-install script (part of the deb package format), or use a dependency to install vim if it's not already installed (and the install would fail if it was unable to install vim).

Note that vim-tiny is flagged as an "important" package an is therefore installed by default in any Debian install (including a minimal one). You have the option of installing a more full-fledged vim package.
(there's a number of them which are possible)). The way it should work (assuming nobody has messed with the structure) is using the alternatives structure and uses symlinks represented by --> below.

/usr/bin/vim --> /etc/alternatives/vim --> (actual executable such as /usr/bin/vim.tiny or /usr/bin/vim.basic)

The bottom line is that some form of vim should pretty much always be installed - unless it was manually removed.

The dependency route is easier, and you could set it to depend on any of the vim flavors (eg vim-tiny OR vim OR vim-gtk OR vim-gnome etc, although the format isn't as I stated here).

If the location to install the txt file is fixed all this is very easy. If it's variable it becomes trickier.
User avatar
bugsbunny
 
Posts: 5355
Joined: 2008-07-06 17:04

Re: Problem creating a .deb packet

Postby barriehie » 2010-03-25 01:21

Well this has become a hoot! :D I made a small .deb file, dependent on vim-common, and it all worked fine. Dug a bit more and still haven't figured out the postinst script thing to make it launch vim with the text file upon completion of the install. Then I made it dependent on various flavors of vim and was expecting to see dependencies not satisfied blah blah blah but oh no! gdebi promptly started installing all of them!!!( maybe I should check it out, it's an emacs thing...) So I'm speed bumped at the pre and post script thing but making the .deb is easy enough.

Edit: Gottit! Only -small- issue is that it open vim in the gdebi installer terminal; have to work on that.
Last edited by barriehie on 2010-03-25 05:24, edited 1 time in total.
barriehie
 

Re: Problem creating a .deb packet

Postby barriehie » 2010-03-25 04:01

lintian doesn't like it but since I'm not a software developer I can live with a bit of whining! It installs and tests for which terminal is in use to open vim and the file in. Since this sounds like a very specific application I'm only testing for terminals I've found common to the distros I've installed, mainly either bash or xterm. Since I've still got a bit over 1000 commands to learn in bash I'm still partial to that one... OP can edit the postinst script as desired to fit the application. Now about that install dir!

Edit: Found a couple of links on creating .deb packages.
1. http://www.debian.org/doc/FAQ/ch-pkg_basics.en.html
2. http://www.linuxfordevices.com/c/a/Linu ... -packages/
Last edited by barriehie on 2010-03-25 05:28, edited 1 time in total.
barriehie
 

Re: Problem creating a .deb packet

Postby stevepusser » 2010-03-25 05:27

Hmmm---hey, you could write a simple Makefile to install or uninstall your text file (Blah, for example):

Code: Select all
make: install uninstall

install:
   cp blah /usr/share/someplace

uninstall:
   rm /usr/share/someplace/blah


indents are with a Tab, not spaces.

Put the Makefile in with your text file in a source folder, give the source folder a name and version number, then debianize it with dh_make -r. You can just replace the default template /debian/rules file with this:

Code: Select all
#!/usr/bin/make -f
%:
   dh $@


which should handle deb package creation automatically. In the /debian/control file, you can specify Depends: and Conflicts: to make sure what vim packages can coexist with your text file.
The MX Linux repositories: Backports galore! If we don't have something, just ask and we'll try--we like challenges. New packages: llvm-8 toolchain, Rustc 1.36, wine-staging 4.16, Telegram-desktop 1.8.8, Pale Moon 28.7.1, Waterfox 56.2.14
User avatar
stevepusser
 
Posts: 11163
Joined: 2009-10-06 05:53

Re: Problem creating a .deb packet

Postby loopin » 2010-03-25 07:20

Well, i'm going to talk about the REAL thing :P becuse VIM was only an example but it's creating confussion...

when i do "apt-get install filterlogcheck" (name of my package) it will check if the logcheck packet is installed previously, if not, my .deb does NOTHING (that would be more like a requirement than a dependence) , if it's installed, it will write a plain text archive in /etc/logcheck/ignore.d.server/ . That will make logcheck to filter some messages, according with that text file i wrote there.

Sorry for the first confussing post!

PS: I'm going to read that howtos right now, hope that will be of help :)
PS2: stevepusser's post seems to be good... i'm going to try that when i finish to read that tutorials

PS3: It seems i did it! i just created the directories' structure filterlog/etc/logcheck/ignore.d.server/filterlist.txt, debianized it with dh_make -r and dpkg'd it. No makefiles, no scripts... nothing :D but it does what i want, copy the filterlist.txt at /etc/logcheck/ignore.d.server/ directory :) I would like to "sharp" this packet, and make it check if /etc/logcheck/ignore.d.server/ exists, or if Logcheck app is installed. Someone can tell me how to do it?

Thanks 4 everything!
loopin
 
Posts: 7
Joined: 2010-03-24 13:53

Re: Problem creating a .deb packet

Postby barriehie » 2010-03-25 14:33

loopin wrote:...muted...
I would like to "sharp" this packet, and make it check if /etc/logcheck/ignore.d.server/ exists, or if Logcheck app is installed. Someone can tell me how to do it?

Thanks 4 everything!


Now this is where you would need the preinst script... In regards to stevepusser's post I have no idea where the script would go! :?:
barriehie
 

Re: Problem creating a .deb packet

Postby bugsbunny » 2010-03-25 15:25

For the preinst script, after you run dh_make look in the debian directory that's created. You'll see, among other things, a bunch of .ex files, where ex stands for example. You can/should delete any you don't need. One of the files is preinst.ex, that's the example for a preinstall script. Modify that and rename it removing the .ex.

Place the checks you want under the install|upgrade section. If it fails the check exit with a non-zero code and the install will fail.

To really do things right you should probably modify the other files in the debian directory and replace the skeleton entries with valid data (leave the rules file alone. Anything else, if in doubt don't touch. Things which you should change should be obvious, the relevant files are commented appropriately).
User avatar
bugsbunny
 
Posts: 5355
Joined: 2008-07-06 17:04

Re: Problem creating a .deb packet

Postby barriehie » 2010-03-25 16:10

This should get you started. Might be a more elegant way...

preinst
Code: Select all
#!/bin/bash

directory="/etc/logcheck/ignore.d.server"

#
#  Check if LogCheck is installed
#
dpkg --get-selections | grep logcheck | gawk '{ if($2~"install") { print "" }}' > ./installed
if [ -f ./installed ]; then
#
#  logcheck is installed so abort installation
#
  rm ./installed
  killall -s 9 apt-get
  exit 1
fi

#
#  logcheck isn't installed so check for /etc/logcheck/ignore.d.server
#
if [ -d $DIRECTORY ]; then
#
#  Directory exists, continue
#
else
#
#  Directory doesn't exist, make it.
#
mkdir /etc/logcheck
mkdir /etc/logcheck/ignore.d.server
fi

#
#  Continue with installation
#

exit 0
barriehie
 

Re: Problem creating a .deb packet

Postby stevepusser » 2010-03-26 04:53

I thought I'd be cute by posting that tiny rules file, since that's seems to be what the upstream policy in Sid seems determined to prefer. It does everything that the big template that dh_make creates automagically...gave me fits when I first saw one of those. Turns out you customize one of those by adding override sections, to change the defaults.
The MX Linux repositories: Backports galore! If we don't have something, just ask and we'll try--we like challenges. New packages: llvm-8 toolchain, Rustc 1.36, wine-staging 4.16, Telegram-desktop 1.8.8, Pale Moon 28.7.1, Waterfox 56.2.14
User avatar
stevepusser
 
Posts: 11163
Joined: 2009-10-06 05:53

Re: Problem creating a .deb packet

Postby bugsbunny » 2010-03-27 04:22

Modified version of presinst.ex created by dh_make

Code: Select all
#!/bin/sh
# preinst script
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    install|upgrade)
      [ -x /usr/sbin/logcheck ] || exit 1
    ;;

    abort-upgrade)
    ;;

    *)
        echo "preinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


The only thing I did was add the line:
Code: Select all
      [ -x /usr/sbin/logcheck ] || exit 1

which will test to see if /usr/sbin/logcheck exists and is an executable file. If not it exits with a return code of 1. That's all that's needed. As long as the structure of the data is done correctly and needed directory structure will automatically get created upon install.
User avatar
bugsbunny
 
Posts: 5355
Joined: 2008-07-06 17:04

Re: Problem creating a .deb packet

Postby loopin » 2010-04-05 07:39

Hey, many thanks for your advices! First of all, sorry for being afk all this time, it was my holidays :)
Now my "boss" has changed his mind, he wants the packet to check if logcheck is installed, if not, it will install it from the repository... i think i can do this only by editing the "depends:" line in the control file, adding logcheck to the line, am i right?

Edit: depends didn't help me because if i put logcheck in the depends line at control file, ti checks if it's installed, if not, it does nothing, but now i want it to install logcheck if it's not installed, now i'm going to check if "pre-depends" can work

Thanks for the scripts, they look so "pro" but i'll try the easier way, so if i can't do that in that way, i'll try with that scripts
loopin
 
Posts: 7
Joined: 2010-03-24 13:53

Next

Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 10 guests

fashionable