From 4b70501e432eb5fd9ed04a4afbadafabd982e9fc Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 Sep 2014 01:31:14 -0400 Subject: restructure to have most data in YAML --- misc/git-hooks/auto-deploy | 16 ++++++++++++++++ misc/git-hooks/generic | 12 ++++++++++++ misc/git-hooks/hackers-update | 22 ++++++++++++++++++++++ misc/git-shell-commands/change-description | 19 +++++++++++++++++++ misc/git-shell-commands/change-owner | 19 +++++++++++++++++++ misc/git-shell-commands/create-bare-repo | 18 ++++++++++++++++++ misc/git-shell-commands/delete-repo | 17 +++++++++++++++++ misc/git-shell-commands/fetch-mirrors | 13 +++++++++++++ misc/git-shell-commands/help | 12 ++++++++++++ misc/git-shell-commands/hook-install | 28 ++++++++++++++++++++++++++++ misc/git-shell-commands/mirror | 10 ++++++++++ misc/git-shell-commands/mirrors | 9 +++++++++ 12 files changed, 195 insertions(+) create mode 100755 misc/git-hooks/auto-deploy create mode 100755 misc/git-hooks/generic create mode 100755 misc/git-hooks/hackers-update create mode 100755 misc/git-shell-commands/change-description create mode 100755 misc/git-shell-commands/change-owner create mode 100755 misc/git-shell-commands/create-bare-repo create mode 100755 misc/git-shell-commands/delete-repo create mode 100755 misc/git-shell-commands/fetch-mirrors create mode 100755 misc/git-shell-commands/help create mode 100755 misc/git-shell-commands/hook-install create mode 100755 misc/git-shell-commands/mirror create mode 100755 misc/git-shell-commands/mirrors (limited to 'misc') diff --git a/misc/git-hooks/auto-deploy b/misc/git-hooks/auto-deploy new file mode 100755 index 0000000..02a22e7 --- /dev/null +++ b/misc/git-hooks/auto-deploy @@ -0,0 +1,16 @@ +#!/bin/bash +# auto-deploy +# Usage: auto-deploy /srv/http/repo + +# fail on any error +set -e + +# Can we write on the clone? +test -w "${1}/.git/HEAD" + +alias git="git --git-dir '${1}/.git' --work-tree '${1}'" + +# pull this repo on the current branch +git pull origin $(git rev-parse --abbrev-ref HEAD) + +exit $? diff --git a/misc/git-hooks/generic b/misc/git-hooks/generic new file mode 100755 index 0000000..ebf56f4 --- /dev/null +++ b/misc/git-hooks/generic @@ -0,0 +1,12 @@ +#!/bin/sh +# Generic hook, installs itself as a valid githook(5) and runs whatever it +# finds on hacking.hook.$self +# Format: +# hacking.hooks.post-receive.auto-deploy /srv/http/markpower.hackcoop.com.ar + +git config -f config --get-regexp "hacking.hooks.$(basename ${0}).*" | \ +while read hook repo; do + hook="`echo "${hook}" | cut -d'.' -f4`" + + ${HOME}/.ssh/git-hooks/${hook} ${repo} ${@} "${repo}".git/description +else + printf 'Does not exist: %s\n' "${repo}" + exit 1 +fi diff --git a/misc/git-shell-commands/change-owner b/misc/git-shell-commands/change-owner new file mode 100755 index 0000000..6b6f353 --- /dev/null +++ b/misc/git-shell-commands/change-owner @@ -0,0 +1,19 @@ +#!/bin/bash +# * change-owner +# Define quiƩn manda +# ssh git@host change-owner repo "Hacklab" + +set -e + +repo=$1; shift + +repo="$(sed -r 's,^/*,,' <<<"$repo")" +_repo="$(sed -r -e '/(^|\/)\.\.($|\/)/d' -e "s,[^A-Za-z0-9\./_~-],,g" <<<"$repo")" +test "$repo" = "$_repo" || { printf 'Illegal name: %s\n' "${repo}"; exit 1; } + +if test -d "${repo}".git; then + git config -f "${repo}.git/config" "gitweb.owner" "${*}" +else + printf 'Does not exist: %s\n' "${repo}" + exit 1 +fi diff --git a/misc/git-shell-commands/create-bare-repo b/misc/git-shell-commands/create-bare-repo new file mode 100755 index 0000000..b4d2d5f --- /dev/null +++ b/misc/git-shell-commands/create-bare-repo @@ -0,0 +1,18 @@ +#!/bin/bash +# * create-bare-repo +# Allows users to create repo.git +# ssh git@host create-bare-repo repo1 repo2 ... + +set -e + +for repo in "$@"; do + repo="$(sed -r 's,^/*,,' <<<"$repo")" + _repo="$(sed -r -e '/(^|\/)\.\.($|\/)/d' -e "s,[^A-Za-z0-9\./_~-],,g" <<<"$repo")" + test "$repo" != "$_repo" && { printf 'Illegal name: %s\n' "${repo}"; continue; } + test -d "$repo".git && { printf 'Already exists: %s\n' "${repo}"; continue; } + + mkdir -p -- "$repo".git + pushd "$repo".git >/dev/null + git init --bare + popd >/dev/null +done diff --git a/misc/git-shell-commands/delete-repo b/misc/git-shell-commands/delete-repo new file mode 100755 index 0000000..5ef94b1 --- /dev/null +++ b/misc/git-shell-commands/delete-repo @@ -0,0 +1,17 @@ +#!/bin/bash +# * delete-repo +# Allows users to delete repositories permanently +# ssh git@host delete-repo repo1 repo2 ... + +set -e + +for repo in "$@"; do + repo="$(sed -r 's,^/*,,' <<<"$repo")" + _repo="$(sed -r -e '/(^|\/)\.\.($|\/)/d' -e "s,[^A-Za-z0-9\./_~-],,g" <<<"$repo")" + test "$repo" != "$_repo" && { printf 'Illegal name: %s\n' "${repo}"; continue; } + test ! -d "$repo".git && { printf 'Does not exist: %s\n' "${repo}"; continue; } + + echo "Removing ${repo}.git" + # lo and behold absolute horror + rm -rf -- "$repo".git +done diff --git a/misc/git-shell-commands/fetch-mirrors b/misc/git-shell-commands/fetch-mirrors new file mode 100755 index 0000000..15bf9c4 --- /dev/null +++ b/misc/git-shell-commands/fetch-mirrors @@ -0,0 +1,13 @@ +#!/bin/sh +# * fetch-mirrors +# Actualiza el `mirrors` (espejos) creados con `mirror` +# ssh git@host fetch-mirrors + +set -e + +# Find all mirrors +"$(dirname "$0")"/mirrors | while read -r mirror; do + pushd "$mirror" >/dev/null + git remote update + popd >/dev/null +done diff --git a/misc/git-shell-commands/help b/misc/git-shell-commands/help new file mode 100755 index 0000000..f1d116b --- /dev/null +++ b/misc/git-shell-commands/help @@ -0,0 +1,12 @@ +#!/bin/sh +# * help +# Obtiene los comando habilitados +# ssh git@host help + +set -e + +# Gets the initial comment after the shebeng from every git-shell-command +for c in "$(dirname "$0")"/*; do + sed -rn '2,/^[^#]/s/^# ?//p' "$c" + echo +done diff --git a/misc/git-shell-commands/hook-install b/misc/git-shell-commands/hook-install new file mode 100755 index 0000000..b38836a --- /dev/null +++ b/misc/git-shell-commands/hook-install @@ -0,0 +1,28 @@ +#!/bin/sh +# * hook-install +# Instala un hook en un repo +# ssh git@host hook-install hook script repo [alt-dir] + +set -e + +exit 1 # I don't trust this script + +hook="${1}" +script="${HOME}/.ssh/git-hooks/${2}" +repo="${3}" +clone="${4:-${repo}}" + +repo="$(sed -r 's,^/*,,' <<<"$repo")" +_repo="$(sed -r -e '/(^|\/)\.\.($|\/)/d' -e "s,[^A-Za-z0-9\./_~-],,g" <<<"$repo")" +test "$repo" = "$_repo" || { printf 'Illegal name: %s\n' "${repo}"; exit 1; } +test -d "$repo".git || { printf 'Does not exist: %s\n' "${repo}"; exit 1; } + +# Tests +test -f "${repo}.git/HEAD" +test -f "${clone}/.git/HEAD" + +# Installs the generic hook that runs scripts +test -f "${repo}.git/hooks/${hook}" || ln -s "${HOME}/.ssh/git-hooks/generic" "${repo}.git/hooks/${hook}" + +# Install the hook on the repo +git config -f "${repo}.git/config" --add "hacking.hooks.${hook}.${2}" "${clone}" diff --git a/misc/git-shell-commands/mirror b/misc/git-shell-commands/mirror new file mode 100755 index 0000000..8282e9b --- /dev/null +++ b/misc/git-shell-commands/mirror @@ -0,0 +1,10 @@ +#!/bin/sh +# * mirror +# Espeja un repositorio +# ssh git@host mirror git://url/repo.git + +set -E + +for _m in "$@"; do + git clone --mirror "$_m" +done diff --git a/misc/git-shell-commands/mirrors b/misc/git-shell-commands/mirrors new file mode 100755 index 0000000..436564f --- /dev/null +++ b/misc/git-shell-commands/mirrors @@ -0,0 +1,9 @@ +#!/bin/sh +# * mirrors +# Muestra todos los repositorios espejos (mirror) +# ssh git@host mirrors + +set -e + +# Find all mirrors +find $(find * -name '*.git' -type d) -maxdepth 1 -name config -exec grep -l 'mirror\s*=\s*true' {} + | sed 's,/config$,,' -- cgit v1.2.3