Skip to content

Instantly share code, notes, and snippets.

@jhrcz
Last active December 18, 2015 04:49
Show Gist options
  • Save jhrcz/5727972 to your computer and use it in GitHub Desktop.
Save jhrcz/5727972 to your computer and use it in GitHub Desktop.

real world example of check-pkgswithoutrepo.sh

it is important to note, that this is slooooow. i think about some sort of asynchronicity

# time bash check-out-of-repos.sh
FAILED, 8 packages without repos found:  etnpol-tomcat-5.5.23-mysql-5.5.23-6.noarch git-1.8.0.1-1.jhr.1.el6.x86_64 etnpol-tomcat-5.5.23-log4j-5.5.23-6.noarch etnpol-tomcat-5.5.23-5.5.23-6.noarch perl-Git-1.8.0.1-1.jhr.1.el6.noarch percona-release-0.0-1.x86_64 etnpol-tomcat-5.5.23-core-5.5.23-6.noarch nagios-plugin-check-bindmounts-0.1.00.snap.20130307.115442.git.7b7b268-0.el6.noarch

real	5m32.469s
user	3m58.912s
sys	1m37.078s
#!/bin/bash
#
# check-pkgswithoutrepo.sh
#
# find packages not in any repo or spacewalk channel
# reported packages indicate manual/local instalation
#
# sample output:
#
# a) some packages without repo found (exit status 3)
# 1 package(s) without repos found: git-1.8.0.1-1.jhr.1.el6.x86_64
# b) no packages without repo found (exit status 0)
# all is ok, all packages available in repos
#
EXCLUDE=( "^gpg-pubkey" "^kernel" )
norepopkgs=""
norepopkgs_cnt=0
while read pkg
do
for exc in ${EXCLUDE[@]}
do
if echo $pkg | grep -q "$exc"
then
continue 2
fi
done
if yum -C info --showduplicates $pkg 2>/dev/null | grep -q 'Available Packages'
then
:
else
norepopkgs="$norepopkgs $pkg"
norepopkgs_cnt=$(($norepopkgs_cnt + 1))
fi
done < <( rpm -qa )
if [ "$norepopkgs_cnt" -gt 0 ]
then
echo "FAILED, $norepopkgs_cnt package(s) without repos found: $norepopkgs" >&2
exit 3
else
echo "OK, all packages available in repos"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment