diff options
Diffstat (limited to 'modules/services/nixos/cgit/gitShellCommands.nix')
| -rw-r--r-- | modules/services/nixos/cgit/gitShellCommands.nix | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/modules/services/nixos/cgit/gitShellCommands.nix b/modules/services/nixos/cgit/gitShellCommands.nix new file mode 100644 index 0000000..e99f9f2 --- /dev/null +++ b/modules/services/nixos/cgit/gitShellCommands.nix @@ -0,0 +1,43 @@ +{ + hjem.users."git".files = { + "git-shell-commands/set-description" = { + executable = true; + text = '' + #!/usr/bin/env bash + set -euo pipefail + repo="$1" + desc="$2" + base="/var/lib/cgit" + repo_path="$base/$repo" + + test -d "$repo_path" || { echo "Repository does not exist"; exit 1; } + + # Prevent path traversal + real=$(realpath "$repo_path") + if [[ "$real" != "$base/"* ]]; then + echo "Invalid path" + exit 1 + fi + + echo "$desc" | head -n 1 > "$repo_path/description" + + echo "Description updated for '$repo'" + ''; + }; + "git-shell-commands/create-repo" = { + executable = true; + text = '' + #!/usr/bin/env bash + set -euo pipefail + repo="$1" + base="/var/lib/cgit" + repo_path="$base/$repo" + + test -d "$repo_path" && { echo "Repository already exists."; exit 1; } + + git init --bare "$repo_path" + echo "Repository '$repo' created" + ''; + }; + }; +} |
