#!/bin/bash # # SCARICA I PROGETTI A CUI HAI ACCESSO SU GITEA. # # ./progetti.sh # elenca e chiede quali scaricare # ./progetti.sh nome1 nome2 # scarica questi # # Li mette in $CARTELLA_PROGETTI (di solito ~/Work/workspace/oto). Un progetto # gia' scaricato non si tocca. Vedi solo i repository che l'amministratore ti # ha dato: se ne manca uno, e' da chiedere a lui. set -u cd "$(dirname "$0")" || exit 1 . ./comune.sh TOKEN="$(token_gitea)" if [ -z "$TOKEN" ] || [ -z "$(utente_gitea)" ] ; then male "token Gitea mancante o non valido: lancia prima ./configura.sh" exit 1 fi # Tutti i repository visibili, pagina per pagina. ELENCO="" PAGINA=1 while : ; do BLOCCO="$(curl -s --max-time 15 -H "Authorization: token $TOKEN" \ "$GITEA_URL/api/v1/user/repos?limit=50&page=$PAGINA" \ | grep -o '"full_name":"[^"]*"' | sed 's/"full_name":"\(.*\)"/\1/')" [ -z "$BLOCCO" ] && break ELENCO="$ELENCO $BLOCCO" PAGINA=$((PAGINA + 1)) done ELENCO="$(printf '%s\n' "$ELENCO" | grep -v '^$' | grep -v '/_OTO_IT_onboard$' | sort -u)" if [ -z "$ELENCO" ] ; then attento "non vedi ancora nessun progetto: chiedi all'amministratore di aggiungerti ai repository" exit 0 fi if [ "$#" -gt 0 ] ; then SCELTI="$*" else titolo "Progetti che puoi scaricare" printf '%s\n' "$ELENCO" | sed 's#.*/##' | nl -w3 -s'. ' echo read -r -p "Numeri o nomi, separati da spazio (invio = nessuno, 'tutti' = tutti): " RISPOSTA [ -z "$RISPOSTA" ] && exit 0 if [ "$RISPOSTA" = "tutti" ] ; then SCELTI="$(printf '%s\n' "$ELENCO" | sed 's#.*/##')" else SCELTI="" for R in $RISPOSTA ; do case "$R" in *[!0-9]*) SCELTI="$SCELTI $R" ;; *) SCELTI="$SCELTI $(printf '%s\n' "$ELENCO" | sed -n "${R}p" | sed 's#.*/##')" ;; esac done fi fi mkdir -p "$CARTELLA_PROGETTI" titolo "Scarico in $CARTELLA_PROGETTI" for NOME in $SCELTI ; do COMPLETO="$(printf '%s\n' "$ELENCO" | grep -E "/$NOME\$" | head -n 1)" if [ -z "$COMPLETO" ] ; then male "$NOME: non lo vedi su Gitea" continue fi if [ -d "$CARTELLA_PROGETTI/$NOME/.git" ] ; then ok "$NOME: gia' scaricato" continue fi if git clone -q "$GITEA_URL/$COMPLETO.git" "$CARTELLA_PROGETTI/$NOME" ; then ok "$NOME" else male "$NOME: git clone non riuscito" fi done echo echo " In ogni progetto: ./start.sh (progetti con pannello) oppure bin/local-init.sh" echo " (Drupal e WordPress). Apri claude nella cartella del progetto: ti spiega il resto."