From a774497248febb00b55ed3ed3bad6d0c2c1d7ce3 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Sun, 25 Aug 2019 23:31:25 +0400 Subject: [PATCH 1/3] squelette --- repoctl | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100755 repoctl diff --git a/repoctl b/repoctl new file mode 100755 index 0000000..1a603c0 --- /dev/null +++ b/repoctl @@ -0,0 +1,127 @@ +#!/bin/bash +# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 +source "$(dirname "$0")/lib/ulib/ulib" || exit 1 +urequire DEFAULTS + +function display_help() { + uecho "$scriptname: piloter un serveur git (gitolite, gogs, gitea, etc.) + +USAGE + $scriptname ACTION [options] + +ACTIONS + create URL [description] + Créer un nouveau dépôt avec la description spécifiée + + list [ORG] + Lister les dépôts dans l'organisation spécifiée. Par défaut, lister les + dépôts de l'utilisateur + + move URL ORG[/NAME] + Déplacer le dépôt spécifié dans l'organisation spécifiée. Le cas + échéant, le dépôt est renommé + + delete URL + Supprimée le dépôt spécifié. + +OPTIONS" +} + +function repo_init() { + repourl="${1%.git}" + [ -n "$repourl" ] || return + rname= + rtype=gitolite + rprefix= + + REPO_PREFIXES=() + REPO_TYPES=() + set_defaults pcrone + + # Traduire les aliases éventuels + local asrcdest asrc adest + for asrcdest in "${REPO_PREFIXES[@]}"; do + splitfsep "$asrcdest" = asrc adest + if [ "${repourl#$asrc}" != "$repourl" ]; then + newurl="$adest${repourl#$asrc}" + if [ "$newurl" != "$repourl" ]; then + enote "$repourl --> $newurl" + repourl="$newurl" + break + fi + fi + done + + local rnametypeprefix tmp found + for rnametypeprefix in "${REPO_TYPES[@]}"; do + splitfsep "$rnametypeprefix" : rname tmp + splitfsep "$tmp" : rtype rprefix + if [ "${repourl#$rprefix}" != "$repourl" ]; then + found=1 + break + fi + done + if [ -z "$found" ]; then + rname= + rtype=gitolite + rprefix= + fi +} + +function curlto() { + local url="$1"; shift + local payload="$1"; shift + local outfile="$1"; shift + local tmpfile + if [ -z "$outfile" ]; then + ac_set_tmpfile tmpfile + outfile="$tmpfile" + fi + + local -a args + local r http_code + args=(-s -w '%{http_code}' -o "$outfile") + [ -n "$payload" ] && args+=(-d "$payload") + args+=("$@" "$url") + setx http_code=curl "${args[@]}" + + case "$http_code" in + 2*) r=0;; + 4*) r=1;; + 5*) r=3;; + *) r=11;; + esac + if [ -n "$tmpfile" ]; then + cat "$tmpfile" + ac_clean "$tmpfile" + fi + + upvar http_code "$http_code" + return "$r" +} + +action= +args=( + --help '$exit_with display_help' + -c,--create action=create + -l,--list action=list + -m,--move action=move + -d,--delete action=delete +) +parse_args "$@"; set -- "${args[@]}" + +if [ -z "$action" ]; then + action="$1"; shift +fi +[ -n "$action" ] || action=list + +case "$action" in +c|create) + ;; +l|list) + ;; +m|move) + ;; +d|del|delete|rm|remove) + ;; +esac From 914f635fe18a337496ff9d1081fac16b36a92263 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 11 Sep 2019 22:16:07 +0400 Subject: [PATCH 2/3] =?UTF-8?q?impl=C3=A9mentation=20initiale=20de=20creat?= =?UTF-8?q?e,=20list,=20delete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/default/{pcrone => repoctl} | 12 +- lib/repoctl/json_build.php | 27 +++++ lib/repoctl/json_each.php | 28 +++++ lib/repoctl/json_get.php | 27 +++++ repoctl | 195 ++++++++++++++++++++++++++++---- 5 files changed, 262 insertions(+), 27 deletions(-) rename lib/default/{pcrone => repoctl} (77%) create mode 100755 lib/repoctl/json_build.php create mode 100755 lib/repoctl/json_each.php create mode 100755 lib/repoctl/json_get.php diff --git a/lib/default/pcrone b/lib/default/repoctl similarity index 77% rename from lib/default/pcrone rename to lib/default/repoctl index f64e5ae..73ae148 100644 --- a/lib/default/pcrone +++ b/lib/default/repoctl @@ -1,13 +1,15 @@ # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 # Liste de préfixes permettant de taper le nom d'un dépôt plus rapidement e.g -# pcrone g/ssi-php/myproj -# pcrone v:modules/myproj +# repoctl g/ssi-php/myproj +# repoctl v:modules/myproj # sont équivalents à -# pcrone https://git.univ-reunion.fr/ssi-php/myproj -# pcrone git@vcs.univ.run:modules/myproj -# Ces définitions fonctionnent aussi pour pclone +# repoctl https://git.univ-reunion.fr/ssi-php/myproj +# repoctl git@vcs.univ.run:modules/myproj # Le format est ALIAS=ACTUAL +# +# Ces définitions fonctionnent aussi pour tous les scripts qui utilisent +# repoctl, dont notamment pclone et pcrone REPO_PREFIXES=( s:=git@git.univ-reunion.fr: g/=https://git.univ-reunion.fr/ diff --git a/lib/repoctl/json_build.php b/lib/repoctl/json_build.php new file mode 100755 index 0000000..0106b58 --- /dev/null +++ b/lib/repoctl/json_build.php @@ -0,0 +1,27 @@ +#!/usr/bin/php + Date: Sat, 28 Sep 2019 12:33:03 +0400 Subject: [PATCH 3/3] =?UTF-8?q?support=20limit=C3=A9=20de=20pcrone=20et=20?= =?UTF-8?q?pclone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/default/repoctl | 10 ++++++---- uproject | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/default/repoctl b/lib/default/repoctl index 73ae148..cea1682 100644 --- a/lib/default/repoctl +++ b/lib/default/repoctl @@ -1,11 +1,11 @@ # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 # Liste de préfixes permettant de taper le nom d'un dépôt plus rapidement e.g -# repoctl g/ssi-php/myproj -# repoctl v:modules/myproj +# repoctl create g/ssi-php/myproj +# repoctl create v:modules/myproj # sont équivalents à -# repoctl https://git.univ-reunion.fr/ssi-php/myproj -# repoctl git@vcs.univ.run:modules/myproj +# repoctl create https://git.univ-reunion.fr/ssi-php/myproj +# repoctl create git@vcs.univ.run:modules/myproj # Le format est ALIAS=ACTUAL # # Ces définitions fonctionnent aussi pour tous les scripts qui utilisent @@ -15,6 +15,7 @@ REPO_PREFIXES=( g/=https://git.univ-reunion.fr/ v:=git@vcs.univ.run: av/=https://vcs.univ-reunion.fr/anongit/ p:=pgit@vcs.univ.run: ap/=https://pvcs.univ-reunion.fr/anongit/ + j/=https://git.jclain.fr/ ) # Définitions des types de dépôt. Le format est NAME:TYPE:PREFIX @@ -23,6 +24,7 @@ REPO_PREFIXES=( # type par défaut est 'gitolite' REPO_TYPES=( ur:gitea:https://git.univ-reunion.fr/ + jclain:gitea:https://git.jclain.fr/ ) # Configuration de l'accès à l'API gogs diff --git a/uproject b/uproject index 8e81620..40f8764 100755 --- a/uproject +++ b/uproject @@ -250,7 +250,7 @@ function cxone_init() { REPO_PREFIXES=() REPO_TYPES=() - set_defaults pcrone + set_defaults repoctl # Traduire les aliases éventuels local asrcdest asrc adest