commit 09beaf0e1d66089059eaa910e8f74b0689daf4dd
parent 1bff4860ac1192b5b0eec312dab2505a558fc333
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Thu, 13 Jan 2022 19:22:33 +0100

Style changes

Diffstat:
Maddkey | 32++++++++++++--------------------
Medit | 4++--
Mhelp | 11+++++------
Minit | 12++++++------
Msubscripts/mirror-repository | 6++++++
5 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/addkey b/addkey @@ -1,32 +1,24 @@ #!/bin/sh -# Read in the SSH key -echo "Input the key to be added:" +echo "Paste the key to be added:" read key -# Place the key in a temporary file (it's hard to get ssh-keygen -# to read from stdin; <<< works for bash, but is non-posix) -keyfile=$(tempfile) && echo "$key" > $keyfile +keyfile="$(mktemp)" +echo "$key" > "$keyfile" -# Generate a fingerprint -fingerprint=$(ssh-keygen -lf $keyfile) - -# Check for errors -if [ $(echo "$fingerprint" | egrep -c '(R|D)SA') -eq 0 ] -then - # Display the fingerprint error and clean up - echo "Error: $fingerprint" - rm $keyfile - exit 1 +# check for errors +fingerprint="$(ssh-keygen -lf $keyfile)" +if [ "$(echo "$fingerprint" | egrep -c '\((R|D)SA|ED25519\)')" -ne "1" ]; then + echo "Error: $fingerprint" + rm "$keyfile" + exit 1 fi -# Add the key to the authorised keys file and clean up mkdir -p .ssh && \ echo -n "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty " >> .ssh/authorized_keys && \ - cat $keyfile >> .ssh/authorized_keys + cat "$keyfile" >> .ssh/authorized_keys -rm $keyfile +rm "$keyfile" -# Display the fingerprint for reference echo "Success! Added a key with the following fingerprint:" -echo $fingerprint +echo "$fingerprint" diff --git a/edit b/edit @@ -3,7 +3,7 @@ # check number of params [ $# -ne 1 ] && echo "Usage: edit repo[.git]" && exit 1 -# set the project name, adding .git if necessary +# set the repository name, adding .git if necessary p=$(echo "$1" | sed 's/\.git$\|$/.git/i') [ ! -d "$p" ] && echo "$p not found." && exit 1 @@ -12,7 +12,7 @@ get_category() { if [ ! -f "$p/git-daemon-export-ok" ]; then echo "Private repository" elif [ ! -f "$p/category" ]; then - echo "Unlisted repo (public cloning but not listed on website)" + echo "Unlisted repository (public cloning but not listed on website)" else printf "Public repository, category: " cat "$p/category" diff --git a/help b/help @@ -4,10 +4,9 @@ echo "Run 'help' for help, or 'exit' to leave. Available commands:" cd "$(dirname "$0")" -for cmd in * -do - case "$cmd" in - help) ;; - *) [ -f "$cmd" ] && [ -x "$cmd" ] && echo " $cmd" ;; - esac +for cmd in *; do + case "$cmd" in + help) ;; + *) [ -f "$cmd" ] && [ -x "$cmd" ] && echo " $cmd" ;; + esac done diff --git a/init b/init @@ -1,17 +1,17 @@ #!/bin/sh -# Check number of params -[ $# -ne 1 ] && echo "Usage: init project[.git]" && exit 1 +# check number of params +[ $# -ne 1 ] && echo "Usage: init repo[.git]" && exit 1 -# Set the project name, adding .git if necessary +# set the repository name, adding .git if necessary p=$(echo "$1" | sed 's/\.git$\|$/.git/i') [ -e "$p" ] && echo "$p is already a file or directory." && exit 1 -# Create and initialise the project +# create and initialise the repository mkdir "$p" && \ - cd "$p" && \ - git --bare init + cd "$p" && \ + git --bare init ln -sf "/usr/local/share/doc/stagit/example_post-receive.sh" "hooks/post-receive" ln -sf "post-update.sample" "hooks/post-update" diff --git a/subscripts/mirror-repository b/subscripts/mirror-repository @@ -1,5 +1,11 @@ #!/usr/bin/env bash +# you should never call this script from a non-public repository, but just in +# case... +if [ ! -f "git-daemon-export-ok" ] || [ ! -f "category" ]; then + exit 1 +fi + set -e trap "notify \"ERROR pushing $repo\" \"There was an error pushing $repo to either SourceHut or GitHub.\"" ERR