diff options
author | dweller <dweller@cabin.digital> | 2024-03-09 02:50:22 +0200 |
---|---|---|
committer | dweller <dweller@cabin.digital> | 2024-03-09 02:50:22 +0200 |
commit | 9b9bda8bb3700b25007a1b78958a2a4ac7c2f9cb (patch) | |
tree | 894a24c89afdff8eae712307bc186b83cd6b0044 |
Initial commit
Diffstat (limited to '')
-rw-r--r-- | LICENSE | 30 | ||||
-rw-r--r-- | README | 34 | ||||
-rwxr-xr-x | git-descremote | 19 | ||||
-rwxr-xr-x | git-mkremote | 21 | ||||
-rwxr-xr-x | git-shell-commands/help | 12 | ||||
-rwxr-xr-x | git-shell-commands/mkrepo | 42 | ||||
-rwxr-xr-x | git-shell-commands/setdesc | 37 |
7 files changed, 195 insertions, 0 deletions
@@ -0,0 +1,30 @@ +BSD 3-Clause License (BSD-3-Clause) + +Copyright (C) 2024 dwlr <dweller@cabin.digital> + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + @@ -0,0 +1,34 @@ +gitscripts +---------- + +Collection of scripts that make it easier to manager self-hosted git server. + + +If you have a git server, and you don't like the idea of running large web frontends, but still want +to be able to do something as basic as create a new remote (bare) repository this might be for you. + +Install/Usage: + 1. Create a 'git' user (or any other name, but you'll have to substitute henceforth) + I use git's $HOME to store my repositories, but you can either change git's $HOME on creation + or just change PREFIX in the scripts; + + 2. `chsh -s $(command -v git-shell) git` to change 'git' to use git-shell (this will restrict + the user to use only the git related commands we allow); + + 3. Clone this repository and `cp -r git-shell-commands /home/git`, without this folder and + scripts in it, git-shell won't be interactive (see git-shell(1) man page). + - help: just prints the contents of git-shell-commands directory; + - mkrepo: creates a new bare repository at given path and optionally provides description; + - setdesc: sets/changes a repository's description. + + 4. That's it for the remote, now copy (or `ln -s` from this repo) `git-description` and + `git-mkremote` to somewhere that is in your $PATH. Now you can access them by calling + `git mkremote/descremote`. All of them provide usage example when called without arguments; + + 5. That's it! Now you can create remotes easily from the comfort of your terminal, like a normal + terminally terminal person. + +NOTICE: + The git-shell scripts provide access for anyone with ssh access to git user to create folders + and initialize repositories anywhere on your system with lax permissions! Maybe chroot(1)ing + your git server could be a good idea, or maybe if it's just a personal git sever this is okay. diff --git a/git-descremote b/git-descremote new file mode 100755 index 0000000..e7c0a78 --- /dev/null +++ b/git-descremote @@ -0,0 +1,19 @@ +#!/bin/sh +# Copyright (C) 2024 dwlr <dweller@cabin.digital> +# +# BSD 3-Clause License (BSD-3-Clause) +# See LICENSE for details + +set -e + + +if [ $# -lt 3 ]; then + echo "Usage: $0 <server> <repo name> <description>" + exit 1; +fi + +serv=$1 +repo=$2 +shift 2 + +ssh "$serv" setdesc "$repo" "$@" diff --git a/git-mkremote b/git-mkremote new file mode 100755 index 0000000..168f142 --- /dev/null +++ b/git-mkremote @@ -0,0 +1,21 @@ +#!/bin/sh +# Copyright (C) 2024 dwlr <dweller@cabin.digital> +# +# BSD 3-Clause License (BSD-3-Clause) +# See LICENSE for details + +set -e + + +if [ $# -lt 3 ]; then + echo "Usage: $0 <name> <server> <repo name> [description]" + exit 1; +fi + +name=$1 +serv=$2 +repo=$3 +shift 3 + +remote=$(ssh "$serv" mkrepo "$repo" "$@") +git remote add "$name" "$serv$remote" diff --git a/git-shell-commands/help b/git-shell-commands/help new file mode 100755 index 0000000..292cb97 --- /dev/null +++ b/git-shell-commands/help @@ -0,0 +1,12 @@ +#!/bin/sh +# Copyright (C) 2024 dwlr <dweller@cabin.digital> +# +# BSD 3-Clause License (BSD-3-Clause) +# See LICENSE for details + +set -e + + +echo "Available: commands:" +ls "$HOME/git-shell-commands" +echo "exit" diff --git a/git-shell-commands/mkrepo b/git-shell-commands/mkrepo new file mode 100755 index 0000000..356cafa --- /dev/null +++ b/git-shell-commands/mkrepo @@ -0,0 +1,42 @@ +#!/bin/sh +# Copyright (C) 2024 dwlr <dweller@cabin.digital> +# +# BSD 3-Clause License (BSD-3-Clause) +# See LICENSE for details + +set -e + +#FIXME: this is wide open for exploits by using crafted paths like ../../../etc/passwd or something +# But we should be okay since this is behind ssh, right? r- right..? + + +PREFIX="$HOME/repos" + +if [ $# -lt 1 ]; then + echo "Usage: $(basename $0) <repo name> [description]" + exit 1; +fi + +case "$1" in + *.git) reponame="$1" ;; + *) reponame="$1.git" ;; +esac + +netname=$(echo "$PREFIX/$reponame" | sed "s|$HOME|:|") +reponame="$PREFIX/$reponame" + + +if [ ! -e "$reponame" ]; +then + mkdir -p "$reponame" + cd "$reponame" + git init -q --bare && echo "$netname" || echo "Failed to create repo '$netname' :(" + + if [ $# -gt 1 ]; then + shift + echo "$@" > description + fi +else + echo "$netname exists!" + exit 1 +fi diff --git a/git-shell-commands/setdesc b/git-shell-commands/setdesc new file mode 100755 index 0000000..651b170 --- /dev/null +++ b/git-shell-commands/setdesc @@ -0,0 +1,37 @@ +#!/bin/sh +# Copyright (C) 2024 dwlr <dweller@cabin.digital> +# +# BSD 3-Clause License (BSD-3-Clause) +# See LICENSE for details + +set -e + +#FIXME: this is wide open for exploits by using crafted paths like ../../../etc/passwd or something +# But we should be okay since this is behind ssh, right? r- right..? + + +PREFIX="$HOME/repos" + +if [ $# -lt 2 ]; then + echo "Usage: $(basename $0) <repo name> <description>" + exit 1; +fi + +case "$1" in + *.git) reponame="$1" ;; + *) reponame="$1.git" ;; +esac + +netname=$(echo "$PREFIX/$reponame" | sed "s|$HOME|:|") +reponame="$PREFIX/$reponame" + + +if [ -e "$reponame" ]; +then + cd "$reponame" + shift + echo "$@" > description +else + echo "$netname doesn't exists!" + exit 1 +fi |