From dc54a69b7552d8d44adf25b8009992c4a2b395be Mon Sep 17 00:00:00 2001 From: steering7253 Date: Mon, 18 May 2026 01:25:46 -0600 Subject: init --- addkey | 8 +++++ catkeys | 4 +++ delkey | 19 +++++++++++ description | 10 ++++++ fetch-all | 12 +++++++ find-nonstandard-hooks | 5 +++ git | 28 +++++++++++++++++ git.d/config | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ gpg-import | 6 ++++ gpg-import-ownertrust | 6 ++++ help | 20 ++++++++++++ hiderepo | 10 ++++++ hideuser | 5 +++ ls | 9 ++++++ mkrepo | 29 +++++++++++++++++ rename | 19 +++++++++++ select | 14 +++++++++ showrepo | 9 ++++++ showuser | 4 +++ 19 files changed, 302 insertions(+) create mode 100755 addkey create mode 100755 catkeys create mode 100755 delkey create mode 100755 description create mode 100755 fetch-all create mode 100755 find-nonstandard-hooks create mode 100755 git create mode 100755 git.d/config create mode 100755 gpg-import create mode 100755 gpg-import-ownertrust create mode 100755 help create mode 100755 hiderepo create mode 100755 hideuser create mode 100755 ls create mode 100755 mkrepo create mode 100755 rename create mode 100755 select create mode 100755 showrepo create mode 100755 showuser diff --git a/addkey b/addkey new file mode 100755 index 0000000..e8bda98 --- /dev/null +++ b/addkey @@ -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" diff --git a/catkeys b/catkeys new file mode 100755 index 0000000..79dbc3d --- /dev/null +++ b/catkeys @@ -0,0 +1,4 @@ +#!/bin/bash +# cat your authorized_keys + +cat -n "$HOME/.ssh/authorized_keys" diff --git a/delkey b/delkey new file mode 100755 index 0000000..fcb858c --- /dev/null +++ b/delkey @@ -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 " >&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 diff --git a/git b/git new file mode 100755 index 0000000..742bff1 --- /dev/null +++ b/git @@ -0,0 +1,28 @@ +#!/bin/bash +# Some git subcommands are made available to you. +# Use `select ` first. + + + +if [ $# -lt 1 ]; then + echo "Usage: $0 ..." >&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] " + echo " $parentcmd $cmd [--global|--local] set " + 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 | 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 diff --git a/help b/help new file mode 100755 index 0000000..47b7e14 --- /dev/null +++ b/help @@ -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" diff --git a/ls b/ls new file mode 100755 index 0000000..fd6230c --- /dev/null +++ b/ls @@ -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" diff --git a/mkrepo b/mkrepo new file mode 100755 index 0000000..b184d82 --- /dev/null +++ b/mkrepo @@ -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] " >&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" diff --git a/rename b/rename new file mode 100755 index 0000000..afa951e --- /dev/null +++ b/rename @@ -0,0 +1,19 @@ +#!/bin/bash +# Rename a repo + +if [ $# -ne 2 ]; then + echo "Syntax: $0 " >&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" diff --git a/select b/select new file mode 100755 index 0000000..5464c7d --- /dev/null +++ b/select @@ -0,0 +1,14 @@ +#!/bin/bash +# Select a repo (for later git commands to operate on) + +if [ $# -ne 1 ]; then + echo "Syntax: $0 " >&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" -- cgit v1.3.1-10-gc9f91