resolvedeps.sh - A standalone script for dependency resolution

interpretive language scripts


Moderator: Forum moderators

Post Reply
User avatar
sc0ttman
Posts: 93
Joined: Sat Aug 22, 2020 3:55 pm
Has thanked: 4 times
Been thanked: 33 times

resolvedeps.sh - A standalone script for dependency resolution

Post by sc0ttman »

resolvedeps.sh

A standalone script for dependency resolution.

This is in alpha/toy/experiment state. Not ready for production, as they say.

A standalone script that can resolves deps of a given package name is something I wanted years ago, cos:

  • The dep resolution functions in PPM are hard to extract.
  • The dep resolution function in Pkg is not very good.

This resolvedeps.sh can only do package "short names" or "bare names" (no versions, name only, so gimp, mplayer, etc).

Usage

Code: Select all

source resolvedeps.sh

resolvedeps gimp

resolvedeps krita

resolvedeps kodi

Features:

  • accepts package short name, returns its list of deps (recursive)
  • searches all repos at once
  • mostly faster than PPM and Pkg
  • hides builtin packages
  • hides devx packages
  • hides blacklisted packages (it reads from the file ~/.pkg/blacklisted_packages)
  • that's it

Issues & bugs I'd like to fix:

  • does not respect minimum/maximum version numbers in package filenames (it simply strips off the &ge1.2.0, &lt4.0 etc)
  • does not respect "epochs" in package filenames (strips them off too)
  • does not check for correct architecture (x86_64, arm, etc)
  • does not know about "multilib" anything (cos nor do I)
  • does not respect package "alias" name (like PPM and Pkg do)
  • does not respect your repos fallback order (as defined in Pkg configs)
  • does not respect your chosen list of "supported" repos (it will search all available repo files, no matter what)
  • does not hide user installed packages (this may be desired, maybe not)
  • only tested on Focal Fossa, should work in all pups that support PET packages

resolvedeps.sh:

Code: Select all

function list_all_builtins() {
  cut -f2 -d'|' ~/.packages/woof-installed-packages* | sort -u
}



function list_all_devx() {
  cut -f2 -d'|' ~/.packages/devx-only-installed-packages* | sort -u
}



function pkg_deps_top_level() {
  grep "|$1|" ~/.packages/Packages-* \
    | cut -f9 -d'|' \
    | tr , '\n' \
    | sed -e "s#[&|:][any|eq|ge|gt|le|lt|:0-9].*##g" -e 's#^+##' \
    | sort -u
}



function resolvedeps() {
  rm /tmp/$1_deps_level* &>/dev/null
  rm /tmp/$1_deps_no* &>/dev/null

  list_all_builtins > /tmp/all_builtins
  list_all_devx     > /tmp/all_devx

  pkg_deps_top_level $1 > /tmp/$1_deps_level1

  for DEP in $(\cat /tmp/$1_deps_level1)
  do
    [ -z "$DEP" ] && continue
    [ -s /tmp/$1_deps_level1 ] || continue
    pkg_deps_top_level $DEP >> /tmp/$1_deps_level2
  done

  cat /tmp/$1_deps_level1 /tmp/$1_deps_level2 2>/dev/null | sort -u | grep -v ^$ > /tmp/$1_deps_level2_no_dupes
  comm -23 /tmp/$1_deps_level2_no_dupes /tmp/all_builtins > /tmp/$1_deps_level2_no_dupes_no_builtins
  comm -23 /tmp/$1_deps_level2_no_dupes_no_builtins /tmp/all_devx > /tmp/$1_deps_level2_no_dupes_no_builtins_no_devx

  for i in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 18 19 20 21 22 23 24 25
  do
    [ ! -s /tmp/$1_deps_level$(($i - 1))_no_dupes_no_builtins_no_devx ] && continue
    for DEP in $(cat /tmp/$1_deps_level$(($i - 1))_no_dupes_no_builtins_no_devx)
    do
      [ -z "$DEP" ] && continue
      pkg_deps_top_level $DEP >> /tmp/$1_deps_level${i}
    done

    sort -u /tmp/$1_deps_level${i} 2>/dev/null > /tmp/$1_deps_level${i}_no_dupes
    comm -23 /tmp/$1_deps_level${i}_no_dupes /tmp/all_builtins > /tmp/$1_deps_level${i}_no_dupes_no_builtins
    comm -23 /tmp/$1_deps_level${i}_no_dupes_no_builtins /tmp/all_devx > /tmp/$1_deps_level${i}_no_dupes_no_builtins_no_devx
  done

  cat /tmp/$1_deps_level*_no_dupes_no_builtins_no_devx | sort -u | grep -v ^$ 2>/dev/null > /tmp/$1_deps_no_dupes_no_builtins_no_devx

  comm -23 /tmp/$1_deps_no_dupes_no_builtins_no_devx ~/.pkg/blacklisted_packages > /tmp/$1_deps_no_dupes_no_builtins_no_devx_no_blacklisted

  cat /tmp/$1_deps_no_dupes_no_builtins_no_devx_no_blacklisted

}

export -f list_all_builtins
export -f list_all_devx
export -f pkg_deps_top_level
export -f resolvedeps
Last edited by sc0ttman on Sun Aug 28, 2022 12:39 pm, edited 3 times in total.
User avatar
sc0ttman
Posts: 93
Joined: Sat Aug 22, 2020 3:55 pm
Has thanked: 4 times
Been thanked: 33 times

Re: resolvedeps.sh

Post by sc0ttman »

At some point, I'd like to make a deptree.sh <pkgname> command/script from the above, that can print out a nice tree style hierarchy of dependencies to the terminal.

Something like:

Code: Select all

$ deptree.sh freeciv

freeciv
├── freeciv-client-gtk3
├── freeciv-data
└── libfluidsynth2
      ├── libinstpatch-1.0-2
      └── timgm6mb-soundfont

Any code suggestions, help or ideas would be much appreciated.

User avatar
rockedge
Site Admin
Posts: 6543
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2749 times
Been thanked: 2624 times
Contact:

Re: resolvedeps.sh

Post by rockedge »

I do have somewhere on some disk PHP code that makes such a tree. If I can track it down maybe I can translate it to bash or ash and a get an idea.

All in all very exciting stuff starting to come together.

Post Reply

Return to “Scripts”