/srv/irclogs.ubuntu.com/2008/07/28/#ubuntu-classroom.txt

bazhang@schedule05:20
ubottubazhang: Schedule for Etc/UTC: 28 Jul 14:00:  Maintainer scripts | 31 Jul 14:00: Mentoring Reception | 31 Jul 16:00: Ubuntu Mobile | 02 Aug 13:00: Xubuntu Community | 03 Aug 18:00: Mozilla Team | 05 Aug 22:00: Community Council05:20
bazhangdmwaters, could you specify a bit more? what modules do you need to load05:22
=== dosnubbi1 is now known as dosnubbie
=== croppa_ is now known as croppa
goshawkhi14:54
DRebellionallo14:54
goshawkhi norsetto14:54
goshawk:)14:54
norsettoheya :-)14:54
* DRebellion draws a giant stickman on the whiteboard14:55
DRebellion:P14:55
norsettoHi everybody, thanks for coming and welcome to this lecture!15:01
norsettoWho do we have here?15:01
DRebellionme15:01
coolbhavicoolbhavi, me15:01
goshawkme15:01
=== pleia2 changed the topic of #ubuntu-classroom to: Ubuntu Open Week is over, thanks for participating! | Information and Logs: https://wiki.ubuntu.com/UbuntuOpenWeek | Current Session: Monday 28th July at 14:00 UTC: MOTU School Session: Maintainer Scripts by Cesare Tirabassi
norsettohi DRebellion!15:01
norsettocoolbhavi, goshawk: nice to see you here15:01
goshawknorsetto: are you cesare tirabassi?15:02
norsettonobody else? Too timid to talk?15:02
tuxmaniacHi everybody15:02
norsettogoshawk: the very one15:02
norsettohi tuxmaniac15:02
tarvidnah just too many of us15:02
Xk2chi15:02
RainCTheh15:02
ssweenyif everyone sounded off the session would be over15:02
NielsEhi15:02
DabianI am here too .. trying to catch up.15:02
DabianThe topic change confused me.15:03
norsettook, I guess we can start, make yourself confortable, take a can of your preferred drink ;-)15:03
coolbhavinorsetto, I ve seen you working at LP answer tracker Interested to attend this session15:03
coolbhavivery interested15:03
norsettoDabian: what topic change?15:03
* huats too :)15:04
norsettoDabian: look good to me :-)15:04
pleia2Dabian: just updated from "Next" to "Current" :)15:04
DabianThe topic of the channel changed ... I'm not used to this client.15:04
norsettoWe will talk in general about the basics of the debian package management and cover maintainer scripts in some detail15:04
goshawknorsetto: i'm italian too :) (your name is italian)15:04
norsettoWe will not tackle very complex subjects, I tried to make this very informative but at the same time accessible to all newcomers, even those with little debian/ubuntu experience (sorry if this will bore everybody else)15:04
norsettogoshawk: yes, nobody is perfect ;-)15:05
norsettoIf there is something you don't understand, stop me and ask, ok?15:05
coolbhaviok15:05
DabianOK15:05
NielsEok :-)15:05
norsettoAnybody know what a debian binary package is (I mean, the .deb file)?15:05
goshawkok15:05
goshawki know15:05
DRebellionnorsetto, a file tree essentially15:05
NielsEyes15:06
norsettoyep, its just an archive file15:06
norsettoYou can download a deb, for instance ucf, hardy version: wget http://archive.ubuntu.com/ubuntu/pool/main/u/ucf/ucf_3.005_all.deb15:06
norsettowget http://archive.ubuntu.com/ubuntu/pool/main/u/ucf/ucf_3.005_all.deb15:06
norsettook, everybody got it? We will use this quite often during this lecture.15:07
NielsEgot it15:07
Xk2cyep15:07
DRebellionyar15:07
norsettoNow check it with: ar -t ucf_3.005_all.deb15:07
DabianWell .. I don't know the structure of it, but I guess its a compressed directory structure of some kind.15:07
norsettoWhat do you see?15:07
bhavi_norsetto, question: can we update a package maintained by some one else?15:07
norsettobhavi_: yes, of course you can, but is always better to first ask15:08
Xk2cdebian-binary control.tar.gz data.tar.gz15:08
norsettodebian-binary is simply an ascii file containing the version of the debian format (now 2.0)15:08
DabianI got it now .. about to check it.15:08
norsettodata.tar.gz contains the files to be installed15:09
Kopfgeldjaeger2Three files, one containing the control file and sometimes {pre,post}{rm,inst} and the other one containing the application itself (binary files, man pages, scripts)15:09
norsettocontrol.tar.gz contains the control files, we will see later in details what these are15:09
norsettoKopfgeldjaeger2: yes15:09
norsettoThat's about it, simple isn't?15:10
NielsEseems easy15:10
DRebellionnorsetto, why does debian use the 'ar' format instead of 'tar'15:10
DRebellion?15:10
DabianI am trying to catch up.15:10
norsettoDRebellion: good question, I guess thats because ar is simpler15:11
DRebellionnorsetto, then, why don't we all use ar instead of tar?15:11
norsettoDRebellion: because ar is not universal15:11
norsettoDRebellion: ar is just GNU, tar is unix and linux15:12
DRebellionok15:12
norsettoI guess everybody know what dpkg is?15:12
norsettoOK, dpkg is Debian main package management program (some people would disagree with the word management though)15:12
bhavi_yes15:13
DRebellionjust a note, wikipedia says that tar has weak integrity checking and supports unicode, ar does not.15:13
norsettoDRebellion: yes, its simpler ;-)15:13
norsettoIt can be used to install, unpack, configure, remove or purge packages15:13
norsettoIt can also be used to extract or list the content of a package15:14
norsettodpkg will not attempt to satisfy dependencies, for that you have to use a more advanced tool, like apt (which uses dpkg as a backend)15:14
norsettoIf you want to be a good maintainer, you should learn how dpkg works when it installs/upgrades or removes packages15:15
norsettoplease let me know if you think I'm going too fast15:15
MikeMcok15:15
Xk2cis ok15:15
NielsEnot for me (yet)15:15
DRebellionfine15:15
norsettoWhat would you do if, for whatever reasons, dpkg is corrupted on your system and doesn't work anymore?15:15
Xk2cboot knoppix15:16
coolbhavireconfigure dpkg15:16
DRebellionnorsetto, download the dpkg debs, extract the file structure, copy it to your root (/).15:16
Kopfgeldjaeger2sudo apt-get -f install (in some cases)15:16
norsettowell, think about what we just learned about the structure of a deb package15:16
norsettoDRebellion: exactly15:17
DRebellion:)15:17
norsettoKopfgeldjaeger2: that will not work, since dpkg will not work15:17
coolbhavidpkg --configure -a?15:17
Kopfgeldjaeger2norsetto: yay, i just thought we had unresolved dependencies or so15:17
norsettocoolbhavi: also that would fail, dpkg doesn't work15:17
coolbhaviOK!15:18
Kopfgeldjaeger2but as that's not the case, jsut ignore it15:18
norsettoFor example, lets see what dpkg will do when requested to remove a package15:18
norsettoYou can check man dpkg for some basics, there are more complex and exhaustive information in the Debian policy, chapter 615:18
norsettoHere is a link if you want a reference during this lecture: http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html15:19
norsettoWhen dpkg is requested to remove a package, first, it will run the package's prerm script15:19
norsettoThe prerm script is one of the maintainer scripts, we will see it later in details15:19
norsettoThen it will remove the files that were installed for that package, minus the configuration files15:19
norsettoWe will see later what the configuration files are15:19
norsettoThen it will run the postrm script15:20
norsettoAs you guessed it, another maintainer script15:20
norsettoIs that sequence clear?15:20
coolbhaviyes15:20
DRebelliongot it15:20
Xk2cprerm then postrm15:20
norsettoFor purging it is the same but as a last step it will also remove the configuration files15:20
norsettoAnother more complex example is for an upgrade15:21
norsettoFirst of all it will extract the control files of the new package (the control.tar.gz)15:21
coolbhaviOK15:21
norsettoIt will then execute the prerm script of the old package15:21
norsettoAfter which it will run the preinst script from the new package15:21
norsettoAgain, preinst is a maintainer script15:22
norsettoAfterwards, it will remove the old files and unpack the new files15:22
norsettoIt will then execute the postrm script of the old package15:22
norsettoThen it will unpack the configuration files15:22
norsettoAnd finally run the new postinst script15:22
norsettoAnd finally the last maintainer script :-)15:22
norsettoYou don't need to memorise all these steps, a man dpkg will refresh your memory when you need it15:23
norsettoAs the name indicates, prerm is roughly called before a removal, postinst, after an installation and so on15:23
DabianIf dpkg is corrupted .. I couldn't use apt-get, right?15:23
norsettoAll clear so far? If so, lets see what these scripts in general are used for15:24
norsettoDabian: absolutely15:24
norsettoAs a general rule of thumb, many preinst stop services for packages which are being upgraded15:24
norsettoMany postinst start or restart services once a new package has been installed or upgraded15:24
norsettoSometime you may use postinst to finish a configuration, asking as well user input. This should preferably be done via debconf15:25
norsettoWe won't cover debconf in this lecture, but you should read about it; very good info can be found here: http://www.fifi.org/doc/debconf-doc/tutorial.html15:25
norsettoprerm are typically used to stop services for a package before removing the package15:26
norsettopostrm typically modifies links or other files associated with the package, and/or removes files created by the package15:26
norsettoWhen you want/need to add a maintainer script in your package, as for every packaging file you add it in the debian directory15:27
DRebellionnorsetto, unfortunately, I have to leave.15:27
norsettoFor instance the prerm script for the binary <foo> will be called <foo>.prerm and so on, if there is only one binary package you may omit the <foo>15:27
norsettoDRebellion: ok, it was good to have you here, even if for short15:27
DRebellion;)15:27
coolbhavinorsetto, me too15:27
geseranother good link to see how maintainer scripts interact is http://women.debian.org/wiki/English/MaintainerScripts15:28
DRebellionI will read the logs later.15:28
norsettogeser: yes, we will come to that later :-)15:28
norsettoAll these will be installed in the binary package by dpkg-deb15:28
norsettoOK, before we cover those in detail, lets see what are the configuration files. Anyone has any idea?15:28
DabianUhm15:29
Xk2ceverything in /etc15:29
DabianWhich configuration files?15:29
DabianOh .. the ones that purge removes15:29
norsettoDabian: those I was talking about before, when I mentioned purging for instance15:29
DabianRight15:29
norsettoConfiguration files are all files which affects the operation of a program, or provides site- or host-specific information, or otherwise customises the behaviour of a program15:30
DabianWell, those are the ones that tells the programs in the package how to adapt to the current system, and how to work.15:30
norsettoSome examples which should be in your system are:15:30
norsettoDabian: exactly15:30
norsetto/etc/apt/sources.list15:30
norsettoyou all know about that15:30
norsetto/etc/X11/xorg.conf (this tends to disappear but I still want it!)15:30
norsetto/etc/network/interfaces15:31
norsettoNow, the policy dictates that any configuration files created or used by your package must reside in /etc15:31
norsettowhich is the case for all these examples15:31
norsettoFor any installed <package>, you will find a list of its configuration files in /var/lib/dpkg/info/<package>.conffiles15:31
norsettoFor instance:15:32
norsetto/var/lib/dpkg/info/x11-common.conffiles15:32
huatsyou say "now" it was not the case with previous policy (before 3.8.0) ?15:32
norsetto/var/lib/dpkg/info/udev.conffiles15:32
Dabianahhh15:32
norsettoNo, I meant it as an interlocution ;-)15:32
huatsok :)15:32
DabianHence the ","15:33
Dabianhuats: However, I think debconf is /kinda/ new ... (I don't think it was there pre debian 2.0)15:33
norsettoDabian: yes, sorry if it wasn't clear. You may want to check those, they are all readable15:33
norsettoconffiles are special, by default they are not removed on removal or overwritten on upgrade!15:34
DabianIts very clear .. I already know the .list files .. but I guess they don't show the conf files :)15:34
norsettoDabian: they do actually, but not those which are created DURING the installation process15:35
DabianRight15:35
norsettoVery good, lets see now what are the control files15:35
norsettoControl files are all the files in a debian package necessary for its installation and configuration15:35
norsettoSome examples of control files which you may see:15:36
norsettoconffiles (a list of all configuration files)15:36
norsettowe have seen this already15:36
norsettoconfig (debconf config script)15:36
norsettotemplates (debconf templates)15:36
norsettomd5sums (md5sums for all files to be installed)15:36
norsettoshlibs (contain the mapping from shared libraries to the necessary dependency information)15:36
norsettotriggers (triggers list)15:37
norsettocontrol (binary control file)15:37
norsettoBe carefull about control file (singular) and control files (plural)15:37
norsettoand then all the maintainer scripts: postinst, postrm, preinst, prerm15:37
norsettoAll these are in control.tar.gz, which we have seen before15:37
norsettoThey are all unpacked in /var/lib/dpkg/info/15:38
norsettoThere, you will also find a <package>.list file, which will lists ALL files belonging to <package>15:38
norsettostrictly speaking <package>.list is not a control file though :-)15:38
DabianExcluding those that are created during install :)15:39
norsettoYou can check it out now if you want15:39
norsettoWe have a nice utility that can be used to work with control files: dpkg-deb15:40
norsettoAlso dpkg can be used since it can also act as a front end to dpkg-deb15:40
norsettowith dpkg-deb you can:15:40
norsettoprint a summary of the content of a package as well as its control file15:40
norsettoprint the content of control files15:40
norsettoprint control file information: this is the binary control file15:40
norsettoLets see some examples:15:41
norsettodpkg-deb -e <package> : Extracts the control information files into a subdir of the current dir named DEBIAN15:41
norsettodpkg-deb -I <package> : Print a summary of the content as well as the control file15:41
norsettodpkg-deb -I <package> <control file>: Print content of one of the <control file>s15:41
norsettodpkg-deb -f <package> : Print control file information15:42
norsettoIf you have not yet downloaded the deb, now is the time to do it15:42
norsettoEverybody has it?15:42
NielsEyes15:42
huatsyep15:42
MikeMcyes15:42
Dabian-e doesn't list anything?15:43
norsettoGood, now lets check some of these commands on the ucf package:15:43
DabianFor the example package, that is.15:43
norsettoLets start with dpkg -e :-)15:43
Dabianok :)15:43
norsettodpkg -e ucf_3.005_all.deb15:43
norsettoNow you should have a DEBIAN subdirectory. Can you check what is in there?15:43
Xk2cnorsetto: dpkg -e or dpkg-deb -e ?15:43
NielsEDabian: -e creaes a directory15:43
Dabianoh15:43
norsettoXk2c: the same15:43
Xk2cic15:43
Dabianconffiles  control  md5sums  postinst  postrm  preinst  templates15:44
norsettoDEBIAN is nothing less nothing more than control.tar.gz again :-)15:44
norsettoLets check the content of the control file15:44
norsettoThat would be DEBIAN/control15:44
DabianNielsE: Thank you .. I just reread norsettos explanation. :)15:45
norsettodo you see what is in there?15:45
norsettoAs you can see its a mixed bag of things from debian/control and more15:45
Xk2cnorsetto: that looks liek the output of aptitude show $PACKAGE15:45
norsettoXk2c: indeed, thats where aptitude fetch that info15:45
Xk2cic15:45
norsettoMore info about the control file can be found in the deb-control man page (part of the dpkg-dev package)15:46
norsettoNow, lets see another example:15:46
norsettodpkg-deb -I ucf_3.005_all.deb15:46
norsettoYou will see the control file + a summary of all the control files, with some info about them, like size, number of lines, and if it is an executable what kind of executable it is15:47
norsettoLets see a final example, how can we see what are the configuration files of ucf?15:47
Xk2ccat ucf.conffiles15:48
Xk2c:)15:48
norsettoXk2c: well, yes, you can use dpkg(-deb) -e, but also dpkg -I15:48
DabianThere is a file named conffiles15:48
Dabianotherwise I guess you can do this:15:48
ranfdpkg-deb -I ucf_3.005_all.deb conffiles15:49
Dabiandpkg-deb <package> conffile15:49
norsettoranf: yes15:49
Dabianoh .. I forgot -I15:49
Xk2ccool15:49
norsettoOK, we are finally coming to the crunch of the lecture.15:49
Xk2c:( sad15:49
norsettoPlease let me know if there is anything unclear before we proceed15:50
MikeMcare conffiles always necessary?15:50
norsettoMikeMc: no, it depends on the package15:50
norsettoMikeMc: as you can see for ucf there is only one15:51
MikeMcthanks15:51
norsettoAs we have seen, maintainer scripts are part of a package which the package management system will run for you when your package is installed, upgraded or removed.15:51
norsettoThey are normally shell (/bin/sh) scripts but they can also be other shebang scripts15:51
norsettoIts normally better to use /bin/sh, otherwise you have to depends on bash/perl/python,etc.15:52
norsettoAlso, POSIX shell or Bash are preferred to Perl/Python etc. since they enable debhelper to easily add bits to the scripts15:52
norsettoOn Ubuntu (and now Debian) /bin/sh points to dash, so be careful, if you use bashisms, it will fail ...15:52
norsettoLets check the postrm for ucf, how can we do that?15:53
NielsEcat postrm15:53
norsettoNielsE: :-) and without exctracting it?15:53
Dabiandpkg-deb -I <packagename> postrm15:54
huatsdpkg-deb  -I ucf_3.005_all.deb postrm15:54
Dabian?15:54
norsettoindeed15:54
Xk2cdpkg-deb -I ucf_3.005_all.deb postrm15:54
DabianNeat :)15:54
norsettoAs you can see, its a pretty complex (or apparently so) script. Some general remarks:15:55
norsettoThe policy requires that maintainer scripts must be idempotent, this means that you need to make sure nothing bad will happen if the script is called twice where it would usually be called once15:55
norsettoStandard input and output may be redirected (e.g. into pipes) for logging purposes, so don't rely on them being a tty15:55
sistpoty|workerm, just to clear up: you can use anything that has essential=yes set in maintainer scripts (and *don't need a depends*). Anything else is not always safe to use (e.g. a preinst won't have dependencies installed)15:56
Dabianidempotent .. thats a hard word. :)15:56
DabianOr I guess, just unfamiliar, really.15:56
Dabianto me. :)15:56
norsettosistpoty|work: yes, I will come to an example about that later on15:56
sistpoty|work:)15:56
norsettoAll prompting or interactive configuration should be kept to a minimum. When it is necessary, you should use the debconf package for the interface. Remember that prompting in any case can only be in the configure stage of the postinst script15:57
Dabiansistpoty|work: That was greek to me.15:57
norsettoKeep the maintainer scripts as simple as possible, and don't assume that $PATH will allow you to use all commands (so use absolute and complete paths)15:57
sistpoty|workDabian: norsetto will come to it laters ;)15:57
DabianOK, thought so :)15:57
norsettoNow to the script, note the set -e at the top: this will make the script abort if any command returns an error value15:58
norsettoVery important, we don't want to continue if there is any error, and possibly cripple the user's machine15:58
norsettoBut as important as well, we don't want to leave uninstalled/unconfigured stuff which may cripple the user's package management system!15:58
norsettoAs we will see, there are ways to recover errors, but the most important way is to CHECK beforehand for things that can go wrong and abort GRACEFULLY if possible.15:59
norsettoYou can use the usual test constructs, for example:15:59
norsettoif [ <test> ]; then15:59
norsettoprint >&2 "Error. Please fix me."15:59
norsettoexit 0;15:59
norsettofi15:59
norsettoNote that I use exit 0, so I let dpkg finish its job and at the same time I alert the user that something "strange" happened16:00
norsettoLets download another example:16:00
norsettowget http://archive.ubuntu.com/ubuntu/pool/universe/t/trousers/trousers_0.3.1-4_amd64.deb16:00
* norsetto loves that package :-S16:01
norsettoNow lets check the postinst script16:01
norsettoeverybody has it?16:02
NielsEyes16:02
MikeMcyep16:02
norsettoNow, lets for a moment forget the first part of the script, we will see later what all these actions are16:02
norsettoIn the second part, after the comment # Automatically added by dh_installinit you will see that it will call another script, which, in effect IS a maintainer script even though it will not be part of the control files16:02
norsettoIn this particular case, its a configuration file, which makes it tricky since it might be difficult to remove it if it fails16:02
norsettoThis is an init script, ie. a script used to launch a daemon at boot-up or stop it at shutdown16:03
norsettoIt is standard practice to use this script as well to launch or stop the daemon during package upgrade/removal16:03
norsettoNow, lets check this init script. How could we do it?16:03
MikeMctry each line manually?16:04
norsettoMikeMc: sure, but I mean, how to see what is inside first ;-)16:04
norsettoAnyone?16:04
Dabiantrying to catch up16:05
tarviddpkg-deb -I trousers_0.3.1-4_amd64.deb postinst|less16:05
norsettotarvid: that won't show the init script though, remember, its not a control file16:05
MikeMcdone it thought you meant something else16:05
norsettoMikeMc: yes, my Englitalian its a bit funny ;-)16:06
Xk2cnorsetto: $ dpkg -x trousers_0.3.1-4_amd64.deb16:06
DabianOh16:06
norsettoXk2c: yes, that a good one16:06
norsettoAnd you will find it as etc/init.d/trousers16:06
Xk2cvim etc/init.d/trousers16:07
norsettodoes everybody see what is the content of this file?16:07
MikeMcyes16:07
Xk2cyep16:07
norsettoAs you can see this script does something very nice, before starting the daemon it checks if something which is necessary for the daemon to be successfull is there16:08
norsettoDo you see the test lines?16:08
norsettoIf it isn't, it doesn't bail off, and hell breaks loose, it will print an error message and exit gracefully16:08
norsettoSo, the user is informed and his system is not screwed up16:08
DabianIt checks if the binary exists and is excuteable by the current user?16:08
norsettoDabian: yes, but the check I mean is about about the existance of the dev file, which means the tpm module is loaded into memory16:09
Dabiandarn ... I think I have to run ... can I idle here ?16:09
norsettoDabian: sure16:09
Xk2cDabian: lines 26 to 3116:10
DabianThanks for the lesson so far norsetto .. its been very enlightning :)16:10
norsettoDabian: thx to you, I'm very glad you find it usefull16:10
norsettoLook also at the stop action16:10
norsettoThe daemon is stopped with the --oknodo option, this makes return exit status 0 instead of 1 in case of errors16:11
norsettoCould we improve on that? For instance, catch obvious problems before they happen?16:11
Xk2cnorsetto: if the daemon ist running is checked already?16:13
Xk2cwith the "--pidfile /var/run/$NAME.pid " ?16:13
norsettoyes, but what again if /dev/tpm doesn't exist?16:13
norsettoEven better (and the package has later been patched like this) would be to have the same check that we have for the start action16:13
norsettois everything clear?16:14
MikeMcyes16:15
NielsEyes16:15
norsettoOK, back to ucf, lets check again the postrm16:15
norsettoAs you can see there are a number of actions in there16:15
norsettoAll the possible actions are (hope I don't forget any):16:16
norsettoconfigure, abort-deconfigure, deconfigure-in-favour, install, abort-install, upgrade, abort-upgrade, failed-upgrade, remove, abort-remove, remove in-favour, purge, disappear16:16
norsettoah, the beauty of cut and paste :-)16:16
norsettoThese are all coming from dpkg16:16
Xk2c_sorry network problems16:16
=== e-jat is now known as groups
=== groups is now known as e-jat
norsettoFor the benefit of Xk2c_16:17
=== e-jat is now known as fenris-
norsettoconfigure, abort-deconfigure, deconfigure-in-favour, install, abort-install, upgrade, abort-upgrade, failed-upgrade, remove, abort-remove, remove in-favour, purge, disappear16:17
norsettothese are all the actions that dpkg can use when calling a maintainer script16:18
norsettoSome of these are pretty obscure and it is likely that you will never need to use them16:18
norsettoAs you can see, the maintainer for ucf used some template (I guess coming from an old version of dh-make) where all the possible actions for a postrm script are already there, with comments which explain what they do16:18
norsettoAll clear? Don't try to memorise all these!16:18
norsettoYou have to know that when dpkg calls the maintainer scripts, its calls are of the type: script action [package|version]16:19
norsettoEach action will depend on what dpkg is trying to do16:19
norsettoIs it trying to remove the package?16:19
norsettoIs it trying to purge the package?16:19
norsettoIs it trying to recover from a failed remove?16:19
norsettoWhat dpkg will do depends on the request from the user and the status of the system16:20
norsettoFor instance for postrm, dpkg could call it as follows:16:20
norsetto<postrm> remove: dpkg will call this after a removal16:20
norsetto<postrm> purge: dpkg will call this after a purge16:20
norsetto<old-postrm> upgrade <new-version>: dpkg will call this after removing an old package during an upgrade16:21
norsettoand an important one16:21
norsetto<new-postrm> failed-upgrade <old-version>: dpkg will call this if the postrm of the old package during upgrade failed16:21
norsettoThe other cases are really very special or corner cases and we will skip them for this lecture16:21
norsettoNow, lets see an example for an upgrade16:21
norsettoThere are some nice diagrams that could help you to visualise this in http://women.debian.org/wiki/English/MaintainerScripts16:22
norsettogeser already pointed these out to you16:22
norsettoCan you see the upgrade diagram in this page?16:22
MikeMcyep16:23
NielsEyes16:23
norsettoThe nominal steps are as we explained briefly above (prerm->preinst->postrm->postinst), but if something goes wrong things get hairy, for instance:16:23
norsettoFirst dpkg will call prerm-from-old-package upgrade new-version16:24
norsettoIf the script runs but exits with a non-zero exit status, dpkg will attempt:16:24
norsettoprerm-from-new-package failed-upgrade old-version16:24
norsettoDo you see this in the diagram?16:24
MikeMcyes16:24
norsettoIf this works, the upgrade continues. If this does not work, it will continue with:16:24
norsettopostinst-from-old-package abort-upgrade new-version16:25
norsettoIf this works, then the old-version is "Installed", if not, the old version is in a "Failed-Config" state.16:25
norsettoupgrade is really a complex example, but I wanted to show you what attempts dpkg will do in case something goes wrong16:25
norsettoyou can make a clever use of these in your maintainer scripts, to ensure that dpkg will eventually be able ti install, or eventually to remove faulty packages16:26
norsettoAnother example, configuration:16:26
norsettopostinst configure most-recently-configured-version16:27
norsettoThat's it, no attempt is made to recover errors! If the configuration fails, the package is in a "Failed Config" state, and an error message is generated, so, be careful with that16:27
norsettoYou can find these and all other possible dpkg calls in the debian policy, chapter 616:27
norsettowell, that was the hard bit, I hope your brain is not confused as mine :-)16:27
* norsetto tries unsuccesfully to wake up huats16:28
norsettoUsually one will not manually write these scripts, debhelper scripts will do that for us16:28
huatsnorsetto: (phone call...)16:28
norsettoFor instance if our package installs icons and we want to update the Freedesktop icon caches, you will just add a dh_icons call in debian/rules, this will create appropriate maintainers scripts that will call update-icon-caches16:28
norsettoIf you have several debhelper scriplets, all the fragments from each will be collated in a single maintainer script16:29
norsettoIf you need to have a mixed script, ie. a part manually written and another generated by debhelper, you can use the #DEBHELPER# token16:29
norsettoDuring build, the token will be replaced by whatever "functions" debhelper needs to generate16:29
norsettoYou have seen and example of this for trousers16:29
norsettoIn that case there was a fragment that was inserted in the postinst by dh_installinit16:30
norsettoYou can check it by looking at trousers.postinst in the debian dir of the trousers source package16:30
norsettoEven though you will rarely need to write maintainer scripts manually, it is VERY IMPORTANT to be able to debug failures coming from maintainer scripts16:30
norsettoThis is because these may cause packages to be left in an non-desirable state and possibly screw up the whole package management16:30
norsettoYou will see many bugs of this kind in the LP bug tracker16:31
norsettoIt is also important to check an init script provided by upstream before installing it16:31
norsettoSince it will be a maintainer script we need to make sure that it doesn't fail, and if it does so, it does it gracefully16:31
norsettoIf an init script fails, it may fail one of the maintainer scripts and leave a user's system in a mess16:32
norsettoOn top of that, it is a conffile, so, not removed on upgrade16:32
norsettoAnybody know how we could solve such a situation?16:32
norsettoAnybody has ever seen or used dh_installinit?16:33
huatsnever user16:34
huatsused16:34
Xk2c_no16:34
MikeMcno sounds intersting...16:34
norsettoWe have seen this for trousers, dh_installinit is the debhelper scriplet that installs init scripts into package build directories16:34
norsettodh_installinit also automatically generates the postinst, postrm and prerm commands needed to set up the symlinks in /etc/rc*.d/ and to start and stop the init scripts16:34
norsettothere is a nice option that this debhelper function provides16:35
norsettoYou can override the failure action by using the option --error-handler=function when calling dh_installinit in debian/rules16:35
norsettoIn this case, the named shell function will be run if the init script fails16:35
norsettoThis function should be provided in the prerm and postinst scripts, before the #DEBHELPER# token16:35
norsettoThis will simply modify the snippets inserted by dh_installinit with something like "/etc/init.d/init_script action || function" instead of "/etc/init.d/init_script action || exit $?"16:35
norsettoso if "init_script action" fails it will execute funtion instead of exiting with an error <> 0 and failing the maintainer script16:36
norsettoFor instance a simple --error-handler=true will just make the removal continue if the initscript fails stopping the daemon and you have16:37
norsettoa new version to install that fix that very bug! Without this, you will have to ask the user to manually modify the init script himself16:37
norsettoAnother thing to be careful is that you cannot assume in your maintainer scripts that conffiles from another package are available16:38
norsettoFurthermore, you should not assume that a conffile being present means that some functionality are available, remember that conffiles are only removed on purge16:38
norsettoI have an example to show you this16:38
norsettoI stumbled against a problem of the first kind in a recent bug (bug 248150), which I hope I won't have to fix (hint to any member of motu-sru which might be around :-))16:38
ubottuLaunchpad bug 248150 in fcalendar "package r-cran-fcalendar 220.10063-1 failed to install/upgrade: " [Undecided,Confirmed] https://launchpad.net/bugs/24815016:39
norsettothis is showing an example of sistpoty|work words of wisdom16:39
sistpoty|work<- isn't anywhere wise :P16:39
huats:)16:40
norsettothere is a very nice explanation by supermaster steve langasek in the debian bug which should enligthen you (it did it for me ;-))16:40
norsettodo you see what the problem is ?16:42
NielsEI think I globally understand it16:43
MikeMcsymlink?16:44
norsettoto tell you in a (hopefull) nutshell, the postrm of the old packages was calling a binary which relied on a conffile being present16:44
norsettoproblem is, that that conffile was moved from one location to another, and a symlink installed to point to the new location16:45
norsettonow, when the package is upgraded, if the new package providing the binary is not yet installed, everything goes fine16:46
norsettohowever, if the new package is installed, since it will not yet be configured, the symlink will be left dangling, and that binary will fail16:47
norsettoand fail 40+ other packages with it ...16:47
norsettoDon't be worried if you don't get it immediately, its not that simple :-)16:48
norsettothat was just to show you what kind of considerations one would have to make when doing maintainer scripts and what pain they can cause to debug16:49
norsettoShall we do another simpler example?16:49
MikeMcyes16:49
NielsEyes16:49
huatsnorsetto: if you have one16:50
huats:)16:50
norsettoLets see another example, bug 25008816:50
ubottuLaunchpad bug 250088 in psad "can't remove psad package" [Undecided,Fix released] https://launchpad.net/bugs/25008816:50
norsettohuats: I have plenty ;-)16:50
huatsI have doubts on the "simple" :)16:50
norsettoto understand this, download psad (the buggy version) and check what the prerm script does16:51
norsettowget http://archive.ubuntu.com/ubuntu/pool/universe/p/psad/psad_2.1-1_amd64.deb16:53
norsettodpkg -I psad_2.1-1_amd64.deb prerm16:54
norsettodo you see where it fails?16:54
huatsthe line find /var/run/psad/ -type f -exec rm -f {} \;16:54
norsettoyes, do you see why it fails?16:55
huatsshould test first the existence of /var/run/psad16:55
norsettoindeed, lets not forget that in ubuntu /var/run is mounted as tmpfs16:55
huatssince if it does not exists, find will raise an error16:55
norsettoindeed, and fail the removal, leaving the user machine in a mess (recoverable, but still a mess)16:56
huatssure16:56
NielsEyes16:56
norsettoin this particular case I also believe that this will need to be done in the preinst and/or postinst (creating /var/run/psad if not existing)16:58
huatsok16:58
norsettoanother example?16:59
MikeMcok16:59
huatsgo ahead16:59
huats:)16:59
norsettook, lats one since its about two hours now :-)17:00
norsettobug 25169617:00
ubottuLaunchpad bug 251696 in pygopherd "package pygopherd 2.0.17 failed to install/upgrade: subprocess post-installation script returned error exit status 1 (dup-of: 238755)" [Undecided,Incomplete] https://launchpad.net/bugs/25169617:00
ubottuLaunchpad bug 238755 in shadow "'Account has expired' message when adding a new user" [Undecided,Confirmed] https://launchpad.net/bugs/23875517:00
norsettoI think pleia2 has recorded everything, so the logs will be available?17:02
norsettodo you see whats happening with this?17:03
huatsthe pb here seems that the postinst tests if /var/gopher exists17:03
huatsand then copy in /var/gopher/gophermap17:03
huatsno ?17:03
norsettohmmm, no :-)17:03
pleia2james_w typically posts logs following a session, we'll reply to the list with their location17:03
norsettopleia2: okki, thanks17:03
MikeMc 'passwd -l' is broken?17:04
norsettothere are two problems actually, but one is not lethal (even though is silly)17:04
NielsEpleia2: the message goes to the motu-list?17:05
norsettoMikeMc: well, you could say that, other people may also disagree, but the issue is definetively in the chsh call17:05
norsettoyou can all see that in the script17:05
huatswhen he grep the passd file17:06
huatshe search for the HOMEDIR17:06
huatsbut he do not take into accoutn the result of HOMEDIREXISTS17:06
norsettohuats: he is using that, later on17:07
Xk2c_Your account has expired; please contact your system administrator17:07
Xk2c_from the original bug17:08
norsettoyes17:08
norsettojust immediately after resuming normal error checking17:08
norsettohe is calling "chsh -s /bin/sh gopher"17:08
james_wNielsE: yes, it will.17:08
norsettothat will fail if your account is locked, and fail everything else17:08
Xk2c_yeah passwd -l is broken :(17:09
norsetto:-)17:09
norsettosomebody call that a feature ;-)17:09
Xk2c_norsetto: if used at the right place17:10
Xk2c_but an expired rootaccount causes headages17:10
norsettoWell, I really hope you enjoyed the lecture and I could help to shed some light on maintainer scripts and dpkg, any questions ?17:11
norsettoAnybody still alive?17:12
NielsEthanks for taking the time, you did a perfect job, no questions for me atm17:12
Xk2c_norsetto: thank you17:12
MikeMcthanks, when is the next one?17:12
huatsthanks a lot cesare17:13
norsettoMikeMc: thats for james_w to answer? I know he is working on solving the misteries surrounding kde packaging17:13
james_wthanks norsetto17:14
james_wI don't have another session lined up right now, but I hope to have one in two weeks time.17:14
norsettothanks to everybody that partecipated, was a real pleasure to talk with you all17:15
james_wwiki.ubutntu.com/MOTU/School/Requests if you would like to request a session, or offer to present one.17:15
james_wthanks again norsetto, it was a great session. I'll post the logs a little later.17:15
james_wany help create documentation out of the logs would be appreciated.17:16
NielsEwiki.ubuntu.com/MOTU/School/Request does not exist...17:16
NielsEoh wait17:16
NielsEnvm :)17:17
Xk2c_bye17:26
NielsEbye17:28
prashant321whats going on in the session18:34
e-jathi19:05
=== Kopfgeldjaeger2 is now known as Kopfgeldjaeger
wordare there any logs from the session earlier today?22:11
pleia2word: https://wiki.ubuntu.com/MOTU/School/MaintainerScripts22:11
wordthanks :)22:11

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!