gitzone

git-based zone management tool for static and dynamic domains
git clone https://git.parazyd.org/gitzone
Log | Files | Refs

commit 528aad32d27e4f25284a408a7dd57ddde11f02d8
parent 1e61adb55d88c69feb3693d117788143904af813
Author: Jaromil <jaromil@dyne.org>
Date:   Sun,  9 Jun 2019 10:56:31 +0200

Merge pull request #8 from dyne/gitzone-shell-posix

Convert gitzone-shell to POSIX shell.
Diffstat:
MREADME.org | 4+---
Mbin/gitzone-shell | 70+++++++++++++++++++++++++++++++++++++++++-----------------------------
2 files changed, 42 insertions(+), 32 deletions(-)

diff --git a/README.org b/README.org @@ -17,9 +17,7 @@ server. Gitzone is written in Perl. Gitzone-shell is similar to git-shell but it restricts the user to the zones repository and provides some additional commands for dynamic DNS -updates & SSH key management. Gitzone-shell and the Gitzone-install -scripts are written in Zsh shell script. - +updates & SSH key management. #+LATEX: \pagebreak diff --git a/bin/gitzone-shell b/bin/gitzone-shell @@ -1,8 +1,8 @@ -#!/usr/bin/env zsh - +#!/bin/sh +# # gitzone-shell - restrictive shell for gitzone # -# Copyright (C) 2011,2013 Dyne.org Foundation +# Copyright (C) 2011,2019 Dyne.org Foundation # # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU Affero General Public License as published by the Free @@ -34,35 +34,47 @@ git=/usr/bin/git grep=/bin/grep error() { - echo "fatal: What do you think I am? A shell?" - exit 128 + echo "fatal: What do you think I am? A shell?" + exit 127 } if [ "$1" != "-c" ]; then error; fi cmd=$2 -if [[ "$cmd" == git-upload-pack* ]]; then - $git upload-pack $repo_dir/$repo -elif [[ "$cmd" == git-receive-pack* ]]; then - $git receive-pack $repo_dir/$repo -elif [[ "$cmd" == update-record* ]]; then - cd $repo_dir/$repo/.git - $gitzone $config update-record "$cmd" -elif [ -f $allow_key_mgmt_file ]; then - if [[ "$cmd" == list-keys ]]; then - cat .ssh/authorized_keys - elif [[ "$cmd" == add-key* ]]; then - key="${cmd:8}" - echo "$key" >> .ssh/authorized_keys && \ - echo "key added" - elif [[ "$cmd" == del-key* ]]; then - key="${cmd:8}" - $grep -v "$key" .ssh/authorized_keys > .ssh/authorized_keys-new && \ - mv .ssh/authorized_keys-new .ssh/authorized_keys && \ - echo "key deleted" - else - error - fi -else - error +case "$cmd" in +git-upload-pack*) + $git upload-pack "$repo_dir/$repo" + exit $? + ;; +git-receive-pack*) + $git receive-pack "$repo_dir/$repo" + exit $? + ;; +update-record*) + cd "$repo_dir/$repo/.git" || exit 1 + $gitzone "$config" update-record "$cmd" + exit $? + ;; +esac + +if [ -f "$allow_key_mgmt_file" ]; then + case "$cmd" in + list-keys) + cat .ssh/authorized_keys + exit $? + ;; + add-key*) + key="$(echo "$cmd" | cut -c9-)" + echo "$key" >> .ssh/authorized_keys && echo "key added" + exit $? + ;; + del-key*) + key="$(echo "$cmd" | cut -c9-)" + $grep -v "$key" .ssh/authorized_keys > .ssh/authorized_keys-new || exit 1 + mv .ssh/authorized_keys-new .ssh/authorized_keys && echo "key deleted" + exit $? + ;; + esac fi + +error