summaryrefslogtreecommitdiffstats
path: root/build_tools/bin/lddd
diff options
context:
space:
mode:
authorBritney Fransen <brfransen@gmail.com>2014-12-19 16:41:48 (GMT)
committerBritney Fransen <brfransen@gmail.com>2014-12-19 16:41:48 (GMT)
commit3f1b05fe6c45807a18f97df952fbabdf830da1de (patch)
treee6949264ca343515720fb3a06d1f19604304ce51 /build_tools/bin/lddd
parent36b3fb5b9118bc2ab52f7579fad9f0e411144a5d (diff)
downloadlinhes_dev-3f1b05fe6c45807a18f97df952fbabdf830da1de.zip
chk_arch_pkg.py: utility to pull down arch sources for current package
lddd: from arch devtools
Diffstat (limited to 'build_tools/bin/lddd')
-rwxr-xr-xbuild_tools/bin/lddd291
1 files changed, 291 insertions, 0 deletions
diff --git a/build_tools/bin/lddd b/build_tools/bin/lddd
new file mode 100755
index 0000000..a16b332
--- /dev/null
+++ b/build_tools/bin/lddd
@@ -0,0 +1,291 @@
+#!/bin/bash
+#
+# lddd - find broken library links on your machine
+#
+
+# Avoid any encoding problems
+export LANG=C
+
+shopt -s extglob
+
+# check if messages are to be printed using color
+unset ALL_OFF BOLD BLUE GREEN RED YELLOW
+if [[ -t 2 ]]; then
+ # prefer terminal safe colored and bold text when tput is supported
+ if tput setaf 0 &>/dev/null; then
+ ALL_OFF="$(tput sgr0)"
+ BOLD="$(tput bold)"
+ BLUE="${BOLD}$(tput setaf 4)"
+ GREEN="${BOLD}$(tput setaf 2)"
+ RED="${BOLD}$(tput setaf 1)"
+ YELLOW="${BOLD}$(tput setaf 3)"
+ else
+ ALL_OFF="\e[1;0m"
+ BOLD="\e[1;1m"
+ BLUE="${BOLD}\e[1;34m"
+ GREEN="${BOLD}\e[1;32m"
+ RED="${BOLD}\e[1;31m"
+ YELLOW="${BOLD}\e[1;33m"
+ fi
+fi
+readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
+
+plain() {
+ local mesg=$1; shift
+ printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+msg() {
+ local mesg=$1; shift
+ printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+msg2() {
+ local mesg=$1; shift
+ printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+warning() {
+ local mesg=$1; shift
+ printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+error() {
+ local mesg=$1; shift
+ printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+stat_busy() {
+ local mesg=$1; shift
+ printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" >&2
+}
+
+stat_done() {
+ printf "${BOLD}done${ALL_OFF}\n" >&2
+}
+
+setup_workdir() {
+ [[ -z $WORKDIR ]] && WORKDIR=$(mktemp -d --tmpdir "${0##*/}.XXXXXXXXXX")
+}
+
+cleanup() {
+ [[ -n $WORKDIR ]] && rm -rf "$WORKDIR"
+ exit ${1:-0}
+}
+
+abort() {
+ error 'Aborting...'
+ cleanup 255
+}
+
+trap_abort() {
+ trap - EXIT INT QUIT TERM HUP
+ abort
+}
+
+trap_exit() {
+ local r=$?
+ trap - EXIT INT QUIT TERM HUP
+ cleanup $r
+}
+
+die() {
+ (( $# )) && error "$@"
+ cleanup 255
+}
+
+trap 'trap_abort' INT QUIT TERM HUP
+trap 'trap_exit' EXIT
+
+##
+# usage : in_array( $needle, $haystack )
+# return : 0 - found
+# 1 - not found
+##
+in_array() {
+ local needle=$1; shift
+ local item
+ for item in "$@"; do
+ [[ $item = $needle ]] && return 0 # Found
+ done
+ return 1 # Not Found
+}
+
+##
+# usage : get_full_version( [$pkgname] )
+# return : full version spec, including epoch (if necessary), pkgver, pkgrel
+##
+get_full_version() {
+ # set defaults if they weren't specified in buildfile
+ pkgbase=${pkgbase:-${pkgname[0]}}
+ epoch=${epoch:-0}
+ if [[ -z $1 ]]; then
+ if (( ! epoch )); then
+ echo $pkgver-$pkgrel
+ else
+ echo $epoch:$pkgver-$pkgrel
+ fi
+ else
+ for i in pkgver pkgrel epoch; do
+ local indirect="${i}_override"
+ eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p")
+ [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\"
+ done
+ if (( ! $epoch_override )); then
+ echo $pkgver_override-$pkgrel_override
+ else
+ echo $epoch_override:$pkgver_override-$pkgrel_override
+ fi
+ fi
+}
+
+##
+# usage : lock( $fd, $file, $message )
+##
+lock() {
+ eval "exec $1>"'"$2"'
+ if ! flock -n $1; then
+ stat_busy "$3"
+ flock $1
+ stat_done
+ fi
+}
+
+##
+# usage : slock( $fd, $file, $message )
+##
+slock() {
+ eval "exec $1>"'"$2"'
+ if ! flock -sn $1; then
+ stat_busy "$3"
+ flock -s $1
+ stat_done
+ fi
+}
+
+##
+# usage: pkgver_equal( $pkgver1, $pkgver2 )
+##
+pkgver_equal() {
+ local left right
+
+ if [[ $1 = *-* && $2 = *-* ]]; then
+ # if both versions have a pkgrel, then they must be an exact match
+ [[ $1 = "$2" ]]
+ else
+ # otherwise, trim any pkgrel and compare the bare version.
+ [[ ${1%%-*} = "${2%%-*}" ]]
+ fi
+}
+
+##
+# usage: find_cached_package( $pkgname, $pkgver, $arch )
+#
+# $pkgver can be supplied with or without a pkgrel appended.
+# If not supplied, any pkgrel will be matched.
+##
+find_cached_package() {
+ local searchdirs=("$PWD" "$PKGDEST") results=()
+ local targetname=$1 targetver=$2 targetarch=$3
+ local dir pkg pkgbasename pkgparts name ver rel arch size r results
+
+ for dir in "${searchdirs[@]}"; do
+ [[ -d $dir ]] || continue
+
+ for pkg in "$dir"/*.pkg.tar?(.?z); do
+ [[ -f $pkg ]] || continue
+
+ # avoid adding duplicates of the same inode
+ for r in "${results[@]}"; do
+ [[ $r -ef $pkg ]] && continue 2
+ done
+
+ # split apart package filename into parts
+ pkgbasename=${pkg##*/}
+ pkgbasename=${pkgbasename%.pkg.tar?(.?z)}
+
+ arch=${pkgbasename##*-}
+ pkgbasename=${pkgbasename%-"$arch"}
+
+ rel=${pkgbasename##*-}
+ pkgbasename=${pkgbasename%-"$rel"}
+
+ ver=${pkgbasename##*-}
+ name=${pkgbasename%-"$ver"}
+
+ if [[ $targetname = "$name" && $targetarch = "$arch" ]] &&
+ pkgver_equal "$targetver" "$ver-$rel"; then
+ results+=("$pkg")
+ fi
+ done
+ done
+
+ case ${#results[*]} in
+ 0)
+ return 1
+ ;;
+ 1)
+ printf '%s\n' "$results"
+ return 0
+ ;;
+ *)
+ error 'Multiple packages found:'
+ printf '\t%s\n' "${results[@]}" >&2
+ return 1
+ esac
+}
+
+##
+# usage : check_root ("$0" "$@")
+##
+check_root() {
+ (( EUID == 0 )) && return
+ if type -P sudo >/dev/null; then
+ exec sudo -- "$@"
+ else
+ exec su root -c "$(printf ' %q' "$@")"
+ fi
+}
+
+
+ifs=$IFS
+IFS="${IFS}:"
+
+libdirs="/lib /usr/lib /usr/local/lib $(cat /etc/ld.so.conf.d/*)"
+extras=
+
+TEMPDIR=$(mktemp -d --tmpdir lddd-script.XXXX)
+
+msg 'Go out and drink some tea, this will take a while :) ...'
+# Check ELF binaries in the PATH and specified dir trees.
+for tree in $PATH $libdirs $extras; do
+ msg2 "DIR $tree"
+
+ # Get list of files in tree.
+ files=$(find $tree -type f ! -name '*.a' ! -name '*.la' ! -name '*.py*' ! -name '*.txt' ! -name '*.h' ! -name '*.ttf' ! \
+ -name '*.rb' ! -name '*.ko' ! -name '*.pc' ! -name '*.enc' ! -name '*.cf' ! -name '*.def' ! -name '*.rules' ! -name \
+ '*.cmi' ! -name '*.mli' ! -name '*.ml' ! -name '*.cma' ! -name '*.cmx' ! -name '*.cmxa' ! -name '*.pod' ! -name '*.pm' \
+ ! -name '*.pl' ! -name '*.al' ! -name '*.tcl' ! -name '*.bs' ! -name '*.o' ! -name '*.png' ! -name '*.gif' ! -name '*.cmo' \
+ ! -name '*.cgi' ! -name '*.defs' ! -name '*.conf' ! -name '*_LOCALE' ! -name 'Compose' ! -name '*_OBJS' ! -name '*.msg' ! \
+ -name '*.mcopclass' ! -name '*.mcoptype')
+ IFS=$ifs
+ for i in $files; do
+ if (( $(file $i | grep -c 'ELF') != 0 )); then
+ # Is an ELF binary.
+ if (( $(ldd $i 2>/dev/null | grep -c 'not found') != 0 )); then
+ # Missing lib.
+ echo "$i:" >> $TEMPDIR/raw.txt
+ ldd $i 2>/dev/null | grep 'not found' >> $TEMPDIR/raw.txt
+ fi
+ fi
+ done
+done
+grep '^/' $TEMPDIR/raw.txt | sed -e 's/://g' >> $TEMPDIR/affected-files.txt
+# invoke pacman
+for i in $(cat $TEMPDIR/affected-files.txt); do
+ pacman -Qo $i | awk '{print $4,$5}' >> $TEMPDIR/pacman.txt
+done
+# clean list
+sort -u $TEMPDIR/pacman.txt >> $TEMPDIR/possible-rebuilds.txt
+
+msg "Files saved to $TEMPDIR"