#!/bin/bash output_dirname=$1 input_dirname=$2 # make sure "sort" works the way we expect it to export LC_ALL=C rpm_dir=/var/lib/rpm dpkg_dir=/var/lib/dpkg bin_dir=`readlink -f $0 | xargs dirname` dpkg=0 rpm=0 if [ "X${output_dirname}" == "X" ] ; then echo "Need to specify output directory. " echo " update_distro []" exit 1 fi function process_rpm { rpm -q --queryformat="%{NAME} %{VERSION} %{RELEASE} %{ARCH}\n" \ -a --dbpath ${input_dirname} \ > ${output_dirname}/packages # Use rpm to generate a list like: # firstpkg # firstpkg.list # firstpkg /path/to/Afile1 # firstpkg /path/to/Afile2 # secondpkg # secondpkg.list # secondpkg /path/to/Bfile1 # secondpkg /path/to/Bfile2 # That list can be ran through "sort -u" to elminate # duplicates within each package, and then the leading # package names can be stripped off using "sed". That # gives a list that can be piped into swab_testf, which # will test each for the existance of each file and # generate the pkg.list files. rpm -qa --qf "%{NAME} # ${output_dirname}/%{NAME}.list\n[%{NAME} %{FILENAMES}\n]" \ --dbpath ${input_dirname} | sort -u | sed -e 's/[^ ]* //' | ${bin_dir}/swab_testf } function process_dpkg { dpkg-query -W \ --showformat="\${Package} \${Version} 0 \${Architecture}\n" \ --admindir=${input_dirname} > ${output_dirname}/packages ls -d1 ${input_dirname}/info/*.list | while read pkg_path ; do echo "# ${output_dirname}/"`basename ${pkg_path}` cat ${pkg_path} done | ${bin_dir}/swab_testf } function detect_distro { HOST=`grep 'openSUSE\|Fedora\| SUSE\|Red Hat\|Ubuntu' /etc/issue| sed 's/.*\(openSUSE\|Fedora\| SUSE\|Red Hat\|Ubuntu\).*/\1/'` if [ -z "$HOST" ];then echo unable to determine host type exit 1 fi TEMP=`mktemp` if [ "$HOST" = "Ubuntu" ]; then NEWEST=10.04 VER=`cat /etc/issue|head -n1 | awk '{print $2}'` dpkg-query -l > $TEMP if [ $? != 0 ];then echo package listing failed exit 1 fi elif [ "$HOST" = "Fedora" ]; then NEWEST=11 VER=`cat /etc/issue|head -n1 | awk '{print $3}'` HOST="fedora" rpm -qa > $TEMP if [ $? != 0 ];then echo package listing failed exit 1 fi elif [ "$HOST" = "Red Hat" ]; then HOST="redhat" release_ver=`rpm -q --queryformat "%{VERSION}" redhat-release` MAJOR="?" if [ `echo ${release_ver} | grep 4` ] ; then MAJOR="4" MINOR=`cat /etc/issue|head -n1 | sed 's/.*\([0-9]\))/\1/'` elif [ `echo ${release_ver} | grep 5` ] ; then MAJOR="5" MINOR=`cat /etc/redhat-release | sed -e "s/^.*\.//" -e "s/ .*$//"` fi VER="${MAJOR}.${MINOR}" elif [ "$HOST" = " SUSE" ]; then NEWEST=11.0 HOST="SLED" VER=`grep SUSE /etc/issue|head -n1 | awk '{print $7}'` if [ "$VER" = "10" ];then VER=10.2 fi rpm -qa > $TEMP if [ $? != 0 ];then echo package listing failed exit 1 fi elif [ "$HOST" = "openSUSE" ]; then NEWEST=11.2 VER=`grep SUSE /etc/issue|head -n1 | awk '{print $4}'` if [ "$VER" = "10" ];then VER=10.2 fi rpm -qa > $TEMP if [ $? != 0 ];then echo package listing failed exit 1 fi else echo unknown host type -- $HOST exit 1 fi W=`tail -n1 /proc/kallsyms |awk '{print $1}'|wc -c` WIDTH=`echo "($W-1)*4"|bc` echo $HOST-$VER-${WIDTH} } function regenerate_blob { echo Reading package directory from ${input_dirname}, writing out to ${output_dirname} mkdir -p ${output_dirname} || \ ( echo "Could not create output directory ${output_dirname}" ; exit ) if [ ${rpm} -eq 1 ] ; then echo Looks like an RPM distribution to me... process_rpm fi if [ ${dpkg} -eq 1 ] ; then echo Looks like a dpkg distribution to me... process_dpkg fi echo ${distro_name} > ${output_dirname}/distro blob_file=${distro_dir}/distro.blob ${bin_dir}/load_distro -d ${output_dirname} echo ${md5} > ${md5_file} } distro_name=`detect_distro` echo "Distribution is ${distro_name}" if [ "X${input_dirname}" != "X" ] ; then rpm_dir=${input_dirname} dpkg_dir=${input_dirname} fi if [ -f ${rpm_dir}/Packages ] ; then input_dirname=${rpm_dir} rpm=1 else if [ -f ${dpkg_dir}/status ] ; then input_dirname=${dpkg_dir} dpkg=1 else echo Could not identify distribution. exit 1 fi fi md5_file=${output_dirname}/md5 md5=`ls -lR ${input_dirname} | md5sum | cut -f 1 -d " " ` existing_md5=`cat ${md5_file} 2> /dev/null` if [ ! "X${md5}" == "X${existing_md5}" ] ; then echo Regenerating regenerate_blob else echo Existing cache can be used fi rm -f ${output_dirname}/*list