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