You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
71 lines
1.9 KiB
#!/bin/bash
|
|
|
|
if [[ -e /var/lock/update-tde-git-submodules ]]; then
|
|
echo "TDE GIT submodules are currently being updated"
|
|
echo "If this is not the case, please remove the lockfile /var/lock/update-tde-git-submodules"
|
|
exit 0
|
|
fi
|
|
|
|
if [[ ! -e .git ]] ||
|
|
[[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then
|
|
echo "Current directory does not contain a .git folder. Exiting..."
|
|
exit 1
|
|
fi
|
|
|
|
branch=`git symbolic-ref -q HEAD | sed "s|^refs/heads/||"`
|
|
if [[ -z "$branch" ]] ||
|
|
[[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
|
|
echo "There is not active upstream branch. Exiting..."
|
|
exit 1
|
|
fi
|
|
|
|
touch /var/lock/update-tde-git-submodules
|
|
|
|
PARENTDIR=$PWD
|
|
echo "Working in $PARENTDIR"
|
|
git pull
|
|
if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
|
|
git reset --hard HEAD
|
|
git clean -dxff
|
|
fi
|
|
|
|
exec 3< submodules
|
|
while read <&3
|
|
do
|
|
cd $PARENTDIR
|
|
DIR2UPDATE=$REPLY
|
|
if [[ $DIR2UPDATE != "" ]]; then
|
|
echo "Attempting to reset submodule $DIR2UPDATE"
|
|
cd $PARENTDIR/$DIR2UPDATE/..
|
|
cd `git rev-parse --show-toplevel`
|
|
if [[ -z "`grep \"^Updated: $PWD$\" /var/lock/update-tde-git-submodules`" ]]; then
|
|
echo "Updated: $PWD" >>/var/lock/update-tde-git-submodules
|
|
git submodule init
|
|
git submodule update
|
|
fi
|
|
cd $PARENTDIR/$DIR2UPDATE
|
|
if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
|
|
git reset --hard HEAD
|
|
git clean -dxff
|
|
fi
|
|
git checkout $branch
|
|
git pull
|
|
cd ..
|
|
cd `git rev-parse --show-toplevel`
|
|
echo "Committing changes to $PWD"
|
|
if [[ ! -z "`git status --porcelain $PARENTDIR/$DIR2UPDATE`" ]]; then
|
|
git add $PARENTDIR/$DIR2UPDATE
|
|
git commit $PARENTDIR/$DIR2UPDATE -m "Reset submodule $DIR2UPDATE to latest HEAD"
|
|
fi
|
|
if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
|
|
git push origin HEAD
|
|
fi
|
|
fi
|
|
done
|
|
exec 3>&-
|
|
|
|
# Let the disk subsystem recover
|
|
sleep 60
|
|
|
|
rm /var/lock/update-tde-git-submodules
|