commit ddde8021b371c7e519e8dfbca5c1f403af7099dd
parent 6285c22a07893303bc8719afefe3e878ed6bc887
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 26 Sep 2023 23:09:34 +0200
Simplify install/uninstall
Diffstat:
4 files changed, 90 insertions(+), 25 deletions(-)
diff --git a/Makefile b/Makefile
@@ -210,19 +210,18 @@ getconf.o: getconf.h
getconf.h:
scripts/getconf.sh > $@
-install: all
- mkdir -p $(DESTDIR)$(PREFIX)/bin
- cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
- cd $(DESTDIR)$(PREFIX)/bin && ln -f test [ && chmod 755 $(BIN)
- mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
- mkdir -p $(DESTDIR)$(MANPREFIX)/man1
- for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
- cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
- mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
-
-uninstall:
- cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) [ install
- cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN) install.1
+install uninstall:
+ scripts/mkproto $@ $(DESTDIR)$(PREFIX) $(DESTDIR)$(MANPREFIX) proto
+ scripts/$@ proto
+
+sbase-box-install: sbase-box
+ scripts/mkproto $@ $(DESTDIR)$(PREFIX) $(DESTDIR)$(MANPREFIX) proto
+ scripts/$@ proto
+ $(DESTDIR)$(PREFIX)/bin/sbase-box -i $(DESTDIR)$(PREFIX)/bin/
+
+sbase-box-uninstall: sbase-box
+ $(DESTDIR)$(PREFIX)/bin/sbase-box -d $(DESTDIR)$(PREFIX)/bin/
+ $(MAKE) uninstall
dist: clean
mkdir -p sbase-$(VERSION)
@@ -235,21 +234,10 @@ sbase-box: $(BIN)
scripts/mkbox
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB)
-sbase-box-install: sbase-box
- mkdir -p $(DESTDIR)$(PREFIX)/bin
- mkdir -p $(DESTDIR)$(MANPREFIX)/man1
- cp -f sbase-box $(DESTDIR)$(PREFIX)/bin
- chmod 755 $(DESTDIR)$(PREFIX)/bin/sbase-box
- $(DESTDIR)$(PREFIX)/bin/sbase-box -i $(DESTDIR)$(PREFIX)/bin/
- cp -f $(MAN) $(DESTDIR)$(MANPREFIX)/man1/
- mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
-
-sbase-box-uninstall: uninstall
- cd $(DESTDIR)$(PREFIX)/bin && rm -f sbase-box
-
clean:
rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz
rm -f getconf.h
+ rm -f proto
rm -rf build
.PHONY: all install uninstall dist sbase-box-install sbase-box-uninstall clean
diff --git a/scripts/install b/scripts/install
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -e
+
+while read type src dst perm
+do
+ case $type in
+ d)
+ mkdir -p $src
+ ;;
+ c)
+ cp $src $dst
+ ;;
+ *)
+ echo install: wrong entry type >&2
+ exit 1
+ ;;
+ esac
+
+ chmod $perm $dst
+done < $1
diff --git a/scripts/mkproto b/scripts/mkproto
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+usage()
+{
+ echo mkproto: prefix manprefix proto>&2
+ exit 1
+}
+
+prefix=${1?$(usage)}
+manprefix=${2?$(usage)}
+proto=${3?$(usage)}
+
+trap "rm -f scripts/proto" EXIT INT QUIT TERM
+
+(set -e
+echo d $prefix/bin $prefix/bin 755
+find . -maxdepth 1 -type f -perm /111 |
+sed "s@.*@c & $prefix/bin/& 755@"
+
+echo d $manprefix/man1 $manprefix/man1 755
+find . -maxdepth 1 -name '*.1' |
+sed "s@.*@c & $manprefix/man1/& 644@") > $proto
+
+trap "" EXIT INT QUIT TERM
diff --git a/scripts/uninstall b/scripts/uninstall
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+set -e
+
+while read type src dst perm
+do
+ case $type in
+ d)
+ echo $type $src $dst $perm
+ continue
+ ;;
+ c)
+ rm -f $dst
+ ;;
+ *)
+ echo uninstall: wrong entry type >&2
+ exit 1
+ ;;
+ esac
+done < $1 |
+sort -r |
+while read type src dst perm
+do
+ case $type in
+ d)
+ if test `ls $dst | wc -l` -eq 0
+ then
+ rmdir $dst
+ fi
+ ;;
+ esac
+done