#!/bin/sh -efu # # Copyright (C) 2000-2006 Dmitry V. Levin # Copyright (C) 2007 Alexey Tourbin # # find-provides - generate list of linux-specific package provides. # Inspired by tool with same name from RPM distribution. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # . @RPMCONFIGDIR@/functions ValidateBuildRoot workdir= exit_handler() { local rc=$? trap - EXIT [ -z "$workdir" ] || rm -rf "$workdir" cat >/dev/null exit $rc } trap exit_handler EXIT HUP INT QUIT PIPE TERM methods=$(SetupMethods prov "$RPM_FINDPROV_METHOD") if [ -z "$methods" ]; then Info "AutoProv disabled, nothing to do" exit 0 fi workdir=$(mktemp -dt "$PROG".XXXXXXXX) # filter file list through TOPDIR and SKIPLIST patterns while IFS= read -r f; do fname="${f#$RPM_BUILD_ROOT}" if [ -n "${RPM_FINDPROV_TOPDIR-}" ] && [ -z "${fname%%$RPM_FINDPROV_TOPDIR/*}" ]; then Debug "skip $f due to RPM_FINDPROV_TOPDIR=$RPM_FINDPROV_TOPDIR" continue fi if [ -n "${RPM_FINDPROV_SKIPLIST-}" ]; then for skip in $RPM_FINDPROV_SKIPLIST; do if [ -z "${fname##$skip}" ]; then Debug "skip $f due to RPM_FINDPROV_SKIPLIST pattern $skip" continue 2 fi done fi if [ -L "$f" ]; then to="$(readlink "$f")" if [ -n "$to" -a -z "${to##/*}" ]; then Info "absolute symbolic link $f -> $to is not going to provide anything" continue elif ! [ -e "$f" ]; then Info "broken symbolic link $f -> $to is not going to provide anything" continue fi fi echo "$f" done >"$workdir"/files if ! [ -s "$workdir"/files ]; then Info "empty file list, nothing to do" exit 0 fi # filter file list through file(1) to append types (dereference symlinks) if ! file -L -NF$'\t' -f "$workdir"/files >"$workdir"/files+types; then sed -n '/\t *ERROR:/p' "$workdir"/files+types >&2 exit 1 fi found= RunMethod() { local exe="$1"; shift local filter="$exe".files if ! [ -x "$filter" ]; then # XXX should be Fatal Info "$filter not available" return fi local filelist="$workdir/${exe##*/}".files local deplist="$workdir/${exe##*/}".deps Debug "running $filter" "$filter" <"$workdir"/files+types >"$filelist" Verbose "$filter: $(wc -l <"$filelist") files" [ -s "$filelist" ] || return 0 # XXX validate $filelist Debug "running $exe" "$exe" <"$filelist" >"$deplist" Verbose "$exe: $(wc -l <"$deplist") dependencies" [ -s "$deplist" ] || return 0 found=1 } Info "running scripts ($methods)" RunMethods prov "$methods" RunMethod [ -z "$found" ] || (set +f; LC_COLLATE=C sort -u "$workdir"/*.deps) || exit 1 exit 0 FIND_MONO= FIND_PERL= FIND_PYTHON= FIND_TCL= ParseMethod() { local t for t in "$@"; do case "${t/%,}" in no|none|off|false) FIND_MONO= FIND_PERL= FIND_PYTHON= FIND_TCL= ;; java|nojava) ;; mono) FIND_MONO=1 ;; nomono) FIND_MONO= ;; perl) FIND_PERL=1 ;; noperl) FIND_PERL= ;; python) FIND_PYTHON=1 ;; nopython) FIND_PYTHON= ;; tcl) FIND_TCL=1 ;; notcl) FIND_TCL= ;; all) FIND_MONO=1 FIND_PERL=1 FIND_PYTHON=1 FIND_TCL=1 ;; default|yes|true) ParseMethod $RPM_FINDPROV_DEFAULT_METHOD || return 1 ;; *) Fatal "Unrecognized find-provides method: $t" ;; esac done } ParseMethod $RPM_FINDPROV_METHOD if [ -z "$FIND_MONO" -a \ -z "$FIND_PERL" -a \ -z "$FIND_PYTHON" -a \ -z "$FIND_TCL" ]; then # Nothing to do cat >/dev/null 2>&1 exit 0 fi ulimit -c 0 case "$LD_PRELOAD" in *libfakeroot*) unset LD_PRELOAD ;; *libbuildreq.so*) unset LD_PRELOAD ;; esac FOUND_PROVS= LIST_MONO= LIST_PERL= LIST_PYTHON= LIST_TCL= ListScriptProvs() { local f t f="$1" t="$2" # Ignore symlinks for non-PAM scripts. [ ! -L "$f" ] || return 0 if [ -z "${t##perl script text*}" -o -z "${t##Perl5 module source text}" -o -z "${f%%*.p[lmh]}" ]; then if [ -n "$FIND_PERL" ]; then [ -z "$LIST_PERL" ] && LIST_PERL="$f" || LIST_PERL="$LIST_PERL $f" fi fi if [ -z "${f%%*.py}" -o -z "${f%%*.pyo}" -o -z "${f%%*.pyc}" -o -z "${f%%*.pth}" ]; then if [ -n "$FIND_PYTHON" ]; then [ -z "$LIST_PYTHON" ] && LIST_PYTHON="$f" || LIST_PYTHON="$LIST_PYTHON $f" fi fi if [ "${f##*/}" = "pkgIndex.tcl" ]; then if [ -n "$FIND_TCL" ]; then [ -z "$LIST_TCL" ] && LIST_TCL="$f" || LIST_TCL="$LIST_TCL $f" fi fi } FindMonoProvs() { [ -n "$FIND_MONO" -a -n "$LIST_MONO" -a -x "@RPMCONFIGDIR@/mono.prov" ] || return 0 local r r="$(printf %s\\n "$LIST_MONO" | @RPMCONFIGDIR@/mono.prov "$RPM_BUILD_DIR" "$RPM_BUILD_ROOT" "$RPM_LIBDIR")" || return 1 [ -z "$FOUND_PROVS" ] && FOUND_PROVS="$r" || FOUND_PROVS="$FOUND_PROVS $r" } FindPerlProvs() { [ -n "$FIND_PERL" -a -n "$LIST_PERL" ] || return 0 local r r="$(printf %s\\n "$LIST_PERL" |@RPMCONFIGDIR@/perl.prov)" || return 1 [ -z "$FOUND_PROVS" ] && FOUND_PROVS="$r" || FOUND_PROVS="$FOUND_PROVS $r" } FindPythonProvs() { [ -n "$FIND_PYTHON" -a -n "$LIST_PYTHON" ] || return 0 [ -x "$RPM_PYTHON" ] || return 0 local r r="$(printf %s\\n "$LIST_PYTHON" |"$RPM_PYTHON" @RPMCONFIGDIR@/python.prov.py)" || return 1 [ -z "$FOUND_PROVS" ] && FOUND_PROVS="$r" || FOUND_PROVS="$FOUND_PROVS $r" } FindTclProvs() { [ -n "$FIND_TCL" -a -n "$LIST_TCL" ] || return 0 [ -x "$RPM_TCLSH" ] || return 0 local r r="$(printf %s\\n "$LIST_TCL" |@RPMCONFIGDIR@/tcl.prov)" || return 1 [ -z "$FOUND_PROVS" ] && FOUND_PROVS="$r" || FOUND_PROVS="$FOUND_PROVS $r" } while IFS= read -r f; do if t="$(file -bL "$f")"; then if [ -z "${t##* text*}" ]; then ListScriptProvs "$f" "$t" elif [ -z "${t##*MS Windows PE*}" ]; then [ -z "$LIST_MONO" ] && LIST_MONO="$f" || LIST_MONO="$LIST_MONO $f" elif [ "${f##*/}" = '__init__.py' ]; then # Zero-length python init files have major sense. [ -z "$LIST_PYTHON" ] && LIST_PYTHON="$f" || LIST_PYTHON="$LIST_PYTHON $f" fi else Info "$f: file type not available" fi done # Find provides in listed .Net executables and shared libraries, if any FindMonoProvs # Find provides in listed perl scripts, if any FindPerlProvs # Find provides in listed python scripts and shared libraries, if any FindPythonProvs # Find provides in listed tcl index files, if any FindTclProvs