root/build-tools/patch_rebase_2

149 lines
4.0 KiB
Bash
Executable File

#!/bin/bash
#
# Update srpm_path for packages to be upgraded
#
usage () {
echo ""
echo "Step 2: Update srpm_path for packages to be upgraded"
echo ""
echo "Usage: "
echo " patch_rebase_2 [--origin_branch <branch>] [--working_branch <branch>] [--upversion_data <file>]"
echo ""
echo "Assumes cgcs-centos-repo already has a working_branch commit that sets the new symlinks."
echo ""
echo "The upversion_data file has data on all the src.rpm being updated in the format:"
echo " export UPVERSION_DATA=$MY_WORKSPACE/upversion.log"
echo " PKG=lighttpd"
echo " OLD_SRC_RPM=lighttpd-1.4.41-1.el7.src.rpm"
echo " NEW_SRC_RPM=lighttpd-1.4.41-2.el7.src.rpm"
echo " SRPM_PATH=$MY_REPO/addons/wr-cgcs/layers/cgcs/recipes-extended/lighttpd/centos/srpm_path"
echo " echo \"\$PKG#\$SRPM_PATH##\$OLD_SRC_RPM#\$NEW_SRC_RPM\" > UPVERSION_DATA"
echo ""
}
TEMP=`getopt -o h --long origin_branch:,working_branch:,upversion_data:,help -n 'test.sh' -- "$@"`
eval set -- "$TEMP"
ORIGIN_BRANCH=""
WORKING_BRANCH=""
UPVERSION_LOG=""
HELP=0
while true ; do
case "$1" in
--origin_branch) shift ; ORIGIN_BRANCH="$1" ; shift ;;
--working_branch) shift ; WORKING_BRANCH="$1" ; shift ;;
--upversion_data) shift ; UPVERSION_LOG="$1" ; shift ;;
-h|--help) HELP=1 ; shift ;;
--) shift ; break ;;
*) usage; exit 1 ;;
esac
done
if [ $HELP -eq 1 ]; then
usage
exit 0
fi
if [ "$UPVERSION_LOG" == "" ]; then
UPVERSION_LOG=$UPVERSION_DATA
fi
if [ "$UPVERSION_LOG" == "" ]; then
echo "ERROR: please specify location of upversion data"
usage
exit 1
fi
if [ ! -f "$UPVERSION_LOG" ]; then
echo "File not found: '$UPVERSION_LOG'"
exit 1
fi
if [ "$ORIGIN_BRANCH" == "" ] && [ "$WORKING_BRANCH" == "" ]; then
ORIGIN_BRANCH=$PATCH_SOURCE_BRANCH
WORKING_BRANCH=$MY_PATCH_BRANCH
fi
if [ "$ORIGIN_BRANCH" == "" ] && [ "$WORKING_BRANCH" == "" ]; then
ORIGIN_BRANCH=$SOURCE_BRANCH
WORKING_BRANCH=$MY_BRANCH
fi
if [ "$ORIGIN_BRANCH" == "" ]; then
echo "ERROR: please specify a origin branch"
usage
exit 1
fi
if [ "$WORKING_BRANCH" == "" ]; then
echo "ERROR: please specify a working branch"
usage
exit 1
fi
# One step back to see the old symlinks
cd $MY_REPO
FAILED=""
for dat in $(cat $UPVERSION_LOG); do
name=$(echo $dat | awk -F '#' '{print $1}')
srpm_path=$(echo $dat | awk -F '#' '{print $2}')
old_src_rpm=$(echo $dat | awk -F '#' '{print $4}')
new_src_rpm=$(echo $dat | awk -F '#' '{print $5}')
(
cd $(dirname $srpm_path)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != "$WORKING_BRANCH" ]; then
git checkout $WORKING_BRANCH
if [ $? -ne 0 ]; then
git checkout $ORIGIN_BRANCH
if [ $? -ne 0 ]; then
echo "ERROR: Can't checkout branch '$ORIGIN_BRANCH' in directory '$(pwd)'"
exit 1
fi
git checkout -b $WORKING_BRANCH
if [ $? -ne 0 ]; then
echo "ERROR: failed to 'git checkout -b $WORKING_BRANCH' from '$(pwd)'"
exit 1
else
echo "created branch '$WORKING_BRANCH' at '$(pwd)'"
fi
fi
fi
sed -i "s#$old_src_rpm#$new_src_rpm#" $srpm_path
if [ $? -ne 0 ]; then
echo "ERROR: sed failed '$old_src_rpm' -> '$new_src_rpm'"
exit 1
else
echo "updated $srpm_path: '$old_src_rpm' -> '$new_src_rpm'"
fi
exit 0
)
if [ $? -ne 0 ]; then
echo "ERROR: failed while working on package '$name' at '$srpm_path'"
exit 1
fi
done
echo ""
for d in $(for dat in $(cat $UPVERSION_LOG); do srpm_path=$(echo $dat | awk -F '#' '{print $2}'); ( cd $(dirname $srpm_path); git rev-parse --show-toplevel ); done | sort --unique); do
(
cd $d
echo "cd $d"
for f in $(git status --porcelain | grep 'srpm_path$' | awk '{print $2}'); do
echo "git add $f";
done
echo "git commit -m 'srpm_path updates for patch $PATCH_ID'"
)
done
echo ""