SliTaz SliTaz Forum

You are not logged in.

#1 2011-05-03 21:27:03

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Package management and orphaned packages

Good evening out there,

I posted this is the vanilla forum some time ago but didn't get any response (maybe the idea was too bad but then again somebody would have at least laughed at me or said nasty things about my stupidity...), that's why I start a second turn here:

When I tried to scale down my Slitaz in order to have a real sneaky small version of a frugal-type installation (I use a ~40MB initrd.gz to do a 15 sec boot from HD, unzip the newest downloadable firefox while logging in and use squashfs to include the bigger-type of applications I need, e.g. OpenOffice or java) I found it hard to uninstall packages I thought of not needing.

After several times of breaking XOrg, producing kernel panics or similar, I tried to figure out an old Debian buddy by myself: deborphan-like. Since Slitaz is wonderfully built on quite some impressing shellscript, I was able to at least code some lines that do the basic trick for me (saved as tazorphan in my /sbin directory):

[c]#----------------------------------------------
#! /bin/ash

# necessary for 'tazpkg rdepends' command
tazpkg list > /var/lib/tazpkg/packages.txt

# list of installed packages for testing each one
ls /var/lib/tazpkg/installed > /tmp/installed.txt

# name of the first package in the list (to start with)
AKT=$(head -n 1 /tmp/installed.txt)

# name of the last package in the list
LAST=$(tail -n 1 /tmp/installed.txt)

# Init the line to read out of package list
Zeile=1

# loop through the package list till last package
until [ "$AKT" = "$LAST" ]
do
  # increment line = package name to read
  Zeile=$((Zeile+1))

  # add a 'p' to the line (e.g. 15p) as sed parameter
  Parameter="${Zeile}p"

  # read the name of the actual package to test
  AKT=$(sed -ne $Parameter /tmp/installed.txt)

  # use tazpkg rdepends to test whether there are any dependencies
  DEPs=$(tazpkg rdepends $AKT)

  # if none are reported back
  if [ "$DEPs" = '' ]
   then
     # echo the name of the package
     echo $AKT
  fi

# and continue the loop
done

# remove the package list out of /tmp
rm /tmp/installed.txt

#---------------------------------------------------[/c]
So at least als packages that no other package depends upon is printed out. By that it's easier to find the last bits of flesh that can be drawn from the bones.

I have an additional suggestion concerning package management anyway:

By adding an extra "flag" in the installed-packages list e.g. like this:

linux           s (system-essential)

epdfview        c (chosen)

poppler         d (dependency)

it would - after deliberate removal of a formerly chosen package - be easy to automatically remove packages that have been installed for dependency reasons recursively (the dependency would be orphaned since no package depends on it anymore and since it was not chosen but installed as "d" could be removed.)

For the time being this would not be a very fast (due to recursive action) but reliable option to have a slim an trimmed system.

Looking forward to some reactions.....   ;-)

Offline

#2 2011-05-29 21:26:39

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

Ok, ok, you've been totally right on rejecting this clumsy shellcode (I knew no better way but read some of the docs now...)

Here's a new suggestion with the same results for the time being:

-------------------------------

[c]#!/bin/ash

tazpkg list > /var/lib/tazpkg/packages.txt

for Prog in 'ls /var/lib/tazpkg/installed'
do
  if [ -z "'tazpkg rdepends ${Prog}'" ]; then
   echo ${Prog}
  fi
done
exit 0[/c]
-----------------------

(pls note that ' have to be backticks which are not accepted by the forum interface)

As a file with a .txt extension in the attachment (for those fearing typos...  ;-)  )

I still wonder, if for example two textfiles, containing a) the list of absolutely necessary system packages and b) the list of those chosen by the user would not lead to a system that could be kept cleaner.

Idea is: on uninstallation (tazpkg remove) of a package the tazorphan (or similar) script is run, the results of this script is compared to a) system list and b) chosen list, which will result in a list of files not chosen by the user, not fulfilling any dependencies and not necessary for the system to run.

Meaning: safe to be uninstalled and to further lean the system.

Nobody with any comment out there ?!?

Offline

#3 2011-05-30 11:42:37

totoetsasoeur
Moderator
Registered: 2011-03-29
Posts: 247

Re: Package management and orphaned packages

Hi Filou,

It looks like a really relevant point.

I might be wrong (I haven't checked), but when looking at "tazpkg remove" manual found here: http://hg.slitaz.org/tazpkg/raw-file/tip/doc/tazpkg.en.html:

"...This command will delete all files installed with the package..."

So, to me, your concept is already available through "tazpkg remove". But, as stated before, I haven't checked if this is really the case.

Anyway it would be nice to have dev guys opinion on this. It might worth it asking this on mailing list.

Cheers.

Offline

#4 2011-05-30 12:14:47

pankso
Administrator
Registered: 2026-06-27
Posts: 341
Website

Re: Package management and orphaned packages

Hi,

I confirm 'tazpkg remove' will remove any files that are no more with the package (when upgrade from upstream we have often some changes). If you use 'tazpkg list-files pkg' it will list you the installed files, this list is keeped in /var/lib/tazpkg/installed/pkg/files.list. When tazpkg upgrade a pkg it make a diff between preview installed files and the new one and so remove old files.

But having orphanned packages is a bit different, it may appends if for exmaple you install qemu it will install libsdl, but when you remove qemu it will not remove libsdl because it may be used by and other package but maybe not and so is orphanned and could be removed.

Filou, you script is a great idea and feet SliTaz philosophy to keep a clean filesystem. I have a bunch of work to do right now but will include your work as soon as possible.

Offline

#5 2011-05-30 21:06:01

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

Happy that it finds some appreciation.

Since you will be busy keeping this lovely distribution neat and running I thought of patching tazpkg script at some points to make a suggestion. So if you're happy to wait a couple of days I'll try to work the steps out.

I had some more thoughts about it and the fastest way might be

1.) Creating a file containing the names of system relevant packages (I thought to have a look at base or justx flavour), one in a line

2.) patching tazpkg script so that each time tazpkg install [PKG] is successfully run, [PKG] is added to a file containing the chosen packages, one in a line.

3.) if starting from a flavour already containing some more, it might be necessary to add the chosen packages by hand.

4.) patching tazpkg script some more so if tazpkg remove [PKG] is run, the following steps are performed:

  a) [PKG] is removed from chosen list (using sed for example)

  b) for Package in 'ls -1 /var/lib/tazpkg/installed':

        - check if in system packages list

        - if not, then check if in chosen packages list

        - if not, then check 'tazpkg rdepends'

        - if empty, then remove package and start over.

Like this, the system should be clean afterwards...  (unless I forgot something or am simply wrong...)

Offline

#6 2011-05-31 19:01:40

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

[HELP, forum is NOT accepting my 75,5k upload of tazpkg.txt, any other possibilities to share it? PM?!?]

... so here we go with the first suggested solution...

I fiddled around with tazpkg (ver 3.4 since I'm using Slitaz 3.0) adding some code that does the trick.

1) See the diff of tazpkg 3.4 and the patched version by using diff -a (or reading the appended file)

2) replace /usr/bin/tazpkg with patched version (simply starting locally won't be enough since tazpkg calls itself recursively)

3) copy chosenpkg.lst and systempkg.lst to /var/lib/tazpkg; maybe adjust them to your needs

4) there you go...   "tazpkg unorphan" will invoke the spook and/or you will be asked to perform the task on uninstalling any package anyway...

Some background information:

- if you cancel the uninstall of a package, it will automatically be added to chosenpkg.lst (otherwise the recursive sweep for orphaned packages would be an endless loop), since you actively decided to keep this package. In doing so, the script won't remove any packages you don't want it to.

- if you have multiple instances of tazpkg running (one waiting for input/decision and the other one active) you won't be asked if orphane-sweep shall be done (since tazpkg calls itself recursively I had to check if the current process is the parent one, otherwise you'd be asked everytime a package is removed). But that shouldn't hurt too much 'cause nothing is lost and you may do your orphane-sweep later...

- since common use of variables in several instances of tazpkg is not possible I had to use some sort of external flag, which is /var/lib/tazpkg/.orph, which will be deleted before and after use. Worst case would be if you killed the process while running that you'd have some extra 20 bytes in a hidden file which will be deleted next time the orphane-sweep is run.

Suggestions, improvements, comments?!?

Offline

#7 2011-06-01 15:40:57

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

Had to correct two bugs:

1) I had been to lax with sed, resulting in deletion of multiple pkgnames in chosenpkg.lst

2) I forgot to implement tazpkg (get-)install-list.

the new diff file looks as follows...

@Pankso: I'll try to send you the update via your maintainers Mailaccount at slitaz.org, as the first version...

Offline

#8 2011-06-01 19:43:06

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

With the actual extended version of tazpkg it isn't necessary to copy the chosenpkg.lst anymore (while some standardized version of systempkg.lst should be provided in the package).

First time you start "tazpkg unorphan" you'll be asked if you want to uninstall ANY orphaned package anyway. If you don't want to (since you installed the package with intent), you say no and the package is added to the chosenpkg.lst (which will be created if nonexistent).

So there's (more or less because of the concept, not by intention) a semi-automatism for you to create your own chosenpkg.lst interactively. No editing of the file needed...   :-)

Offline

#9 2011-06-07 22:00:44

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

Seems I am somewhat alone again in this thread talkin to myself ?!?

Since performance of tazorphan and the modified tazpkg script wasn't very high due to quite time consuming "tazpkg rdepends" calls I figured out another way which sped up things quite well (the check on my system went down from 1 min 07 sec to 03 secs).

So here's my new tazorphan script (just copy to /sbin and delete the extension, perhaps chmodding) as well as the new diff of tazpkg against the Slitaz 3.0 version (I'll send the update to pankso as the last ones):

Offline

#10 2011-06-08 01:12:35

noobert
Member
Registered: 2011-05-22
Posts: 17

Re: Package management and orphaned packages

what is this? why are they orphans?

Offline

#11 2011-06-08 06:41:59

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

If you install a package, all dependencies are installed automatically.

On uninstalling the package, those dependencies are NOT automatically removed, since they might be needed by other packages as well.

Those dependencies, that are not needed anymore but are still installed are called "orphaned".

tazorphan presents a list of those packages, that no other pkg depends upon. That might be a pkg installed by intent or an orphaned pkg.

The tazpkg extension searches for orphans upon uninstallation of a pkg, checks against lists of system essential and chosen pkgs and offers to uninstall orphans, so all unneeded pkgs are removed and you have a clean and shiny system.

Offline

#12 2011-06-09 11:26:36

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

Another tiny bug removed; since grep is not as accurate as I'd like it to be, sed is the better choice in the unorphan routine.

Here are the latest patches for tazpkg 3.4 (stable) and 4.7 (cooking). I added systempkg.lst again to be complete.

I streamlined tazorphan some more, too and attach that script again as well...

Offline

#13 2011-06-14 14:40:22

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

New cooking version:

Offline

#14 2012-07-16 09:20:10

tsattler
Member
Registered: 2012-07-14
Posts: 1

Re: Package management and orphaned packages

I know this thread is old, but I cannot find any results. So, what's the "official way", to detect/remove orphaned packages? (I installed slitaz-4.0 and there's neither a 'tazorphan' binary nor anything about "orphan" in the tazpkg manpage.)

Offline

#15 2012-08-05 11:20:39

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

Hi tsattler

and thanx for the interest...

I updated my patch and sent it to pankso but my intentions weren't accepted yet. Maybe I was not clear enough about the description / usage.

You'll find the latest version of the patch attached, if you'd like to use it.

[Edit: I fail in uploading the patch even as .txt file  :-(  sorry for the moment]

What the extension does is (as you might comprehend looking at the script):

block 102- ):

extend the usage information

block 635- ):

upon installation of a package, add the name to /var/lib/chosenpkg.lst

block 765- ):

- collect dependency-information of all installed packages (out of "/var/lib/tazpkg/installed/[pkg]/receipt)

- check if the individual package is system-relevant (see below) or listed in chosenpkg.lst

- check if the individual package is listed in the dependency-collection from above

If the package is neither system-relevant nor deliberately chosen (> chosenpkg.lst) AND no package depends on it, then it is orphaned and is offered for removal. If you choose to remove it, the loop is broken and the check starts from the beginning, since other packages (with "lower" name) might be orphaned now, too.

If you deny removal, then you have deliberately chosen the package now and it is added to chosenpkg.lst.

----------------------------------------------

What is suboptimal up to now:

- As a starting point, you have to perform an initial unorphan run to create chosenpkg.lst; ideally, if the routine was used from the beginning of SliTaz setup, this would have already been created, since every deliberatley installed package would have been logged already.

- I don't have a clear picture of which packages really are system essential. Especially the "level of ambition" (using XOrg or not, choice of Window Manager / Desktop environment) does have an influence on this. On the other hand, this might not be grave as long as you know what you are doing (but who really does ?!?)

- Unorphan patch works (at least on my machines) like a charm using the command line but up to now fails in the "graphical way" using tazpanel due to lack of interactivity during the (de-)installation-process.

I'd highly appreciate a revival of this topic, because up to now I seem to be the only one using my patch...

Cheers,

Filou

Offline

#16 2012-08-06 10:47:45

totoetsasoeur
Moderator
Registered: 2011-03-29
Posts: 247

Re: Package management and orphaned packages

@ Filou,

I am not a Slitaz's developer at all, but I find your idea really interesting and promising.

Before going further, you should try posting/exposing your idea on the Slitaz mailing list. It is well followed by Slitaz's developers and I am pretty sure you will get a positive feedback.

Cheers.

Offline

#17 2012-08-15 12:53:22

Ben H
Member
Registered: 2012-08-15
Posts: 4

Re: Package management and orphaned packages

@ Filou,

I would like to try your patch too, will the old one still work? (for slitaz-4.0)

The issue for me is not knowing/checking what depends will be installed when installing a new package, can get untidy quickly.

Offline

#18 2012-08-24 09:20:53

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

@Ben H:

Yes, the patch should work, at least it does for me. The built-in patch command of busybox doesn't seem to work correctly however, so for the patch you should install patch.tazpkg (using tazpkg get-install patch), then patching with:

patch -N /usr/bin/tazpkg [patchfile]

If you have any further questions.... shoot  ;-)

Cheers...

Offline

#19 2013-07-10 21:48:40

VERAULT
Member
Registered: 2011-07-29
Posts: 119

Re: Package management and orphaned packages

So what is the command to run after installing the patch? Im a little confused about this, but I think its a great idea.

Offline

#20 2013-09-21 18:25:50

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

Sorry for answering this late, I thought nobody at all would use this...

you can invoke it by typing

> tazpkg unorphan

(as it should be listed when invoking tazpkg without parameters)

Cheers,

Nils

Offline

#21 2017-01-16 21:03:36

ray
Member
Registered: 2017-01-16
Posts: 21

Re: Package management and orphaned packages

Hi Filou

I find your idea to keep your system clean and shine interesting. Do you still use it? If so, could you please update your how-to and files?

Cheers from Ukraine)

Offline

#22 2017-08-28 19:01:45

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

Hi ray,

sorry, haven't been in the forum for quite some time although SliTaz is still my absoulte favourite.

I updated to a graphical (yad) version of tazorphan, but did not intend to keep up with patches for the quite fast update cycle of tazpkg, so this is standalone, meaning it doesn't keep track of your choices but simply offers those packages for uninstall that no other package depends upon.

So be careful to not just pick any package you are not sure about.

Cheers from Germany and best wishes to Ukraine

Offline

#23 2017-08-28 19:02:54

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

Upload seems not to have gone through:

=================================================

#!/bin/sh

mkdir -p /tmp/ORPHAN

echo > /tmp/ORPHAN/ORPHANS.txt

echo 1 > /tmp/ORPHAN/UNINSTALLED.txt

while [ [c]grep -c 1 /tmp/ORPHAN/UNINSTALLED.txt[/c] = "1" ]; do

echo > /tmp/ORPHAN/DEPENDENCIES.txt

CHOICE=""

DESCRIPTION=""

for VERZ in /var/lib/tazpkg/installed/*

  do

        . $VERZ/receipt

        for DEPENDENCY in $DEPENDS

         do

                echo "$DEPENDENCY" >> /tmp/ORPHAN/DEPENDENCIES.txt

         done

  done

for VERZ in /var/lib/tazpkg/installed/*

  do

        PACKAGE=$(basename $VERZ)

        if [ -z "[c]sed -n "s/^${PACKAGE}$/&/p" /tmp/ORPHAN/DEPENDENCIES.txt[/c]" ] && [ [c]grep -c $PACKAGE /tmp/ORPHAN/ORPHANS.txt[/c] = 0 ]; then

         CHOICE="$CHOICE FALSE|$PACKAGE|[c]tazpkg -d $PACKAGE | sed '1,3d;$d' | sed '$d'[/c]|"

         echo $PACKAGE >> /tmp/ORPHAN/ORPHANS.txt

        fi

  done

echo 0 > /tmp/ORPHAN/UNINSTALLED.txt

IFS="|"

echo $CHOICE > /tmp/ORPHAN/CHOICE.txt

yad  --list --fullscreen --text "Pick orphaned Packages to uninstall" --multiple --checklist  --column="Pick" --column="PACKAGE" --column "Description" ${CHOICE} --print-column=2 --separator=" " --button="Uninstall" --button="cancel" | while read PKG; do

  echo 1 > /tmp/ORPHAN/UNINSTALLED.txt

  echo y | tazpkg -r $PKG

done

done

rm -r /tmp/ORPHAN

Offline

#24 2017-08-28 19:04:08

Filou
Moderator
Registered: 2011-05-03
Posts: 256

Re: Package management and orphaned packages

Maybe as .txt ?!

Offline

#25 2017-08-29 11:28:07

ray
Member
Registered: 2017-01-16
Posts: 21

Re: Package management and orphaned packages

Hi Filou,

Thanks for you reply! I created script file "tazorphan.sh" and changed the first line to "#!/bin/sh -x" for tracing.

Here is output in terminal:

root@lx:~/Downloads# ./tazorphan.sh

+ mkdir -p /tmp/ORPHAN

+ echo

+ echo 1

+ [ grep -c 1 /tmp/ORPHAN/UNINSTALLED.txt = 1 ]

sh: -c: unknown operand

It seems something wrong with grep in script line:

while [ grep -c 1 /tmp/ORPHAN/UNINSTALLED.txt = "1" ]

Any ideas?

Also, would you mind to communicate via online messenger?

If so, please let me know your preferable app to my email: vray731 at gmail.com

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.019 seconds, 7 queries executed - Memory usage: 1.6 MiB (Peak: 1.77 MiB) ]