#!/bin/bash
# LOAD Functions and common vars
source ./func.sh
# ssh-agent /bin/bash -c " << EOF
# ssh-add ~/.ssh/id_rsa_git
if ! ssh -T -o PasswordAuthentication=no git@.... 1> /dev/null;
then
echo " *** Dont forget to run the ssh-agent and ssh-add command before running this script "
echo " commands: "
echo "
ssh-agent /bin/bash
ssh-add ~/.ssh/id_rsa_git
";
exit 255;
fi
# read source and target repo from config.txt
# clone source remopo to some place (temp folder)
# see if there is a folder with target repo
# if not - make git clone
# if there is a folder with target repo - make git pull in this repo
# remove .git dir from source repo folder
# if in source repo folder common folder exists remove common/.git folder and .gitmodules file
# copy files (except .git folder) from source repo folder to target repo folder
# commit the changes in target repo
# push changes to target repo
CONFIG_FILE="$PWD/config.txt"
WORKING_DIR="$PWD/tmp$$";
cd tmp
mkdir $$
cd $$
set -x
for reg in `cat $CONFIG_FILE`;
do
echo $reg
set +x
set -x
SRC_REPO=`echo $reg | awk -F\; '{print $1}'`;
DEST_REPO=`echo $reg | awk -F\; '{print $2}'`;
TMP_FOLDER=`echo $SRC_REPO | awk -F\/ '{print $NF}'`;
TMP_DEST_FOLDER=`echo $DEST_REPO | awk -F\/ '{print $NF}' | sed 's/\.git//g'`;
echo "$SRC_REPO|$DEST_REPO|$TMP_FOLDER|$TMP_DEST_FOLDER";
echo "***********************************************"
echo " Source Repo: $SRC_REPO\t "
echo "Destination Repo: $DEST_REPO\n\n"
cd $WORKING_DIR;
git clone --recursive $SRC_REPO;
test_return "git clone $SRC_REPO";
cd $TMP_FOLDER;
test_return "cd $TMP_FOLDER";
rm -fR .git
test_return "rm .git in $TMP_FOLDER";
if [ -d common/.git ];
then
rm -fR common/.git;
rm .gitmodules
fi
cd ..
git clone $DEST_REPO;
test_return "git clone $DEST_REPO";
cd $TMP_DEST_FOLDER
test_return "changing directory into $DEST_REPO";
cp -pR ../$TMP_FOLDER/* .;
test_return "error in cp from $SRC_REPO to $DEST_REPO";
git add .;
git commit -m "Automatic update $$";
echo "|$?|";
echo "############################################"
echo " GIT STATUS "
git status;
echo "############################################"
git push origin master;
echo "|$?|";
echo "***********************************************\n\n"
cd ..
done