From 192ad140591b9618550157ed15b3265549326367 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sat, 3 Oct 2020 09:34:38 -0400 Subject: Rebuild the .deb only when needed Also fixed a bug related to blank lines in the control file. The format represents a blank line as a single '.' and literal '.' beginning a line is escaped as '..'. --- Makefile | 2 ++ selfpublish.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 1420696..99f3ab4 100644 --- a/Makefile +++ b/Makefile @@ -2,3 +2,5 @@ self-publish: sudo$(if $(FORCE), FORCE=y) bash$(if $(VERBOSE), -x) selfpublish.sh +fast: + sudo NO_APT=y bash selfpublish.sh diff --git a/selfpublish.sh b/selfpublish.sh index 56f1b68..3aa0a77 100644 --- a/selfpublish.sh +++ b/selfpublish.sh @@ -89,7 +89,52 @@ fmt_dependencies() control_file_file() { printf 'File: %s %s\n' "$1" "$2" - sed -e 's/^/ /' + sed -e ' s/^[.]/../; s/^$/./; s/^/ /; ' +} + +control_file_file_check() +{ + local prefix RESULT=0 header= data o + tempout=$(mktemp) + while [ "$header" ] || read header + do + set -- $header + case "$1" in + File:) + + case "$2" in + /*) ;; + *) return 1 ;; + esac + + :> "$tempout" + while IFS= read -r data + do + case "$data" in + ' .'*) + printf '%s\n' "${data# .}" >> "$tempout" + continue + ;; + ' '*) + printf '%s\n' "${data# }" >> "$tempout" + continue + ;; + esac + + if ! diff -q "$2" "$tempout" + then + RESULT=1 + install -v -m "$3" "$tempout" -T "$2" + fi + header=$data + continue 2 + + done + ;; + esac + header= + done + return $RESULT } SELF_VERSION='0.1' @@ -105,10 +150,10 @@ Description: selfpublish.sh dependency package script to self-satisfy those dependencies. EOF dependencies | fmt_dependencies - cat </dev/null then - if ! force + if control_file_unchanged && control_file | control_file_file_check then - control_file_unchanged && return + if ! force + then return + fi fi fi which equivs-build >/dev/null 2>&1 || apt_install equivs @@ -333,12 +380,15 @@ equivocate() destdir=$(mktemp -d) cd "$destdir" control_file > ./control - # cat ./control equivs-build ./control >&2 DEB=selfpublish-dot-sh_${SELF_VERSION}_all.deb - as_root dpkg -r selfpublish-dot-sh - dpkg_install "$DEB" - install -m0644 "$DEB" "$DEBDEST" + + if ! [ "$NO_APT" ] + then + as_root dpkg -r selfpublish-dot-sh + dpkg_install "$DEB" + install -m0644 "$DEB" "$DEBDEST" + fi ) || exit } @@ -765,7 +815,7 @@ check_tls() } DEBDEST=$(realpath .) -[ "$NO_APT" ] || equivocate >&2 +[ "$NO_EQUIVS" ] || equivocate >&2 APACHE_MODULES='status md rewrite ssl include cgi' APACHE_SITE_DIRS='logs public_html' -- cgit v1.2.3