From aeb39422452102a513686b3d334930c8aa3a09cc Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 10 Sep 2020 13:12:15 -0400 Subject: avoid building deps package if dependencies did not change also removed verbosity in various places --- Makefile | 2 +- selfpublish.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index fe41e10..a55f0be 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ self-publish: - sudo bash -x selfpublish.sh + sudo bash $(if $(VERBOSE),-x) selfpublish.sh diff --git a/selfpublish.sh b/selfpublish.sh index 98dd2df..d16ac53 100644 --- a/selfpublish.sh +++ b/selfpublish.sh @@ -47,24 +47,73 @@ dpkg_install() as_root $SHELL -c "set -$- +e; dpkg -i $*; apt-get -t buster-backports -f install" } +dependencies() +{ + cat <= 2.4.46) +cgit +curl +fortune-mod +fortunes-min +libssl1.1 (>= 1.1.1d) +EOF +} + +fmt_dependencies() +{ + local outline= + while read inline + do + if [ ! "$outline" ] + then + outline="Depends: $inline" + elif [ $((${#outline} + ${#inline})) -ge 60 ] + then + printf '%s,\n' "$outline" + outline=" $inline" + else + outline="$outline, $inline" + fi + done + if [ "$outline" ] + then + printf '%s\n' "$outline" + fi +} + + control_file() { cat <= 2.4.46), libssl1.1 (>= 1.1.1d), - fortune-mod, fortunes-min, curl, cgit Description: selfpublish.sh dependency package This package depends on the dependencies of the selfpublish.sh script, and is installed by that script to self-satisfy those dependencies. - EOF + dependencies | fmt_dependencies + echo +} + +control_file_unchanged() +{ + ( + destdir=$(mktemp -d) + trap 'rm -r "$destdir"' EXIT + dependencies > want-dependencies + dpkg-query -f '${Depends}\n' -W selfpublish-dot-sh-deps | sed 's/, */\n/g' | sort -u > have-dependencies + diff -q want-dependencies have-dependencies + ) } equivocate() { - if dpkg-query -s selfpublish-dot-sh-deps | grep -q '^Status: install ok installed' + if dpkg-query -s selfpublish-dot-sh-deps | grep -q '^Status: install ok installed' 2>/dev/null then + if ! force + then + control_file_unchanged && return + fi as_root dpkg -r selfpublish-dot-sh-deps fi which equivs-build >/dev/null 2>&1 || apt_install equivs @@ -72,7 +121,8 @@ equivocate() destdir=$(mktemp -d) cd "$destdir" control_file > ./control - equivs-build ./control >/dev/null 2>&1 + cat ./control + equivs-build ./control >&2 dpkg_install selfpublish-dot-sh-deps_1.0_all.deb ) } @@ -256,7 +306,7 @@ write_cgit_config() cgit_scan_dir=$SITE_DIR/public_git/ mkdir -p "$cgit_scan_dir" line="scan-path=$cgit_scan_dir" - grep -xF "$line" /etc/cgitrc || printf '%s\n' "$line" >> /etc/cgitrc + grep -qxF "$line" /etc/cgitrc || printf '%s\n' "$line" >> /etc/cgitrc } configure_apache_vhost() @@ -407,7 +457,7 @@ check_tls() curl -s -S -I https://"$1" >/dev/null } -[ "$NO_APT" ] || equivocate +[ "$NO_APT" ] || equivocate >&2 APACHE_MODULES='status md rewrite ssl include cgi' APACHE_SITE_DIRS='logs public_html' -- cgit v1.2.3