Initial commit

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2023-03-22 18:02:55 +02:00
commit 992214329c
3 changed files with 77 additions and 0 deletions

41
sync.sh Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/bash
if [ -z "$GIT_ORIGIN" ] || [ -z "$GIT_UPSTREAM" ] || [ -z "$GIT_BRANCH" ] || [ -z "$GIT_NAME" ] || [ -z "$GIT_EMAIL" ] || [ -z "$GIT_USER" ] || [ -z "$GIT_PASS" ]; then
echo "Environment variables not set"
exit 1
fi
git config --global user.name "$GIT_NAME"
git config --global user.email "$GIT_EMAIL"
PLAIN_URL=$(echo "$GIT_ORIGIN" | sed 's/https:\/\///')
AUTH_URL="https://$GIT_USER:$GIT_PASS@$PLAIN_URL"
WORKDIR="./git"
mkdir -p "$WORKDIR"
if [ ! -d "$WORKDIR/.git" ]; then
echo "Cloning repo"
git clone "$AUTH_URL" "$WORKDIR"
fi
cd "$WORKDIR"
if [ -z "$(git remote | grep origin)" ]; then
git remote add origin "$GIT_ORIGIN"
elif [ "$(git config --get remote.origin.url)" != "$GIT_ORIGIN" ]; then
git remote set-url origin "$GIT_ORIGIN"
fi
if [ -z "$(git remote | grep upstream)" ]; then
git remote add upstream "$GIT_UPSTREAM"
elif [ "$(git config --get remote.upstream.url)" != "$GIT_UPSTREAM" ]; then
git remote set-url upstream "$GIT_UPSTREAM"
fi
git fetch origin
git fetch upstream
git pull origin "$GIT_BRANCH"
git checkout "$GIT_BRANCH"
git merge upstream/"$GIT_BRANCH" --no-edit
git push $AUTH_URL "$GIT_BRANCH"