This repository has been archived on 2025-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
Files
git-dual-sync/sync.sh
Nikolaos Karaolidis 828663e777 Fix permissions
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
2023-03-22 19:15:26 +02:00

43 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
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"
git push --tags $AUTH_URL