src.hhvn.uk > hhvn.uk-scripts > commit > 216202e2cdff9623f815ac998c1b865168ff1583

scripts that power hhvn.uk
Log | Files | Refs | README

commit 216202e2cdff9623f815ac998c1b865168ff1583
Author: Hayden Hamilton <hayden@hhvn.uk>
Date:   Sun, 24 May 2026 13:48:38 +0100

Tracked install/uninstall/clean of scripts

Diffstat:
A.gitignore | 2++
AMakeclean.rc | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AMakefile | 11+++++++++++
AMakeinstall.rc | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
AMakeuninstall.rc | 30++++++++++++++++++++++++++++++
5 files changed, 164 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,2 @@ +.installed +.dirsmade diff --git a/Makeclean.rc b/Makeclean.rc @@ -0,0 +1,69 @@ +#!/bin/rc + +# This script will remove any deleted scripts/dirs previously copied into $1 +# If a directory is present, has previously been copied into $1, +# but no longer contains any executable scripts, this will also be removed. + +bin = $1 + +touch .installed .dirsmade +installed = `$nl{cat .installed} +dirsmade = `$nl{cat .dirsmade} + +fn sigexit { + if (~ $clean_installed ()) { + rm .installed + } else { + {for (s in $clean_installed) { echo $s }} > .installed + } + + if (~ $clean_dirsmade ()) { + rm .dirsmade + } else { + {for (d in $clean_dirsmade) { echo $d }} > .dirsmade + } +} + +for (s in $installed) { + p = $bin/$s + if (test -f $s && test -x $s) { + clean_installed = ($clean_installed $s) + } else { + echo RM $p + rm $p + removed = ($removed $p) + } +} + +fn check_dir_used { + d = $1 { + for (s in $clean_installed) { + ds = `$nl{dirname $s} + if (!~ $ds '.') { + p = '.' + for (e in `$nl'/'{echo $ds}) { + p = $p/$e + if (~ `$nl{echo $p | sed 's/^\.\///'} $d){ + return 0 + } + } + } + } + } + return 1 +} + +for (d in $dirsmade) { + p = $bin/$d + if (test -d $d && check_dir_used $d) { + clean_dirsmade = ($clean_dirsmade $d) + } else { + echo RMDIR $p + rmdir $p + removed = ($removed $p) + } +} + +if (~ $removed ()) { + echo nothing to clean +} diff --git a/Makefile b/Makefile @@ -0,0 +1,11 @@ +PREFIX = $(HOME)/cmd +BIN = $(PREFIX)/bin + +clean: + @./Makeclean.rc $(BIN) + +install: + @./Makeinstall.rc $(BIN) + +uninstall: + @./Makeuninstall.rc $(BIN) diff --git a/Makeinstall.rc b/Makeinstall.rc @@ -0,0 +1,52 @@ +#!/bin/rc + +# This script will install all executables in the current directory to $1 +# Directory structure is preserved +# It stores a list of everything it has transferred / created + +bin = $1 + +scripts = `$nl{find . -perm 0755 -type f ! -name 'Make*' | grep -v '/\.' | sed 's/^\.\///'} + +touch .installed .dirsmade +installed = `$nl{cat .installed} +dirsmade = `$nl{cat .dirsmade} + +# Stores lists before exiting. +# This is the last step regardless of success +fn sigexit { + {for (s in $installed) { echo $s }} > .installed + {for (d in $dirsmade) { echo $d }} > .dirsmade +} + +for (s in $scripts) { + d = `$nl{dirname $s} + if (!~ $d '.') { + # could use mkdir -p here, however in order to actually keep a + # list of what's been made, use a for loop + + p = $bin + for (e in `($nl '/'){echo $d}) { + p = $p/$e + if (!test -d $p) { + echo MKDIR $p + mkdir $p || exit 1 + + # add to list if not already present + if (!~ $d $dirsmade) { + dirsmade = ($dirsmade $d) + } + } + } + } + + if (!cmp -s $s $bin/$s) { + echo CP $s $bin/$s + cp $s $bin/$s + if (!~ $s $installed) { + installed = ($installed $s) + } + } +} + +echo everything up to date diff --git a/Makeuninstall.rc b/Makeuninstall.rc @@ -0,0 +1,30 @@ +#!/bin/rc + +# This script will uninstall all scripts/dirs copied into $1 +# It uses rmdir(1) to prevent removal of any files from elsewhere + +bin = $1 + +if (test -f .installed) { + installed = `$nl{cat .installed} + for (s in $installed) { + echo RM $bin/$s + rm $bin/$s + removed = ($removed $bin/$s) + } + rm .installed +} + +if (test -f .dirsmade) { + dirsmade = `$nl{cat .dirsmade} + for (d in $dirsmade) { + echo RMDIR $bin/$d + rmdir $bin/$d + removed = ($removed $bin/$s) + } + rm .dirsmade +} + +if (~ $removed ()) { + echo nothing to remove +}