summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile14
-rwxr-xr-xMakeinstall.rc52
-rwxr-xr-xMakeperms.rc8
-rwxr-xr-xMakeuninstall.rc30
4 files changed, 104 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..845d997
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+PREFIX = $(HOME)/cmd
+BIN = $(PREFIX)/bin
+
+all: perms install
+clean: uninstall install
+
+perms:
+ @./Makeperms.rc
+
+install:
+ @./Makeinstall.rc $(BIN)
+
+uninstall:
+ @./Makeuninstall.rc $(BIN)
diff --git a/Makeinstall.rc b/Makeinstall.rc
new file mode 100755
index 0000000..33c1cf9
--- /dev/null
+++ 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/Makeperms.rc b/Makeperms.rc
new file mode 100755
index 0000000..d328469
--- /dev/null
+++ b/Makeperms.rc
@@ -0,0 +1,8 @@
+#!/bin/rc
+
+for (f in `$nl{find . -type f ! -name 'Make*' | grep -v '/\.' | sed 's/^\.\///'}) {
+ if (!test -x $f && head -n1 < $f | grep '^#!' >/dev/null) {
+ echo CHMOD +X $f
+ chmod +x $f
+ }
+}
diff --git a/Makeuninstall.rc b/Makeuninstall.rc
new file mode 100755
index 0000000..5ee5003
--- /dev/null
+++ 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
+}