diff options
author | Britney Fransen <brfransen@gmail.com> | 2014-12-19 16:41:48 (GMT) |
---|---|---|
committer | Britney Fransen <brfransen@gmail.com> | 2014-12-19 16:41:48 (GMT) |
commit | 3f1b05fe6c45807a18f97df952fbabdf830da1de (patch) | |
tree | e6949264ca343515720fb3a06d1f19604304ce51 /build_tools/bin | |
parent | 36b3fb5b9118bc2ab52f7579fad9f0e411144a5d (diff) | |
download | linhes_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')
-rwxr-xr-x | build_tools/bin/chk_arch_pkg.py | 181 | ||||
-rwxr-xr-x | build_tools/bin/lddd | 291 |
2 files changed, 472 insertions, 0 deletions
diff --git a/build_tools/bin/chk_arch_pkg.py b/build_tools/bin/chk_arch_pkg.py new file mode 100755 index 0000000..e995fff --- /dev/null +++ b/build_tools/bin/chk_arch_pkg.py @@ -0,0 +1,181 @@ +#!/usr/bin/python2 +#chk_arch_pkg.py uses the current dir name and finds the archlinux package url +#prints the current version of the package in archlinux +#prints the current version of the PKGBUILD in the working dir +#asks to download and expand the archlinx sources +#asks to copy the archlinux sources to the working dir +#asks to delete the downloaded and expanded sources + +import os,sys +import shutil +import urllib2 +import re +import subprocess + +def getArchVer(): + repos=['core', 'extra', 'community', 'aur'] + website="" + archVer="" + aPKGBUILD="" + global repo + global sourceURL + for repo in repos: + try: + if repo == "aur": + url='https://aur.archlinux.org/packages/%s/' %currDirName + else: + url='https://www.archlinux.org/packages/%s/x86_64/%s/' %(repo, currDirName) + website = urllib2.urlopen(url) + #print website + print '%s FOUND in %s:' %(currDirName, repo) + print url + break + except urllib2.HTTPError, e: + print '%s not in %s' %(currDirName, repo) + + if website: + website_text = website.read() + #print website_text + try: + if repo == "aur": + archVerList = re.findall('<h2>Package Details: .*? (.*?)</h2>', website_text) + else: + if "- Split Package Details</title>" in website_text: + print "This is a split package" + aPKGBUILD = urllib2.urlopen("https://projects.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/" + currDirName) + aPKGBUILD_text = aPKGBUILD.read() + archPKGVER = re.findall('pkgver<span class="hl opt">=</span><span class="hl num">(.*?)</span>', aPKGBUILD_text) + archPKGREL = re.findall('pkgrel<span class="hl opt">=</span><span class="hl num">(.*?)</span>', aPKGBUILD_text) + archVer = archPKGVER[0] + "-" + archPKGREL[0] + else: + archVerList = re.findall('<meta itemprop="softwareVersion" content="(.*?)"/>', website_text) + archVer = archVerList[0] + print currDirName + " version in archlinux is: " + archVer + except: + print "Unable to find archlinux version" + + try: + if repo == "aur": + source = re.findall('<li><a href="(.*?)">Download tarball</a></li>', website_text) + sourceURL = "https://aur.archlinux.org" + source[0] + else: + if "- Split Package Details</title>" in website_text: + #print "Split Pkg" + sourceURL = "https://projects.archlinux.org/svntogit/packages.git/tree/trunk?h=packages/" + currDirName + else: + source = re.findall('<a href="(.*?)" title="View source files for .*?">Source Files</a>', website_text) + sourceURL = source[0] + #print sourceURL + except: + print "Unable to find archlinux source link" + sourceURL = "" + else: + print "%s is not found in archlinux repos" %currDirName + + return archVer + +def getLHVer(): + pkgfile = os.getcwd() + "/PKGBUILD" + if not os.path.isfile(pkgfile): + print currDirName + " version in LH PKGBUILD is: Unknown" + print " Can't find",pkgfile + #sys.exit(2) + else: + LHVer="" + variables=["pkgbase", "pkgname", "pkgver", "pkgrel", "epoch"] + # Loop over contents to get our variables + # Use bash to do it because PKGBUILDs are very loose with their format + for item in variables: + v = subprocess.Popen(['/bin/bash','-c', 'source ' + + pkgfile + + '; echo ${' + item + '[@]}'], + stdout = subprocess.PIPE,) + value = v.communicate()[0].strip('\n') + if item == "pkgbase": + pkgbase = value + elif item == "pkgname": + pkgname = value + pkglist = list(value.split()) + elif item == "epoch": + if value: + epoch = "%s:" %value + LHVer=epoch + elif item == "pkgver": + pkgver = value + elif item == "pkgrel": + pkgrel = value + LHVer=LHVer + pkgver + "-" + pkgrel + print currDirName + " version in LH PKGBUILD is: " + LHVer + +def getSource(): + if yes_all: + str1 = "Y" + else: + str1 = raw_input("\n Press any key to download source from arch, or N to cancel: ") + if str1 != 'N' and str1 != 'n': + if repo == "aur": + dlSource = sourceURL + else: + if repo == "community": + repoTag = "community" + else: + repoTag = "packages" + dlSource = 'https://projects.archlinux.org/svntogit/%s.git/snapshot/%s-packages/%s.tar.gz' %(repoTag, repoTag, currDirName) + + print dlSource + subprocess.call(["curl", "-O", dlSource]) + filename=currDirName + ".tar.gz" + subprocess.call(["tar", "xvf", filename]) + + if yes_all: + str2 = "Y" + else: + str2 = raw_input("\n Press any key to copy files to pkgdir, or N to cancel: ") + if str2 != 'N' and str2 != 'n': + if repo == "aur": + srcDir = os.getcwd() + "/" + currDirName + else: + srcDir = os.getcwd() + "/" + repoTag + "-packages/" + currDirName + "/trunk/" + src_files = os.listdir(srcDir) + for file_name in src_files: + if file_name != ".AURINFO": + full_file_name = os.path.join(srcDir, file_name) + if (os.path.isfile(full_file_name)): + shutil.copy(full_file_name, os.getcwd()) + else: + sys.exit(0) + + if yes_all: + str3 = "Y" + else: + str3 = raw_input("\n Press any key to remove downloads, or N to cancel: ") + if str3 != 'N' and str3 != 'n': + subprocess.call(["rm", filename]) + if repo == "aur": + subprocess.call(["rm", "-r", currDirName]) + else: + subprocess.call(["rm", "-r", repoTag + "-packages"]) + else: + sys.exit(0) + +def main(): + global currDirName + global yes_all + + current_folder_path, currDirName = os.path.split(os.getcwd()) + yes_all = False + + if "--yes_all" in sys.argv or "-y" in sys.argv: + yes_all = True + + print "Searching for " + currDirName + " on archlinux.org..." + archVer = getArchVer() + getLHVer() + if archVer != "" and sourceURL != "": + getSource() + +if __name__ == "__main__": + print "--------------------------" + main() + print "--------------------------" + 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" |