root/build-tools/mirror_rebase/link_cgcs_centos_repo_9
Dean Troyer cfe45dadae StarlingX open source release updates
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
2018-06-01 07:45:23 -07:00

347 lines
12 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
#
# Search for tis patched centos src.rpm's that have been upversioned
#
UPVERSION_LOG=$MY_WORKSPACE/upversion.log
if [ "x$WORKING_BRANCH" == "x" ]; then
WORKING_BRANCH=CGCS_DEV_0029_rebase_7_4
fi
if [ ! -f $UPVERSION_LOG ]; then
echo "ERROR: Can't find UPVERSION_LOG at '$UPVERSION_LOG'"
fi
if [ "$DISPLAY" == "" ]; then
echo "ERROR: X-Windows 'DISPLAY' variable not set. This script needs to open pop-up windows."
usage
exit 1
fi
# restore new symlinks
cd $MY_REPO/cgcs-3rd-party-repo
git checkout $WORKING_BRANCH
if [ $? != 0 ]; then
echo "ERROR: Can't checkout branch '$WORKING_BRANCH' in directory '$MY_REPO/cgcs-3rd-party-repo'"
exit 1
fi
cd $MY_REPO/cgcs-centos-repo
git checkout $WORKING_BRANCH
if [ $? != 0 ]; then
echo "ERROR: Can't checkout branch '$WORKING_BRANCH' in directory '$MY_REPO/cgcs-centos-repo'"
exit 1
fi
FAILED=""
build_types="std rt"
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}')
PKG_DIR=$(dirname $(dirname $srpm_path))
OLD_BRANCH=$(echo $old_src_rpm | sed 's#[.]src[.]rpm$##')
NEW_BRANCH=$(echo $new_src_rpm | sed 's#[.]src[.]rpm$##')
WORK_META_DIR=""
for dd in $build_types; do
WORK_META_DIR=$MY_WORKSPACE/$dd/srpm_work/$name/rpmbuild
echo "WORK_META_DIR=$WORK_META_DIR"
if [ -d $WORK_META_DIR ]; then
break;
else
WORK_META_DIR=""
fi
done
if [ "$WORK_META_DIR" == "" ]; then
echo "ERROR: failed to find srpm_work directory for '$name'"
exit 1
fi
# WORK_SRC_DIR=$(dirname $(find $MY_WORKSPACE/srpm_work/$name/gits/ -type d -name .git))
NEW_WORK_SRC_DIR=""
OLD_WORK_SRC_DIR=""
for dd in $build_types; do
for g in $(find $MY_WORKSPACE/$dd/srpm_work/$name/gits/ -type d -name .git); do
d=$(dirname $g)
if [ -d $d ]; then
cd $d;
git tag | grep pre_wrs_ >> /dev/null
if [ $? -ne 0 ]; then
continue
fi
git checkout $OLD_BRANCH 2>> /dev/null
if [ $? -eq 0 ]; then
OLD_WORK_SRC_DIR=$d
fi
git checkout $NEW_BRANCH 2>> /dev/null
if [ $? -eq 0 ]; then
NEW_WORK_SRC_DIR=$d
fi
fi
done
done
if [ "$WORK_META_DIR" == "" ]; then
echo "ERROR: failed to find srpm_work directory for '$name'"
exit 1
fi
echo "$name $old_src_rpm $new_src_rpm"
echo "PKG_DIR=$PKG_DIR"
echo "OLD_BRANCH=$OLD_BRANCH"
echo "NEW_BRANCH=$NEW_BRANCH"
echo "WORK_META_DIR=$WORK_META_DIR"
echo "OLD_WORK_SRC_DIR=$OLD_WORK_SRC_DIR"
echo "NEW_WORK_SRC_DIR=$NEW_WORK_SRC_DIR"
echo ""
(
cd $WORK_META_DIR
if [ $? -ne 0 ]; then
echo "ERROR: failed to cd to WORK_META_DIR=$WORK_META_DIR"
exit 1
fi
echo "--- old meta git log (oldest to newest) ---"
git checkout $OLD_BRANCH
if [ $? -ne 0 ]; then
echo "ERROR: failed to git checkout OLD_BRANCH=$OLD_BRANCH"
exit 1
fi
(git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit ; echo "") | sed '/^$/d' | tac
PATCH_COMMIT_LIST=$((git log --graph --pretty=format:'%h -%d %s (%ci) <%an>' --abbrev-commit ; echo "") | sed '/^$/d' | tac | grep WRS: | grep -v 'WRS: COPY_LIST content' | awk '{ print $2 }')
echo "--- new meta git log (oldest to newest) ---"
git checkout $NEW_BRANCH
if [ $? -ne 0 ]; then
echo "ERROR: failed to git checkout NEW_BRANCH=$NEW_BRANCH"
exit 1
fi
(git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit ; echo "") | sed '/^$/d' | tac
REFERENCE_COMMIT=$((git log --graph --pretty=format:'%h -%d %s (%ci) <%an>' --abbrev-commit ; echo "") | sed '/^$/d' | head -n 1 | awk '{ print $2 }')
echo ""
for COMMIT in ${PATCH_COMMIT_LIST}; do
echo "git cherry-pick $COMMIT"
git --no-pager show "$COMMIT"
git cherry-pick "$COMMIT"
if [ $? -ne 0 ]; then
echo "WARNING: 'git cherry-pick $COMMIT' found merge conflicts. Please fix these files"
git status --porcelain | grep '^UU ' | awk '{ print $2}'
echo "pwd=$(pwd)"
# gitk &
echo "git mergetool --no-prompt"
git mergetool --no-prompt
# for FILE_NAME in $(git status --porcelain | grep '^UU ' | awk '{ print $2}'); do
# xterm -e "vi $FILE_NAME -c '/[<=>][<=>][<=>][<=>]'"
# if [ $? -ne 0 ]; then
# echo "ERROR: problem launching editor on "
# exit 1
# fi
# done
echo "git cherry-pick --continue"
git cherry-pick --continue
fi
done
PATCH_LIST=$(git format-patch -n $REFERENCE_COMMIT)
if [ $? -ne 0 ]; then
echo "ERROR: failed to git format-patch -n REFERENCE_COMMIT=$REFERENCE_COMMIT"
exit 1
fi
for PATCH_FILE in ${PATCH_LIST}; do
PATCH_TARGET=$(echo $PATCH_FILE | sed 's/^[0-9][0-9][0-9][0-9]-WRS-//' | sed 's/.patch$//')
echo "$PATCH_FILE -> $PATCH_TARGET"
N=$(find "$PKG_DIR/centos/meta_patches" -name "$PATCH_TARGET*" | wc -l)
if [ $N -eq 1 ]; then
PATCH_DEST=$(find "$PKG_DIR/centos/meta_patches" -name "$PATCH_TARGET*")
echo "cp -f $PATCH_FILE $PATCH_DEST"
\cp -f $PATCH_FILE $PATCH_DEST
if [ $? -ne 0 ]; then
echo "ERROR: copy failed $WORK_META_DIR/$PATCH_FILE -> $PATCH_DEST"
exit 1
fi
else
echo "ERROR: Don't know what destination file name to use for patch '$WORK_META_DIR/$PATCH_FILE' derived from commit $COMMIT, and to be copied to '$PKG_DIR/centos/meta_patches'"
fi
done
echo ""
echo ""
)
if [ $? -ne 0 ]; then
FAILED=$name
break
fi
(
echo "--- old git log (oldest to newest) ---"
cd $OLD_WORK_SRC_DIR
if [ $? -ne 0 ]; then
echo "ERROR: failed to cd to OLD_WORK_SRC_DIR=$OLD_WORK_SRC_DIR"
exit 1
fi
git checkout $OLD_BRANCH
if [ $? -ne 0 ]; then
echo "ERROR: failed to git checkout OLD_BRANCH=$OLD_BRANCH in directory '$OLD_WORK_SRC_DIR'"
exit 1
fi
(git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit; echo "") | sed '/^$/d' | tac
PATCH_COMMIT_LIST=$((git log --graph --pretty=format:'%h -%d %s (%ci) <%an>' --abbrev-commit; echo "") | sed '/^$/d' | tac | grep WRS: | grep -v 'WRS: COPY_LIST content' | awk '{ print $2 }')
echo "--- new git log (oldest to newest) ---"
cd $NEW_WORK_SRC_DIR
if [ $? -ne 0 ]; then
echo "ERROR: failed to cd to NEW_WORK_SRC_DIR=$NEW_WORK_SRC_DIR"
exit 1
fi
git checkout $NEW_BRANCH
if [ $? -ne 0 ]; then
echo "ERROR: failed to git checkout NEW_BRANCH=$NEW_BRANCH in directory '$NEW_WORK_SRC_DIR'"
exit 1
fi
(git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit; echo "") | sed '/^$/d' | tac
REFERENCE_COMMIT=$((git log --graph --pretty=format:'%h -%d %s (%ci) <%an>' --abbrev-commit ; echo "") | sed '/^$/d' | head -n 1 | awk '{ print $2 }')
echo ""
if [ "$OLD_WORK_SRC_DIR" == "$NEW_WORK_SRC_DIR" ]; then
for COMMIT in ${PATCH_COMMIT_LIST}; do
echo "git cherry-pick $COMMIT"
git --no-pager show "$COMMIT"
git cherry-pick "$COMMIT"
if [ $? -ne 0 ]; then
echo "WARNING: 'git cherry-pick $COMMIT' found merge conflicts. Please fix these files"
git status --porcelain | grep '^UU ' | awk '{ print $2}'
echo "pwd=$(pwd)"
# gitk &
echo "git mergetool --no-prompt"
git mergetool --no-prompt
# for FILE_NAME in $(git status --porcelain | grep '^UU ' | awk '{ print $2}'); do
# xterm -e "vi $FILE_NAME -c '/[<=>][<=>][<=>][<=>]'"
# if [ $? -ne 0 ]; then
# echo "ERROR: problem launching editor on "
# exit 1
# fi
# done
echo "git cherry-pick --continue"
git cherry-pick --continue
fi
done
else
cd $OLD_WORK_SRC_DIR
PATCH_LIST=$(git format-patch -n pre_wrs_$OLD_BRANCH)
if [ $? -ne 0 ]; then
echo "ERROR: failed to git format-patch -n REFERENCE_COMMIT=pre_wrs_$OLD_BRANCH"
exit 1
fi
cd $NEW_WORK_SRC_DIR
for PATCH_FILE in ${PATCH_LIST}; do
echo "=== Apply $PATCH_FILE ==="
cat $OLD_WORK_SRC_DIR/$PATCH_FILE
cat $OLD_WORK_SRC_DIR/$PATCH_FILE | patch -p1
if [ $? -ne 0 ]; then
for REJECT in $(find . -name '*.rej'); do
FILE_NAME=$(echo $REJECT | sed 's#.rej$##')
cd $OLD_WORK_SRC_DIR
gitk $FILE_NAME &
cd $NEW_WORK_SRC_DIR
if [ -f $FILE_NAME ] && [ -f $FILE_NAME.orig ]; then
\cp -f $FILE_NAME.orig $FILE_NAME
xterm -e "vi $FILE_NAME $REJECT"
rm -f $REJECT
rm -f $FILE_NAME.orig
fi
done
fi
git add --all
MSG=$(echo $PATCH_FILE | sed 's/^[0-9][0-9][0-9][0-9]-WRS-//' | sed 's/.patch$//')
git commit -m "WRS: $MSG"
done
fi
PATCH_LIST=$(git format-patch -n $REFERENCE_COMMIT)
if [ $? -ne 0 ]; then
echo "ERROR: failed to git format-patch -n REFERENCE_COMMIT=$REFERENCE_COMMIT"
exit 1
fi
for PATCH_FILE in ${PATCH_LIST}; do
PATCH_TARGET=$(echo $PATCH_FILE | sed 's/^[0-9][0-9][0-9][0-9]-WRS-Patch[0-9]*-//' | sed 's/^[0-9][0-9][0-9][0-9]-WRS-Patch//' | sed 's/.patch$//')
echo "$PATCH_FILE -> $PATCH_TARGET"
PKG_PATCH_DIR="$PKG_DIR/centos/patches"
N=0
if [ -d "$PKG_PATCH_DIR" ]; then
N=$(find "$PKG_PATCH_DIR" -name "$PATCH_TARGET*" | grep -v '[/]meta_patches[/]' | wc -l)
fi
if [ $N -ne 1 ]; then
PKG_PATCH_DIR="$PKG_DIR"
if [ -d "$PKG_PATCH_DIR" ]; then
N=$(find "$PKG_PATCH_DIR" -name "$PATCH_TARGET*" | grep -v '[/]meta_patches[/]' | wc -l)
fi
fi
echo "N=$N"
echo "PKG_PATCH_DIR=$PKG_PATCH_DIR"
if [ $N -eq 1 ]; then
PATCH_DEST=$(find "$PKG_PATCH_DIR" -name "$PATCH_TARGET*" | grep -v '[/]meta_patches[/]')
echo "meld $PATCH_FILE -> $PATCH_DEST"
meld $PATCH_FILE $PATCH_DEST
if [ $? -ne 0 ]; then
echo "ERROR: meld failed $WORK_SRC_DIR/$PATCH_FILE -> $PATCH_DEST"
exit 1
fi
else
echo "ERROR: Don't know what destination file name to use for patch '$OLD_WORK_SRC_DIR/$PATCH_FILE', and to be copied to '$PKG_PATCH_DIR'"
fi
done
echo ""
echo ""
)
if [ $? -ne 0 ]; then
FAILED=$name
break
fi
)
done
if [ "$FAILED" != "" ]; then
echo "Failed for ... $FAILED"
exit 1
fi
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 | awk '{print $2}'); do
echo "git add $f";
done
if [ "$PATCH_ID" == "" ]; then
echo "git commit -m 'rebased patches'"
else
echo "git commit -m 'rebased patches'"
fi
)
done
echo ""