Skip to content

Instantly share code, notes, and snippets.

@satmandu
Last active Mar 25, 2021
Embed
What would you like to do?
Chromebrew get actual runtime dependencies for a package
#!/bin/env bash
# set -x
pkg="${1}"
CREW_LIB_PREFIX=$(crew const | grep CREW_LIB_PREFIX | awk -F = '{print $2}')
# Which packages have a needed library in CREW_LIB_PREFIX
# This is a subset of what crew whatprovides gives
whatprovidesfxn() {
pkgdepslcl="${1}"
filelcl=$(grep "$pkgdepslcl" /usr/local/etc/crew/meta/*.filelist | grep $CREW_LIB_PREFIX)
packagelcl=$(echo "$filelcl" | \
sed 's/.filelist.*//g' | sed 's:.*/::' | awk '!x[$0]++' | sed s/://g)
echo $packagelcl
}
# What files does a package provide
crewfilesfxn() {
pkgname="${1}"
files=$(cat /usr/local/etc/crew/meta/${pkgname}.filelist)
echo $files
}
pkgfiles=$(crewfilesfxn "${pkg}")
# Use readelf to determine library dependencies. (This doesn't almost
# run a program like ldd would.
pkgdeps=$(unset lines ; for i in $pkgfiles ; \
do lines+=$(readelf -d "$i" 2>/dev/null | grep NEEDED | awk '{print $5}' \
| sed 's/\[//g' | sed 's/\]//g') ; done ; echo "$lines" | tr " " "\n" \
| awk '!x[$0]++')
pkgdeps=$(unset lines; for j in $pkgdeps ; \
do lines+=$(echo -e "\n" ; whatprovidesfxn $j); done ; \
echo "$lines" | tr " " "\n" | awk '!x[$0]++')
# Remove original package from list.
pkgdeps=$(echo $pkgdeps | tr " " "\n" | sed "/${1}/d")
pkgdepsnocore=$pkgdeps
for i in $(curl -Ls https://github.com/skycocker/chromebrew/raw/master/tools/core_packages.txt) freetype_sub
do
file=$(basename $i)
pkgdepsnocore=$(echo $pkgdepsnocore | tr " " "\n" | sed "/$file/d")
done
pkgdepsnocore=$(echo $pkgdepsnocore | tr " " "\n" | sort -u )
# If no non-core packages are dependencies, then just mention the core
# dependencies
if [ -z "${pkgdepsnocore}" ]; then
pkgdepsdisplay=$pkgdeps
else
pkgdepsdisplay=$pkgdepsnocore
fi
for i in $pkgdepsdisplay
do
echo " depends_on '$i'"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment