commit e8a8fda25f9659a86c73e5a40e0fd1b60d6984e8
parent 18663f24df07507f3f287e72dba7937b512788b8
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date: Tue, 23 Jun 2020 14:22:20 +0200
Add git-shell commands
Diffstat:
10 files changed, 129 insertions(+), 0 deletions(-)
diff --git a/git-shell-commands/README.md b/git-shell-commands/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/git-shell-commands/addkey b/git-shell-commands/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/git-shell-commands/description b/git-shell-commands/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/git-shell-commands/help b/git-shell-commands/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/git-shell-commands/init b/git-shell-commands/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/git-shell-commands/make-private b/git-shell-commands/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/git-shell-commands/make-public b/git-shell-commands/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/git-shell-commands/owner b/git-shell-commands/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/git-shell-commands/restart-web b/git-shell-commands/restart-web
@@ -0,0 +1 @@
+/usr/local/share/doc/stagit/example_create.sh
+\ No newline at end of file
diff --git a/git-shell-commands/url b/git-shell-commands/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"