commit 8fa6a4407e8d19274315a517644473c96bb9151b
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Tue, 23 Jun 2020 14:22:20 +0200

Add git-shell commands

Diffstat:
AREADME.md | 8++++++++
Aaddkey | 32++++++++++++++++++++++++++++++++
Adescription | 11+++++++++++
Ahelp | 13+++++++++++++
Ainit | 17+++++++++++++++++
Amake-private | 12++++++++++++
Amake-public | 12++++++++++++
Aowner | 11+++++++++++
Arestart-web | 2++
Aurl | 11+++++++++++
10 files changed, 129 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1,8 @@ +# Git shell commands + +These scripts are useful to have in the git-shell when making a git server. Some +of the scripts assume that you have my version of stagit installed. + +Some of the scripts are based in the ones found [here][src]. + +[src]: <http://planzero.org/blog/2012/10/24/hosting_an_admin-friendly_git_server_with_git-shell> "Hosting an admin-friendly git server with git-shell" diff --git a/addkey b/addkey @@ -0,0 +1,32 @@ +#!/bin/sh + +# Read in the SSH key +echo "Input the key to be added:" +read key + +# Place the key in a temporary file (it's hard to get ssh-keygen +# to read from stdin; <<< works for bash, but is non-posix) +keyfile=$(tempfile) && echo "$key" > $keyfile + +# Generate a fingerprint +fingerprint=$(ssh-keygen -lf $keyfile) + +# Check for errors +if [ $(echo "$fingerprint" | egrep -c '(R|D)SA') -eq 0 ] +then + # Display the fingerprint error and clean up + echo "Error: $fingerprint" + rm $keyfile + exit 1 +fi + +# Add the key to the authorised keys file and clean up +mkdir -p .ssh && \ + echo -n "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty " >> .ssh/authorized_keys && \ + cat $keyfile >> .ssh/authorized_keys + +rm $keyfile + +# Display the fingerprint for reference +echo "Success! Added a key with the following fingerprint:" +echo $fingerprint diff --git a/description b/description @@ -0,0 +1,11 @@ +#!/bin/sh + +# Check number of params +[ $# -ne 2 ] && echo "Usage: description <project.git> <description>" && exit 1 + +# Set the project name, adding .git if necessary +p=$(echo "$1" | sed 's/\.git$\|$/.git/i') + +[ ! -d "$p" ] && echo "$p not found." + +echo "$2" > "$p/description" diff --git a/help b/help @@ -0,0 +1,13 @@ +#!/bin/sh + +echo "Run 'help' for help, or 'exit' to leave. Available commands:" + +cd "$(dirname "$0")" + +for cmd in * +do + case "$cmd" in + help) ;; + *) [ -f "$cmd" ] && [ -x "$cmd" ] && echo " $cmd" ;; + esac +done diff --git a/init b/init @@ -0,0 +1,17 @@ +#!/bin/sh + +# Check number of params +[ $# -ne 1 ] && echo "Usage: init <project.git>" && exit 1 + +# Set the project name, adding .git if necessary +p=$(echo "$1" | sed 's/\.git$\|$/.git/i') + +# Create and initialise the project +mkdir "$p" && \ + cd "$p" && \ + git --bare init +ln -sf "/usr/local/share/doc/stagit/example_post-receive.sh" "hooks/post-receive" + +echo "Oscar Benedito" > "owner" +echo "git://git.oscarbenedito.com/${p%.git}" > "url" +echo "${p%.git}" > "description" diff --git a/make-private b/make-private @@ -0,0 +1,12 @@ +#!/bin/sh + +# Check number of params +[ $# -ne 1 ] && echo "Usage: make-private <project.git>" && exit 1 + +# Set the project name, adding .git if necessary +p=$(echo "$1" | sed 's/\.git$\|$/.git/i') + +[ ! -d "$p" ] && echo "$p not found." + +[ ! -f "$p/git-daemon-export-ok" ] && echo "$p is already private." && exit +rm "$p/git-daemon-export-ok" && echo "$p is now private." diff --git a/make-public b/make-public @@ -0,0 +1,12 @@ +#!/bin/sh + +# Check number of params +[ $# -ne 1 ] && echo "Usage: make-public <project.git>" && exit 1 + +# Set the project name, adding .git if necessary +p=$(echo "$1" | sed 's/\.git$\|$/.git/i') + +[ ! -d "$p" ] && echo "$p not found." + +[ -f "$p/git-daemon-export-ok" ] && echo "$p is already public." && exit +touch "$p/git-daemon-export-ok" && echo "$p is now public." diff --git a/owner b/owner @@ -0,0 +1,11 @@ +#!/bin/sh + +# Check number of params +[ $# -ne 2 ] && echo "Usage: owner <project.git> <owner>" && exit 1 + +# Set the project name, adding .git if necessary +p=$(echo "$1" | sed 's/\.git$\|$/.git/i') + +[ ! -d "$p" ] && echo "$p not found." + +echo "$2" > "$p/owner" diff --git a/restart-web b/restart-web @@ -0,0 +1 @@ +/usr/local/share/doc/stagit/example_create.sh +\ No newline at end of file diff --git a/url b/url @@ -0,0 +1,11 @@ +#!/bin/sh + +# Check number of params +[ $# -ne 2 ] && echo "Usage: url <project.git> <url>" && exit 1 + +# Set the project name, adding .git if necessary +p=$(echo "$1" | sed 's/\.git$\|$/.git/i') + +[ ! -d "$p" ] && echo "$p not found." + +echo "$2" > "$p/url"