WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: A script to check dependencies  (Read 15722 times)

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: A script to check dependencies
« Reply #30 on: January 08, 2017, 01:27:46 AM »
Hi coreplayer2
That's what the  [Select]  to the right of where it says  Code:  is for. Click the  [Select]  and it highlights what's inside the
code tags. Then just  Ctrl-C  to copy it to the clipboard.
Thanks,  we learn something new every day :)

Offline polikuo

  • Hero Member
  • *****
  • Posts: 715
Re: A script to check dependencies
« Reply #31 on: January 08, 2017, 01:58:06 AM »
The more I look at this, the more I'm convinced the default arguments if none given should be -cdn
Actually, that's how my script look like at the very beginning, but bmarkus pointed out that
Using > formatting color codes are saved too.
It is better to make it by default and use a -c option to create a colored list if someone need it.
That's why the -c option is no longer one of the default arguments.  :P

Code: [Select]
/tmp/tcloop/alsa $ depList -cdn *
libasound.tcz
ncurses.tcz
These dependencies are missing
libsamplerate.so.0
/tmp/tcloop/alsa $

The latter works fine however :)
That's because most packages only has "usr"  under it's "root directory",
if it has more then one directory (such as etc), you'll cd to etc and get "usr.tcz not found" error message.

Anyway~~
Feel free to modify it to suit your need  ;)
This script is made to help package maintainers to figure out what dependencies are required, and remove all the redundant ones.
(such as cairo.tcz, already a dependence of gtk3.tcz)

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: A script to check dependencies
« Reply #32 on: January 08, 2017, 02:17:30 AM »
Thanks for the insight.

I was just admiring your work and it seemed a pity to modify it just to suite little old me.   But my systems have such long paths to their optional directories  where I build extensions,  it would be near impossible or tedious to say the least to type in the full path every time (even with tab completion).  Even more difficult to remember I need to type the full path each time  :p
Once configure and make has finished the project, I load up a desktop environment asap.


I already created an extension so that we need only enter the directory then run it.   Is an easy fix to add default arguments and use current path, I'll look at that..

thanks for the script, it's really helpful
« Last Edit: January 08, 2017, 02:26:36 AM by coreplayer2 »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14794
Re: A script to check dependencies
« Reply #33 on: January 09, 2017, 01:44:26 AM »
Did you accidentally add/delete anything by chance ?

Hmm - it seems the problem is with fifth, if use opera-9 to copy and paste it works.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: A script to check dependencies
« Reply #34 on: January 09, 2017, 06:44:43 AM »
It would be an actual step in the "grand unified extension build script" dream if we had an extension checker script we could all get behind. We have two kinds of extension dependency problems, those with direct dependencies that we can "measure" using ldd, and those we just have to know about like bash or tzdata or gnome-icon-theme and the like. I like others have a script to solve the first problem. I don't find the '-f' option in the script which is the topic of this thread of much use, it needs to be distilled. To that end here's my script if you want to incorporate it. Or someone else's like it. Or not. It's more in the busybox style, in that you need to create symlinks to get the different functionality. It uses shell recursion to walk the library dependency tree, so it's kinda slow, and painfully so with X/GTK apps. But it seems to give the right answers so I keep using it. The names of the symlinks correspond to the choices in the main case block.

Code: [Select]
#!/bin/sh

list_libs(){
ldd "$2" | grep '=>' | while read SLIB SEP DLIB ADDR; do
if [ "$DLIB $ADDR" = "not found" ] ; then
echo -e "\\n***ERROR*** $SLIB not found ***\\n"
else
DEPTH=$(($1 + 1))
case "$DLIB" in
*/local/* ) EXT=$(readlink -f "$DLIB" | cut -d/ -f4) ;;
* ) EXT="xxx${DEPTH}" ;;
esac
eval "qq$DEPTH=$EXT"
CIRC=0
for LEVEL in $(seq $1); do
eval "DEP=\$qq$LEVEL"
[ "$EXT" = "$DEP" ] && CIRC=$LEVEL
echo -e -n \\t
done
echo -n "$DEPTH ==>> $DLIB"
case "$ELF" in
*"/$EXT/"* ) echo " *** $EXT SELF-REFERENCING ***"
continue ;;
* ) [ "$EXT" != "xxx$DEPTH" -a $CIRC -eq 0 ] && echo -n "  extension: $EXT.tcz" ;;
esac
echo
if [ $CIRC -gt 0 ] ; then
if [ "$EXT" != "$DEP" ] ; then
echo -e "\\n*** CIRCULAR REFERENCES FOUND BETWEEN $EXT and $DEP ***\\n"
return
fi
else
list_libs $DEPTH "$DLIB"
fi
fi
done
}

ME=${0##*/}
DEPTH=0
for ELF in $@; do
echo $ELF
case $ME in
lib-tree) list_libs 0 "$ELF" ;;
lib-deps) list_libs 0 "$ELF" | grep extension | cut -d\  -f6 | sort | uniq -c | sort -n ;;
lib-tcz)  for TLIB in $(find "$ELF" -type f)
        do file -b "$TLIB" | grep -q '^ELF ' && list_libs 0 "$TLIB"
  done | tee /tmp/lib-tcz.out | awk '/  extension: / {printf "%03i %s\n", $1,$5}' \
| sort -u | sort -k2 | uniq -f1 -u | awk '/^001 / {print $2}' ;;
esac
echo -e \\n
done

Offline polikuo

  • Hero Member
  • *****
  • Posts: 715
Re: A script to check dependencies
« Reply #35 on: January 09, 2017, 09:56:50 AM »
I don't find the '-f' option in the script which is the topic of this thread of much use, it needs to be distilled.
Personally, I find it helpful remastering an iso image when copying files, especially when you need some custom packages.
I can trick the script by myscript -f /path/to/an/empty/directory `cat list-of-wanted-packages`, and get a full list.

To that end here's my script if you want to incorporate it.
Thanks,  we learn something new every day :)
It's more in the busybox style, in that you need to create symlinks to get the different functionality.
I learn something new today, I never knew "while" and "read" can be combined and have several variables.  :D
Also, a script called from different symlinks can have different result, knowledge acquired! It does share a similarity with busybox.  ;D
Your script is amazing, I'll need some time to digest that.  :)
Thanks for the script, will work on it when I have time for it.  ;)
Life gets in the way.  :P

Oh, before I go, I notice that you use "readlink" for the linking.
Personally I prefer using "realpath" instead, cause some packages might have libraries that link to each other by tce.installed script.
(Haven't seen one yet, but just in case)

For instance:
/usr/local/lib/libA.so         -->   /tmp/tcloop/libA/usr/local/lib/libA.so
/usr/local/lib/libA.so.1      -->   /usr/local/lib/libA.so

readlink /usr/local/lib/libA.so
/tmp/tcloop/libA/usr/local/lib/libA.so   -->   Good, that's what we want.
readlink /usr/local/lib/libA.so.1
/usr/local/lib/libA.so                           -->   OMG, I need to read again ??
realpath /usr/local/lib/libA.so.1
/tmp/tcloop/libA/usr/local/lib/libA.so   -->   Straight to the target.  :D

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: A script to check dependencies
« Reply #36 on: January 09, 2017, 10:41:44 AM »
Personally, I find it helpful remastering an iso image when copying files, especially when you need some custom packages.
I can trick the script by myscript -f /path/to/an/empty/directory `cat list-of-wanted-packages`, and get a full list.
If you remaster, whether a one off or multiple repetitive ISO's; with or without custom extensions, then I urge you to look at ezremaster.tcz 
:)
« Last Edit: January 09, 2017, 10:44:00 AM by coreplayer2 »

Offline polikuo

  • Hero Member
  • *****
  • Posts: 715
Re: A script to check dependencies
« Reply #37 on: January 09, 2017, 11:16:46 AM »
If you remaster, whether a one off or multiple repetitive ISO's; with or without custom extensions, then I urge you to look at ezremaster.tcz 
:)

Thanks, I do know it, I just prefer remastering manually.
It provides the most flexibility.  ;)

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: A script to check dependencies
« Reply #38 on: January 09, 2017, 11:34:24 AM »
The -f option to readlink is important. That should get you to the actual file.

For checking whether or not I have all the required extensions (unresolved libraries) loaded (in an ESXi VM in my case) I use this:

Code: [Select]
#!/bin/sh
#
for a in $(find /tmp/tcloop -type f)
        do file -b $a | grep -q '^ELF ' && ldd $a | grep -q found && echo $a
done

To find out if I have extensions loaded I don't need (unreferenced extensions) I use this:

Code: [Select]
#!/bin/sh
#
{ tce-status -i ;
for b in $(for a in $(find /tmp/tcloop -type f)
        do file -b $a | grep -q '^ELF ' && ldd $a | grep /local/ | cut -d\  -f3 | cut -d/ -f5
        done | sort -u)
        do find /tmp/tcloop -name $b | cut -d/ -f4
done | sort -u ; } | sort | uniq -u

Again, I use these for jogging my memory. They are by no means definitive.

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 708
Re: A script to check dependencies
« Reply #39 on: January 23, 2017, 02:11:21 PM »
I could be cool if all script's that getting the dep, also make a graphviz dot file.
To visualize the dependency chart map.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: A script to check dependencies
« Reply #40 on: January 23, 2017, 11:34:39 PM »
The first script I posted will do a library dependency tree if called as lib-tree. If you want a .tcz dependency tree you could just grep the output for tcz. Not sure why though, except that it's more educational if not particularly useful.

Offline polikuo

  • Hero Member
  • *****
  • Posts: 715
Re: A script to check dependencies
« Reply #41 on: June 27, 2018, 11:24:35 AM »
I have refactored the script for performance boost and added some new functions.

The latest script can be found here.

The purpose of this script is to help package maintainers to find out which extensions are needed under a certain directory.
For instance, I compile openbox and make install to /tmp/openbox-root.
Then, run the script as below.
Code: [Select]
tc@box:/tmp $ get-dep-list /tmp/openbox-root
WARNING! python script detected
imlib2.tcz
libICE.tcz
libSM.tcz
libXcursor.tcz
libXinerama.tcz
libXrandr.tcz
librsvg.tcz
As you can see, the deps are printed, you can redirect it to openbox.tcz.dep
Since /usr/local/libexec/openbox-xdg-autostart is a python script, you'll get a warning.
However, python.tcz is not appended automatically in the list because usually these scripts are optional functions.
To append it, just run the script this way: "get-dep-list /tmp/openbox-root python"

The new functions are shown below:
Quote
Usage: get-dep-list [-option] directory [append your list here ...]
Available Options (default -ns)
  -c     colorful output
  -d     show only the detected tczs, without custom extensions (blue)
  -g     graph .tcz.tree (magenta)
  -h     show this helpinfo (yellow)
  -n     show dependencies that can not be found (red)
  -p     scan provides.db for dependencies
  -r     show recursively scanned tczs (green)
  -s     show shortened tczs (cyan)
  -t DIR set tcedir to DIR (default /etc/sysconfig/tcedir)
The "-d" function prints only the "ldd-matched" tczs.
The "-g" function prints the dep tree of the shortened tczs.
The "-p" function use provides.db as reference if there are matched missing dependencies.
The "-t" function switch you tcedir to another directory.
All the other functions are inherited from previous versions.

P.S. I think this thread should be moved to "Programming & Scripting - Unofficial".
« Last Edit: June 27, 2018, 11:45:50 AM by polikuo »