cem-utils

Random utilities
git clone git://git.ckyln.com/~cem/cem-utils.git
Log | Files | Refs | README

commit f066420aa8f125d2018b51b43a38f882bf7a666f
parent 222083dcfa1b322e73607f1f589e907d76fa2239
Author: Cem Keylan <cem@ckyln.com>
Date:   Wed,  4 Mar 2020 10:36:25 +0300

kiss-stuff: add to cem-utils

Diffstat:
Akiss-stuff/Makefile | 11+++++++++++
Akiss-stuff/README | 6++++++
Akiss-stuff/kf | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akiss-stuff/kiss-repooutdated | 49+++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 142 insertions(+), 0 deletions(-)

diff --git a/kiss-stuff/Makefile b/kiss-stuff/Makefile @@ -0,0 +1,11 @@ +PREFIX = /usr/local +BINDIR = ${PREFIX}/bin + +install: + install -Dm755 -t ${DESTDIR}${BINDIR} kf kiss-repooutdated + +uninstall: + rm -f ${DESTDIR}${BINDIR}/kf + rm -f ${DESTDIR}${BINDIR}/kiss-repooutdated + +.PHONY: install uninstall diff --git a/kiss-stuff/README b/kiss-stuff/README @@ -0,0 +1,6 @@ +kiss-stuff +========== + +These are the tools I use for repository management. I +use them to automate stuff. Do not use "kf" unless you +are really sure of what you are doing. diff --git a/kiss-stuff/kf b/kiss-stuff/kf @@ -0,0 +1,76 @@ +#!/bin/sh + +# KISS functions that I use. Mostly +# for repository management. + +out() { printf '\033[1;36m-> \033[m%s\n' "$@" ;} +error() { printf '\033[1;31m!> error: \033[m%s\n' "$@" >&2 ;} +die() { error "$1" ; exit 1 ;} + +usage() { +out \ +"${0##*/} [a|b|n|h] [options]" \ +"add Commit the current directory as a new package" \ +"bump Commit current directory with a 'package: bump to version message'" \ +"help Print help information per function" \ +"new Create a template package with package-name, version, and source" +exit 1 +} + +help() { + case "$1" in + a|add) out "Resets git, adds current directory and commits" "with a 'package: add new package at version to repository' message" ; exit ;; + b|bump) out "Resets git, adds current directory and commits" "with a 'package: bump to version' message"; exit ;; + n|new) out "kf new <package> [version] [sources]"; exit ;; + h|help) out "kf help <function>" ; exit ;; + *) usage ;; esac +} + +add() { + [ "$1" ] && help add + [ -f version ] || die "Could not find version directory, are you sure that you are on a package directory?" + git reset + git add . + git commit -m "$(basename "$PWD"): add new package at $(cut -d ' ' -f 1 version) to $(basename "$(dirname "$PWD")")" +} + +bump() { + [ "$1" ] && help bump + [ -f version ] || die "Could not find version directory, are you sure that you are on a package directory?" + git reset + git add . + git commit -m "$(basename "$PWD"): bump to $(cut -d ' ' -f 1 version)" +} + +new() { + # 1: Package name + # 2: Package version + # 3: Package source + [ "$1" ] || help new + [ -d "$1" ] && die "Package $1 already exists" + mkdir -p "$1" || die "Couldn't create directory to ${PWD}/${1}" + out "Populating build file"; { + printf "#!/bin/sh -e\n" > "$1/build" + chmod +x "$1/build" + } + [ "$2" ] && { + out "Populating version file with '${2%% *} 1'" + printf '%s 1\n' "${2%% *}" > "$1/version" + } || printf " 1\n" > "$1/version" + + [ "$3" ] && { + out "Populating sources file with '$3'" + printf '%s\n' "$3" > "$1/sources" + } || :> "$1/sources" +} + +mode="$1" +shift + +case "$mode" in + a|add) add "$@" ;; + b|bump) bump "$@" ;; + n|new) new "$@" ;; + h|help) help "$1" ;; + *) usage ;; +esac diff --git a/kiss-stuff/kiss-repooutdated b/kiss-stuff/kiss-repooutdated @@ -0,0 +1,49 @@ +#!/bin/sh +# +# Check repository packages for updates. + +[ "$KISS_PATH" ] || + { printf '%s\n' 'KISS_PATH not set' >&2 ; exit 1 ;} + +old_IFS=$IFS + +printf '%s\n' "$KISS_PATH" | tr ':' '\n' | while read -r repo +do + find "$repo" ! -name .git -type d -mindepth 1 -maxdepth 1 +done | (while read -r pkg ; do { + read -r ver _ < "$pkg/version" + pkg=${pkg##*/} + + # Fix some package names. + case $pkg in + *-bin) fix=${pkg%%-bin} ;; + esac + + # Grab the repology version from the SVG file. + rep=$(curl -s "https://repology.org/badge/latest-versions/${fix:-$pkg}.svg") + rep=${rep%</text>*} + rep=${rep##*>} + + # Skip these. + # shellcheck disable=2106 + { + [ "${rep:--}" = - ] && continue + [ "$ver" = git ] && continue + } + + # Split the comma separated list. + # shellcheck disable=2086 + { + IFS=', ' + set -f + set +f -- $rep + IFS=$old_IFS + } + + # Parse comma separated version lists. + { + for v; do case $v in "$ver") match=1; esac; done + + [ "$match" ] || { [ "$rep" ] && printf '%s\n' "$pkg $ver -> $rep" ;} + } +} & done; wait)