#!/usr/bin/env bash set -euo pipefail # ========= CONFIG ========= BASE_DIR="/Users/juanlopezfernandez/Library/CloudStorage/OneDrive-Telefonica/PENTAHO" GITEA_URL="https://gitea.juanlf.synology.me" GITEA_USER="juanlf" GITEA_TOKEN="2d94110d5976464c3c363ad7688095a78e92d7ed" GITEA_ORG="PENTAHO" # si quieres crearlos en una organización, pon su nombre. Si no, déjalo vacío. DEFAULT_BRANCH="main" # ========================== create_repo() { local repo_name="$1" if [[ -n "$GITEA_ORG" ]]; then curl -sS -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ "$GITEA_URL/api/v1/orgs/$GITEA_ORG/repos" \ -d "{\"name\":\"$repo_name\",\"private\":true,\"default_branch\":\"$DEFAULT_BRANCH\"}" >/dev/null else curl -sS -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ "$GITEA_URL/api/v1/user/repos" \ -d "{\"name\":\"$repo_name\",\"private\":true,\"default_branch\":\"$DEFAULT_BRANCH\"}" >/dev/null fi } repo_exists() { local repo_name="$1" if [[ -n "$GITEA_ORG" ]]; then curl -sS \ -H "Authorization: token $GITEA_TOKEN" \ "$GITEA_URL/api/v1/repos/$GITEA_ORG/$repo_name" | grep -q "\"name\":\"$repo_name\"" else curl -sS \ -H "Authorization: token $GITEA_TOKEN" \ "$GITEA_URL/api/v1/repos/$GITEA_USER/$repo_name" | grep -q "\"name\":\"$repo_name\"" fi } remote_url() { local repo_name="$1" if [[ -n "$GITEA_ORG" ]]; then echo "$GITEA_URL/$GITEA_ORG/$repo_name.git" else echo "$GITEA_URL/$GITEA_USER/$repo_name.git" fi } for dir in "$BASE_DIR"/*; do [[ -d "$dir" ]] || continue repo_name="$(basename "$dir")" echo "Procesando: $repo_name" if [[ ! -d "$dir/.git" ]]; then git -C "$dir" init -b "$DEFAULT_BRANCH" fi if ! repo_exists "$repo_name"; then echo " Creando repo en Gitea..." create_repo "$repo_name" else echo " El repo ya existe en Gitea" fi if ! git -C "$dir" remote get-url origin >/dev/null 2>&1; then git -C "$dir" remote add origin "$(remote_url "$repo_name")" else echo " origin ya existe" fi git -C "$dir" add . if ! git -C "$dir" diff --cached --quiet || ! git -C "$dir" diff --quiet; then git -C "$dir" commit -m "Initial import" || true fi git -C "$dir" push -u origin "$DEFAULT_BRANCH" || true echo " OK" done