#!/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"