commit 1bff4860ac1192b5b0eec312dab2505a558fc333
parent fa4b532665ee9cc91570d5cf8bed72e46410a922
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Thu,  6 Jan 2022 18:23:39 +0100

Rework of metadata editing scripts

Diffstat:
Dcategory | 13-------------
Ddescription | 11-----------
Aedit | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dmake-private | 31-------------------------------
Dmake-public | 56--------------------------------------------------------
Downer | 11-----------
Msubscripts/mirror-repository | 8++++----
Durl | 11-----------
8 files changed, 78 insertions(+), 137 deletions(-)

diff --git a/category b/category @@ -1,13 +0,0 @@ -#!/bin/sh - -# Check number of params -[ $# -ne 1 ] && [ $# -ne 2 ] && \ - echo "Usage: category project[.git] [category]" && exit 1 - -# Set the project name, adding .git if necessary -p=$(echo "$1" | sed 's/\.git$\|$/.git/i') - -[ ! -d "$p" ] && echo "$p not found." && exit 1 - -[ -n "$2" ] && echo "$2" > "$p/category" \ - || rm -f "$p/category" diff --git a/description b/description @@ -1,11 +0,0 @@ -#!/bin/sh - -# Check number of params -[ $# -ne 2 ] && echo "Usage: description project[.git] description" && exit 1 - -# Set the project name, adding .git if necessary -p=$(echo "$1" | sed 's/\.git$\|$/.git/i') - -[ ! -d "$p" ] && echo "$p not found." && exit 1 - -echo "$2" > "$p/description" diff --git a/edit b/edit @@ -0,0 +1,74 @@ +#!/bin/sh + +# check number of params +[ $# -ne 1 ] && echo "Usage: edit repo[.git]" && exit 1 + +# set the project name, adding .git if necessary +p=$(echo "$1" | sed 's/\.git$\|$/.git/i') + +[ ! -d "$p" ] && echo "$p not found." && exit 1 + +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)" + else + printf "Public repository, category: " + cat "$p/category" + fi +} + +modify_metadata() { + printf "Enter new $1: " + read answer + echo "$answer" > "$p/$1" +} + +modify_category() { + echo "Category options: + + [p]rivate repository + [u]nlisted repository (public cloning but not listed on website) + + [pr]ojects (public repository) + [pe]rsonal setup (public repository) + [m]iscellanea (public repository)" + + printf ">>> " + read answer + + case $answer in + p) rm -f "$p/git-daemon-export-ok"; rm -f "$p/category" ;; + u) touch "$p/git-daemon-export-ok"; rm -f "$p/category" ;; + pr) touch "$p/git-daemon-export-ok"; echo "Projects" > "$p/category" ;; + pe) touch "$p/git-daemon-export-ok"; echo "Personal setup" > "$p/category" ;; + m) touch "$p/git-daemon-export-ok"; echo "Miscellanea" > "$p/category" ;; + *) echo "Option unknown" ;; + esac +} + +while true; do + echo "Editing repository $p. What data do you want to modify? + + [u]rl: $(cat "$p/url") + [o]wner: $(cat "$p/owner") + [d]escription: $(cat "$p/description") + [c]ategory/visibility: $(get_category) + + [e]xit" + + printf "> " + read answer + + case $answer in + u) modify_metadata "url" ;; + o) modify_metadata "owner" ;; + d) modify_metadata "description" ;; + c) modify_category ;; + e) break ;; + *) echo "Option unknown" ;; + esac +done + +$HOME/git-shell-commands/restart-web diff --git a/make-private b/make-private @@ -1,31 +0,0 @@ -#!/bin/sh - -# path must be absolute -reposdir="/srv/git" -webdir="/srv/git/html" - -# Check number of params -[ $# -ne 1 ] && echo "Usage: make-private project[.git]" && exit 1 - -# Set the project name, adding .git if necessary -dir="$(echo "$1" | sed 's/\.git$\|$/.git/i')" -web="/srv/git/html/$(basename "$dir" ".git")" - -[ ! -d "$dir" ] && echo "$dir not found." && exit 1 - -[ ! -f "$dir/git-daemon-export-ok" ] && echo "$dir is already private." && exit - -rm "$dir/git-daemon-export-ok" -git -C "$dir" remote remove srht -git -C "$dir" remote remove github -rm "$dir/hooks/post-update" - -rm -rf "$web" - -repos="" -for d in "$reposdir/"*.git/; do - [ -f "$d/git-daemon-export-ok" ] && repos="$repos $d" -done - -echo "$repos" | xargs stagit-index > "$webdir/index.html" -echo "$dir is now private." diff --git a/make-public b/make-public @@ -1,56 +0,0 @@ -#!/bin/sh - -# path must be absolute -reposdir="/srv/git" -webdir="/srv/git/html" -defaultdir="/usr/local/share/doc/stagit" - -# Check number of params -[ $# -ne 1 ] && echo "Usage: make-public project[.git]" && exit 1 - -# Set the project name, adding .git if necessary -dir=$(echo "$1" | sed 's/\.git$\|$/.git/i') - -[ ! -d "$dir" ] && echo "$dir not found." && exit 1 - -[ -f "$dir/git-daemon-export-ok" ] && echo "$dir is already public." && exit - -touch "$dir/git-daemon-export-ok" -git -C "$dir" remote add srht "git@git.sr.ht:~ob/$(basename "$dir" ".git")" -git -C "$dir" remote add github "git@github.com:oscarbenedito/$(basename "$dir")" -ln -sf "$HOME/git-shell-commands/subscripts/post-update-public-repos" "$dir/hooks/post-update" - -git -C "$dir" update-server-info - -mkdir -p "$webdir" || exit 1 - -# set assets if not already there -ln -s "$defaultdir/style.css" "$webdir/style.css" 2> /dev/null -ln -s "$defaultdir/logo.png" "$webdir/logo.png" 2> /dev/null -ln -s "$defaultdir/favicon.ico" "$webdir/favicon.ico" 2> /dev/null - -# strip .git suffix -r=$(basename "$dir") -d=$(basename "$dir" ".git") -printf "%s... " "$d" - -mkdir -p "$webdir/$d" -cd "$webdir/$d" || continue -stagit -c ".stagit-build-cache" "$reposdir/$r" - -# symlinks -[ -f "about.html" ] \ - && ln -sf about.html index.html \ - || ln -sf log.html index.html -ln -sf "$reposdir/$r" ".git" - -echo "done" - -# make index -repos="" -for d in "$reposdir/"*.git/; do - [ -f "$d/git-daemon-export-ok" ] && repos="$repos $d" -done -echo "$repos" | xargs stagit-index > "$webdir/index.html" - -echo "$dir is now public." diff --git a/owner b/owner @@ -1,11 +0,0 @@ -#!/bin/sh - -# Check number of params -[ $# -ne 2 ] && echo "Usage: owner project[.git] owner" && exit 1 - -# Set the project name, adding .git if necessary -p=$(echo "$1" | sed 's/\.git$\|$/.git/i') - -[ ! -d "$p" ] && echo "$p not found." && exit 1 - -echo "$2" > "$p/owner" diff --git a/subscripts/mirror-repository b/subscripts/mirror-repository @@ -7,12 +7,12 @@ trap "notify \"ERROR pushing $repo\" \"There was an error pushing $repo to eithe dir="$(pwd)" repo="$(basename "$(pwd)" ".git")" -git -C "$dir" remote get-url srht || - \ git -C "$dir" remote add srht "git@git.sr.ht:~ob/$repo" +git -C "$dir" remote get-url srht || \ + git -C "$dir" remote add srht "git@git.sr.ht:~ob/$repo" git -C "$dir" push --all --force --prune srht git -C "$dir" push --tags --force --prune srht -git -C "$dir" remote get-url github || - \ git -C "$dir" remote add github "git@github.com:oscarbenedito/$repo" +git -C "$dir" remote get-url github || \ + git -C "$dir" remote add github "git@github.com:oscarbenedito/$repo" git -C "$dir" push --all --force --prune github git -C "$dir" push --tags --force --prune github diff --git a/url b/url @@ -1,11 +0,0 @@ -#!/bin/sh - -# Check number of params -[ $# -ne 2 ] && echo "Usage: url project[.git] url" && exit 1 - -# Set the project name, adding .git if necessary -p=$(echo "$1" | sed 's/\.git$\|$/.git/i') - -[ ! -d "$p" ] && echo "$p not found." && exit 1 - -echo "$2" > "$p/url"