Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Problem creating a .deb packet

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
loopin
Posts: 7
Joined: 2010-03-24 13:53

Problem creating a .deb packet

#1 Post by loopin »

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 )

barriehie

Re: Problem creating a .deb packet

#2 Post by barriehie »

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

loopin
Posts: 7
Joined: 2010-03-24 13:53

Re: Problem creating a .deb packet

#3 Post by loopin »

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.

barriehie

Re: Problem creating a .deb packet

#4 Post by barriehie »

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?

User avatar
bugsbunny
Posts: 5354
Joined: 2008-07-06 17:04
Been thanked: 1 time

Re: Problem creating a .deb packet

#5 Post by bugsbunny »

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.

barriehie

Re: Problem creating a .deb packet

#6 Post by barriehie »

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

#7 Post by barriehie »

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.

User avatar
stevepusser
Posts: 12930
Joined: 2009-10-06 05:53
Has thanked: 41 times
Been thanked: 71 times

Re: Problem creating a .deb packet

#8 Post by stevepusser »

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.
MX Linux packager and developer

loopin
Posts: 7
Joined: 2010-03-24 13:53

Re: Problem creating a .deb packet

#9 Post by loopin »

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!

barriehie

Re: Problem creating a .deb packet

#10 Post by barriehie »

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! :?:

User avatar
bugsbunny
Posts: 5354
Joined: 2008-07-06 17:04
Been thanked: 1 time

Re: Problem creating a .deb packet

#11 Post by bugsbunny »

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).

barriehie

Re: Problem creating a .deb packet

#12 Post by barriehie »

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

User avatar
stevepusser
Posts: 12930
Joined: 2009-10-06 05:53
Has thanked: 41 times
Been thanked: 71 times

Re: Problem creating a .deb packet

#13 Post by stevepusser »

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.
MX Linux packager and developer

User avatar
bugsbunny
Posts: 5354
Joined: 2008-07-06 17:04
Been thanked: 1 time

Re: Problem creating a .deb packet

#14 Post by bugsbunny »

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.

loopin
Posts: 7
Joined: 2010-03-24 13:53

Re: Problem creating a .deb packet

#15 Post by loopin »

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

User avatar
bugsbunny
Posts: 5354
Joined: 2008-07-06 17:04
Been thanked: 1 time

Re: Problem creating a .deb packet

#16 Post by bugsbunny »

Depends works, and is what you want. It's a matter of HOW you install the package. dpkg (as in dpkg -i) will not resolve dependencies, but will just check to see if they are satisfied.

gdebi on the other hand, will resolve and install missing dependencies. gdebi can be used as either a gui or cli method of installation.

The other solution is to create a local repository then add your package to the local repository. You would then need to add the local repository to your sources.list. After that you would install the package using standard tools like apt-get, aptitude or synaptic. This, however, is almost certainly overkill for only 1 package :), but is worth looking at if you plan on creating lots of local packages.

EDIT: I just looked at the first post and see that the company apparently has it's own repositories. So if gdedi works when testing (I'm guessing you used dpkg -i for testing) then once the package is installed into the local repositories the standard install methods should work fine.

loopin
Posts: 7
Joined: 2010-03-24 13:53

Re: Problem creating a .deb packet

#17 Post by loopin »

hehe many thanks, i did that, i've made a local repository using "deb file:/..../..../ .../" in /etc/apt/sources.list and it worked fine! :)


I'm reading about how to make my .deb packet to ask to the user at the end of the installation, if he wants to run a bash script which has just installed with the .deb .

I think i've got to work with postinst.ex, but i'm not sure.

Should I open another thread for that question? or should ask that here?
Sorry about having so many questions, but i'm totally a noob with this! :D

Post Reply