From 0ea220081fac85da881f21e2524abe134c4a8cd3 Mon Sep 17 00:00:00 2001 From: Michael Schapira Date: Fri, 3 Apr 2026 18:18:47 +0000 Subject: [PATCH] Add push_to_gitea.sh helper --- push_to_gitea.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 push_to_gitea.sh diff --git a/push_to_gitea.sh b/push_to_gitea.sh new file mode 100755 index 0000000..dbf22a1 --- /dev/null +++ b/push_to_gitea.sh @@ -0,0 +1,85 @@ +#!/bin/env bash +# +# push_to_gitea.sh - Push script to Gitea instance +# +# Setup once: export GITEA_USER="your-username" and GITEA_TOKEN="your-git-token" +# + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_DIR="${SCRIPT_DIR}" + +# Default Gitea URL +# Get it from your IBM Gitea instance +GITEA_URL="${GITEA_URL:-https://gitea.corp-softy.ibm.com}" + +GITEA_USER="${GITEA_USER:-michael}" +GITEA_TOKEN="${GITEA_TOKEN:-}" + +# Create .gitconfig for this repo +create_config() { + cat > "${REPO_DIR}/.gitconfig" << 'EOF' +[remote "gitea"] + url = https://${GITEA_TOKEN}@${GITEA_URL}/corporate-softy/cpd-cli-update-script.git + fetch = +refs/heads/*:refs/remotes/origin/* + +# If you want to push to personal fork: +# url = https://${GITEA_TOKEN}@${GITEA_URL}/${GITEA_USER}/cpd-cli-update-script.git +EOF +} + +# Setup +setup() { + if [[ ${GITEA_TOKEN} == "" ]]; then + echo "No GITEA_TOKEN set" | tee -a /tmp/cpd-cli-push-$(date +"%Y-%m-%d-%H-%M-%S").log 1 + read -p "Press enter to cancel, or paste GITEA_TOKEN:" token + export GITEA_TOKEN="${token:-}" + fi + + if [[ ${GITEA_TOKEN} == "" ]]; then + echo "Exiting without GITEA_TOKEN. Please set export GITEA_TOKEN='your-token'" + exit 1 + fi + + config_exists="${REPO_DIR}/.gitconfig" + if [[ ! -f "${config_exists}" ]] || [[ ! $(grep -i ${GITEA_URL} "${config_exists}" 2>/dev/null || echo "") ]]; then + echo "Creating .gitconfig" | tee -a /tmp/cpd-cli-push-$(date +"%Y-%m-%d-%H-%M-%S").log 1 + create_config + fi +} + +# Fetch first +fetch() { + git fetch gitea + echo "Fetched from ${GITEA_URL}" | tee -a /tmp/cpd-cli-push-$(date +"%Y-%m-%d-%H-%M-%S").log 1 +} + +# Add and push +add_push() { + git add -A + local changes + changes=$(git diff-index --quiet HEAD -- || git status -s 2>/dev/null || echo '') + + if [[ -z "$changes" ]]; then + echo "No changes to commit" | tee -a /tmp/cpd-cli-push-$(date +"%Y-%m-%d-%H-%M-%S").log 1 + exit 0 + fi + + git commit -m "Automated update from script" + git push gitea master + echo "Pushed to gitea!" | tee -a /tmp/cpd-cli-push-$(date +"%Y-%m-%d-%H-%M-%S").log 1 +} + +# Main +main() { + echo "Pushing to GitHub: ${GITEA_URL}/${GITEA_USER}/cpd-cli-update-script" + echo "" + setup + fetch + add_push + echo "" + echo "Done!" | tee -a /tmp/cpd-cli-push-$(date +"%Y-%m-%d-%H-%M-%S").log 1 +} + +main "$@"