summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/git-hooks/auto-deploy16
-rwxr-xr-xmisc/git-hooks/generic12
-rwxr-xr-xmisc/git-hooks/hackers-update22
-rwxr-xr-xmisc/git-shell-commands/change-description19
-rwxr-xr-xmisc/git-shell-commands/change-owner19
-rwxr-xr-xmisc/git-shell-commands/create-bare-repo18
-rwxr-xr-xmisc/git-shell-commands/delete-repo17
-rwxr-xr-xmisc/git-shell-commands/fetch-mirrors13
-rwxr-xr-xmisc/git-shell-commands/help12
-rwxr-xr-xmisc/git-shell-commands/hook-install28
-rwxr-xr-xmisc/git-shell-commands/mirror10
-rwxr-xr-xmisc/git-shell-commands/mirrors9
12 files changed, 195 insertions, 0 deletions
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} ${@} </dev/stdin
+done
diff --git a/misc/git-hooks/hackers-update b/misc/git-hooks/hackers-update
new file mode 100755
index 0000000..b78c54d
--- /dev/null
+++ b/misc/git-hooks/hackers-update
@@ -0,0 +1,22 @@
+#!/bin/bash
+# post-receive hook, updates /srv/git/.ssh after pushing to this repo
+# install:
+# git clone hackers.git .ssh
+# cp .ssh/git-hooks/post-receive hackers.git/hooks/
+
+# fail on any error
+set -e
+
+# the ssh dir
+ssh_dir=${HOME}/.ssh
+
+# pull this repo
+git --git-dir ${ssh_dir}/.git \
+ --work-tree ${ssh_dir} \
+ pull origin master
+
+# secure the files (sshd will refuse connections otherwise)
+chmod 600 ${ssh_dir}/authorized_keys
+chmod 700 ${ssh_dir}
+
+exit $?
diff --git a/misc/git-shell-commands/change-description b/misc/git-shell-commands/change-description
new file mode 100755
index 0000000..60db0ac
--- /dev/null
+++ b/misc/git-shell-commands/change-description
@@ -0,0 +1,19 @@
+#!/bin/bash
+# * change-description
+# Cambia la descripcion del projecto, necesita archivo description en el proyecto
+# ssh git@host change-description repo "description"
+
+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
+ echo "${*}" > "${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$,,'