diff options
| author | 2026-05-18 01:25:46 -0600 | |
|---|---|---|
| committer | 2026-05-18 01:25:46 -0600 | |
| commit | dc54a69b7552d8d44adf25b8009992c4a2b395be (patch) | |
| tree | 0c1864e9239bf02fc83408be378d983070250ead | |
init
| -rwxr-xr-x | addkey | 8 | ||||
| -rwxr-xr-x | catkeys | 4 | ||||
| -rwxr-xr-x | delkey | 19 | ||||
| -rwxr-xr-x | description | 10 | ||||
| -rwxr-xr-x | fetch-all | 12 | ||||
| -rwxr-xr-x | find-nonstandard-hooks | 5 | ||||
| -rwxr-xr-x | git | 28 | ||||
| -rwxr-xr-x | git.d/config | 85 | ||||
| -rwxr-xr-x | gpg-import | 6 | ||||
| -rwxr-xr-x | gpg-import-ownertrust | 6 | ||||
| -rwxr-xr-x | help | 20 | ||||
| -rwxr-xr-x | hiderepo | 10 | ||||
| -rwxr-xr-x | hideuser | 5 | ||||
| -rwxr-xr-x | ls | 9 | ||||
| -rwxr-xr-x | mkrepo | 29 | ||||
| -rwxr-xr-x | rename | 19 | ||||
| -rwxr-xr-x | select | 14 | ||||
| -rwxr-xr-x | showrepo | 9 | ||||
| -rwxr-xr-x | showuser | 4 |
19 files changed, 302 insertions, 0 deletions
@@ -0,0 +1,8 @@ +#!/bin/bash +# Add a key (or keys) to your authorized_keys + +[ -t 0 ] && echo "Paste in your authorized_keys content, then press ^D" +tr -dc '-a-zA-Z0-9 +/=:' | sed 's/^/restrict,pty /' - >>"$HOME/.ssh/authorized_keys" + +echo "New keys:" +cat -n "$HOME/.ssh/authorized_keys" @@ -0,0 +1,4 @@ +#!/bin/bash +# cat your authorized_keys + +cat -n "$HOME/.ssh/authorized_keys" @@ -0,0 +1,19 @@ +#!/bin/bash +# Delete an authorized_keys entry. Specify the line number (from catkeys) to delete. + +if [ $# -ne 1 ]; then + echo "Syntax: $0 <line number>" >&2 + exit 1 +fi + +line_no="$1" + +if ! [[ $line_no =~ ^[0-9]+$ ]]; then + echo "Argument must be a number" >&2 + exit 1 +fi + +sed -i "$line_no"d "$HOME/.ssh/authorized_keys" + +echo "New keys:" +cat -n "$HOME/.ssh/authorized_keys" diff --git a/description b/description new file mode 100755 index 0000000..42c7c7e --- /dev/null +++ b/description @@ -0,0 +1,10 @@ +#!/bin/bash +# Change the description of a repo. + +if [[ $1 == *..* ]]; then + echo "No .." >&2 + exit 1 +fi + +echo "Enter the new description and then EOF (^D)" +cat >"$HOME/$1.git/description" diff --git a/fetch-all b/fetch-all new file mode 100755 index 0000000..d556535 --- /dev/null +++ b/fetch-all @@ -0,0 +1,12 @@ +#!/bin/bash +# Fetch all your repos that have a remote + +cd $HOME + +find . -type d -name '*.git' | while read -r repo; do + echo "$repo" + pushd "$repo" >/dev/null + git -c credential.interactive=false fetch --all + git update-server-info + popd >/dev/null +done diff --git a/find-nonstandard-hooks b/find-nonstandard-hooks new file mode 100755 index 0000000..074f8b6 --- /dev/null +++ b/find-nonstandard-hooks @@ -0,0 +1,5 @@ +#!/bin/bash +# Find all your repos that have nonstandard hooks +# Probably mostly of use to staff + +find "$HOME" -type d -name '*.git' -execdir git -C {} config --local --get core.hookspath "!$HOME/hooks/.*" \; -print @@ -0,0 +1,28 @@ +#!/bin/bash +# Some git subcommands are made available to you. +# Use `select <repo>` first. + + + +if [ $# -lt 1 ]; then + echo "Usage: $0 <subcommand>..." >&2 + echo "Available subcommands:" >&2 + ls "$0.d" >&2 + exit 1 +fi + +subcmd="$1" +if [ ! -x "$0.d/$subcmd" ]; then + echo "$0: error: unknown subcommand: $subcmd" >&2 + echo "Available subcommands:" >&2 + ls "$0.d" >&2 + exit 1 +fi + +export SELECTED_REPO="$(cat "$HOME/.selection" 2>/dev/null)" + +shift + +export PARENTCMD="$0" + +exec "$0.d/$subcmd" "$@" diff --git a/git.d/config b/git.d/config new file mode 100755 index 0000000..24f637d --- /dev/null +++ b/git.d/config @@ -0,0 +1,85 @@ +#!/bin/bash + +check_repo(){ + if [ -z "$SELECTED_REPO" ]; then + echo "$0: error: you must first use the select command to pick a repo to operate on" >&2 + exit 1 + else + echo "Operating on: $SELECTED_REPO" + fi +} +usage_and_exit(){ + exec >&2 + echo "$0: error: incorrect syntax" + echo "Usage: $parentcmd $cmd [--global|--local] list" + echo " $parentcmd $cmd [--global|--local] <get|unset> <key>" + echo " $parentcmd $cmd [--global|--local] set <key> <value>" + exit 1 +} + +cmd="$(basename "$0")" +is_global="" +mode="" +while [ -n "$1" ]; do + if [ "$1" = "--global" ]; then + is_global="--global" + elif [ "$1" = "--local" ]; then + is_global="--local" + elif [ "$1" = "unset" ]; then + mode="unset" + elif [ "$1" = "get" ]; then + mode="get" + elif [ "$1" = "set" ]; then + mode="set" + elif [ "$1" = "list" ]; then + mode="list" + else + break + fi + shift +done + +if [ "$mode" = "set" ]; then + if [ $# -ne 2 ]; then + usage_and_exit + fi +elif [ "$mode" = "list" ]; then + if [ $# -ne 0 ]; then + usage_and_exit + fi + git -C "$SELECTED_REPO" config list $is_global + exit 0 +else + if [ $# -ne 1 ]; then + usage_and_exit + fi +fi + +if [ -z "$is_global" ]; then + check_repo +fi + +key="$1" +value="$2" + +whitelist_keys=( + hooks.* + init.defaultObjectFormat + init.defaultRefFormat + cgit.{owner,section,desc,homepage,hide,defbranch,branch-sort,readme} + cgit.{logo,logo-link,extra-head-content,enable-remote-branches} +) + +for whitelist_key in "${whitelist_keys[@]}"; do + if [[ $key == $whitelist_key ]]; then + if [ "$mode" = "set" ]; then + git -C "$SELECTED_REPO" config $is_global $mode -- "$key" "$value" + else + git -C "$SELECTED_REPO" config $is_global $mode -- "$key" + fi + exit + fi +done + +echo "Key not allowed: $key" >&2 +exit 2 diff --git a/gpg-import b/gpg-import new file mode 100755 index 0000000..1102d0a --- /dev/null +++ b/gpg-import @@ -0,0 +1,6 @@ +#!/bin/bash +# gpg --export <keys> | ssh cgit.space gpg-import +# This is solely useful for the signature status in notifications. + +set -x +exec gpg --import --import-options import-local-sigs diff --git a/gpg-import-ownertrust b/gpg-import-ownertrust new file mode 100755 index 0000000..493cd94 --- /dev/null +++ b/gpg-import-ownertrust @@ -0,0 +1,6 @@ +#!/bin/bash +# gpg --export-ownertrust | ssh cgit.space gpg-import-ownertrust +# This is solely useful for the signature status in notifications. + +set -x +exec gpg --import-ownertrust @@ -0,0 +1,20 @@ +#!/bin/sh +# Send help. I'm trapped in the machine. + +if [ $# -eq 0 ]; then + echo "Commands available:" + find -L "$(dirname "$0")" -maxdepth 1 -type f \! -name '.*' -execdir perl -e '$w=80;$buf=""; for (@ARGV) { s@^\./@@; if (length("$buf $_") > $w) { print("$buf\n"); $buf = ""; } $buf .= " $_"; } print("$buf\n");' {} + + echo + echo "This is https://cgit.space/~cgitspace/git-shell-commands.git@$(git describe --abbrev --dirty)" +else + if [[ $1 == *.* ]]; then + echo "No ." >&2 + exit 1 + fi + if [[ $1 == */* ]]; then + echo "No ." >&2 + exit 1 + fi + + sed '/^#!/d;/^\([^#]\|$\)/Q;s/^# \?//' "$(dirname "$0")/$1" +fi diff --git a/hiderepo b/hiderepo new file mode 100755 index 0000000..2b3c9e3 --- /dev/null +++ b/hiderepo @@ -0,0 +1,10 @@ +#!/bin/bash +# Hide a repo from the web interface. +# This DOES NOT prevent users from cloning the repo. + +if [[ $1 == *..* ]]; then + echo "No .." >&2 + exit 1 +fi + +git -C "$HOME/$1.git" config --local cgit.hide 1 diff --git a/hideuser b/hideuser new file mode 100755 index 0000000..ee96e67 --- /dev/null +++ b/hideuser @@ -0,0 +1,5 @@ +#!/bin/bash +# Hide your user from the list. +# This prevents any kind of access to your repos from other (or anonymous) users. + +chmod go-r "$HOME" @@ -0,0 +1,9 @@ +#!/bin/bash +# ls (anything in) your homedir (eq. ls $HOME/$1) + +if [[ $1 == *..* ]]; then + echo "No .." >&2 + exit 1 +fi + +ls "$HOME/$1" @@ -0,0 +1,29 @@ +#!/bin/bash +# Make a new repo. + +declare -a extra_git_args + +if [ "$1" = "--sha256" ]; then + extra_git_args+=( --object-format=sha256 ) + shift +fi + +if [ $# -ne 1 ]; then + echo "Syntax: $0 [--sha256] <name>" >&2 + exit 1 +fi + +if [[ $1 == *..* ]]; then + echo "No .." >&2 + exit 1 +fi +if [[ $1 == */* ]]; then + echo "No /" >&2 + exit 1 +fi + + +git init --shared --bare "${extra_git_args[@]}" "$HOME/$1.git" +git -C "$HOME/$1.git" config --unset receive.denyNonFastForwards + +echo "Created $USER@$(hostname -f):$1.git" @@ -0,0 +1,19 @@ +#!/bin/bash +# Rename a repo + +if [ $# -ne 2 ]; then + echo "Syntax: $0 <source name> <destination name>" >&2 + exit 1 +fi + + +if [[ $1 == *..* ]]; then + echo "No .." >&2 + exit 1 +fi +if [[ $2 == *..* ]]; then + echo "No .." >&2 + exit 1 +fi + +mv --no-target-directory "$HOME/$1.git" "$HOME/$2.git" @@ -0,0 +1,14 @@ +#!/bin/bash +# Select a repo (for later git commands to operate on) + +if [ $# -ne 1 ]; then + echo "Syntax: $0 <name>" >&2 + exit 1 +fi + +if [ ! -O "$HOME/$1.git" ]; then + echo "$0: error: you must own the repo you want to operate on" >&2 + exit 1 +fi + +echo "$HOME/$1.git" >"$HOME/.selection" diff --git a/showrepo b/showrepo new file mode 100755 index 0000000..4c932ea --- /dev/null +++ b/showrepo @@ -0,0 +1,9 @@ +#!/bin/bash +# Un-hide a repo + +if [[ $1 == *..* ]]; then + echo "No .." >&2 + exit 1 +fi + +git -C "$HOME/$1.git" config --local --unset cgit.hide diff --git a/showuser b/showuser new file mode 100755 index 0000000..a325c38 --- /dev/null +++ b/showuser @@ -0,0 +1,4 @@ +#!/bin/bash +# Un-hide your user + +chmod go+r "$HOME" |
