root/build-tools/mirror_rebase/link_cgcs_centos_repo_4

177 lines
5.8 KiB
Bash
Executable File

#!/bin/bash
#
# Part of the monthly mirror update
#
# Update symlinks in cgcs-centos-repo to point to the latest version of packages in /import/mirrors/CentOS/tis-r5-CentOS/newton
#
# This step removes obsolete Binary links
#
cd $MY_REPO/cgcs-centos-repo
MIRROR_ROOT=/import/mirrors/CentOS/tis-r5-CentOS/newton
BIN_ROOT=$MIRROR_ROOT/Binary
SRC_ROOT=$MIRROR_ROOT/Source
cd $MY_REPO/cgcs-centos-repo
if [ $? -ne 0 ]; then
echo 'ERROR: failed to cd to $MY_REPO/cgcs-centos-repo'
return 1
fi
for dat in $(for br in $(find Binary -name '*.rpm' | grep -v '.src.rpm$' ); do
d=$(dirname $br)
b=$(basename $br)
s=$(echo $b | sed -e 's#.centos.#.#' -e 's#.el7.#.#' -e 's#.el7_##' -e 's#.rpm$##' -e 's#.src$##' -e 's#.noarch$##' -e 's#.x86_64$##')
echo "$s#$b#$d"
done | sort -r -V)
do
b=$(echo "$dat" | awk -F '#' '{ print $2 }')
d=$(echo "$dat" | awk -F '#' '{ print $3 }')
r="$d/$b"
name=$(rpm -q --nosignature --queryformat '%{NAME}\n' -p $r)
link=$(readlink $r)
sb=$(rpm -q --info --nosignature -p $r | grep '^Source RPM : ' | sed 's#^Source RPM : ##')
if [ "x$sb" == "x" ]; then
echo "ERROR: no source rpm listed for '$b'"
continue
fi
s=$(find Source -name "$sb")
if [ "x$s" == "x" ]; then
DELETED=0
altname=$(echo $name | sed 's#^python-#python2-#')
if [ "$altname" != "$name" ]; then
# look for python2 alternative
for dat2 in $(for br in $(find $BIN_ROOT -name "$altname-*.rpm" | grep -v '.src.rpm$' | grep -v '[-]debuginfo-'); do
ddd=$(dirname $br)
bbb=$(basename $br)
sss=$(echo $bbb | sed -e 's#.centos.#.#' -e 's#.el7.#.#' -e 's#.el7_##' -e 's#.rpm$##' -e 's#.src$##' -e 's#.noarch$##' -e 's#.x86_64$##')
echo "$sss#$bbb#$ddd"
done | sort -r -V)
do
b2=$(echo "$dat2" | awk -F '#' '{ print $2 }')
d2=$(echo "$dat2" | awk -F '#' '{ print $3 }')
r2="$d2/$b2"
name2=$(rpm -q --nosignature --queryformat '%{NAME}\n' -p $r2)
if [ "$name2" != "$altname" ]; then
continue
fi
sb2=$(rpm -q --info --nosignature -p $r2 | grep '^Source RPM : ' | sed 's#^Source RPM : ##')
if [ "$sb" == "$sb2" ]; then
continue
fi
sbs=$(echo $sb | sed -e 's#.centos.#.#' -e 's#.el7.#.#' -e 's#.el7_##' -e 's#.rpm$##' -e 's#.src$##' -e 's#.noarch$##' -e 's#.x86_64$##')
sbs2=$(echo $sb2 | sed -e 's#.centos.#.#' -e 's#.el7.#.#' -e 's#.el7_##' -e 's#.rpm$##' -e 's#.src$##' -e 's#.noarch$##' -e 's#.x86_64$##')
newer=$((echo $sbs; echo $sbs2) | sort -r -V | head -n 1)
if [ "$sbs" != "$sbs2" ]; then
if [ "$newer" == "$sbs2" ]; then
# swap alternate for original
echo "SUGGEST: rm $r"
git rm -f $r
DELETED=1
fi
fi
done
fi
if [ $DELETED -eq 0 ]; then
echo "ERROR: no source rpm '$sb' found for '$b'"
echo "SUGGEST: rm $r"
git rm -f $r
continue
fi
fi
done
#
# The following would delete all binary rpms that Titanium Cloud would otherwise compile.
# However for bootstrapping the build there are some packages that we must have...
# e.g. bash, kernel-headers, ....
# So we will need something smarter than to just delete everything.
#
# TMP_DIR=$(mktemp -d /tmp/link_cgcs_centos_repo_XXXXXX)
#
# BUILT_SRPMS_FILE=$TMP_DIR/built_srpms_file
#
# for r in $(for c in $(find $MY_REPO -type d -name centos); do
# for sp in $(find $c -name srpm_path); do
# echo "$sp: $(cat $sp)"
# done
# done | grep 'mirror:' | awk -F ' ' '{ print $2 }') ; do
# b=$(basename $r)
# s=$(find $MY_REPO/cgcs-centos-repo/Source/ -name $b)
# n=$(rpm -q --qf '%{NAME}' --nosignature -p $s)
# echo "$n:$b" >> $BUILT_SRPMS_FILE
# done
#
# cd $MY_REPO/cgcs-centos-repo
#
# for r in $(find Binary -name '*.rpm'); do
# b=$(basename $r)
# sb=$(rpm -q --info --nosignature -p $r | grep '^Source RPM :' | sed 's#^Source RPM : ##')
# if [ "x$sb" != "x" ]; then
# s=$(find Source/ -name $sb)
# if [ "x$s" != "x" ]; then
# n=$(rpm -q --qf '%{NAME}' --nosignature -p $s)
# grep "^$n:" $BUILT_SRPMS_FILE
# if [ $? -eq 0 ]; then
# git rm -f $r
# fi
# fi
# fi
# done
#
# \rm $BUILT_SRPMS_FILE
# rmdir $TMP_DIR
TMP_DIR=$(mktemp -d /tmp/link_cgcs_centos_repo_XXXXXX)
EXCLUDE_LIST=$TMP_DIR/exclude_list
# List od packages we compile from scratch, not from centos srpm, goes to $EXCLUDE_LIST
for g in $(find $MY_REPO -type d -name .git); do
d=$(dirname $g)
for cpd in $(find $d -maxdepth 1 -name 'centos_pkg_dir*'); do
(
cd $d
for pd in $(cat $cpd); do
(
cd $pd/centos
if [ -f srpm_path ]; then
continue
fi
for spec in $(find . -name '*.spec'); do
n=$(spec_find_tag 'name' $spec '/tmp/' '0' 2> /dev/null)
echo "$spec: $n"
echo $n >> $EXCLUDE_LIST
done
)
done
)
done
done
cd $MY_REPO/cgcs-centos-repo
for r in $(find Binary -name '*.rpm'); do
s=$(rpm -q --info --nosignature -p $r | grep '^Source RPM' | sed 's#^Source RPM ..##')
n=$(rpm -q --nosignature --qf '%{NAME}' -p $(find Source -name $s) )
grep "^$n$" $EXCLUDE_LIST
if [ $? -eq 0 ]; then
echo "rm $r"
git rm $r
fi
done
\rm -r $TMP_DIR
echo "REMINDER: inspect changes in $MY_REPO/cgcs-centos-repo and commit with ..."
echo ' TIMESTAMP=$(date +"%Y-%m-%d")'
echo ' git commit -m "JENKINS: repo update $TIMESTAMP"'