From 2b0067eb4df168b490e675d67fcfa69401490e43 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 18 Aug 2024 23:59:13 -0300 Subject: [PATCH] Break up 'portzap-install' into multiple files --- Makefile | 5 +- libexec/portzap/commands/portzap-install | 76 ++++++------------- libexec/portzap/utils/install/run | 14 ++++ .../utils/install/update-changed-files | 28 +++++++ .../utils/install/update-deleted-files | 22 ++++++ share/portzap/CHANGELOG | 4 + 6 files changed, 95 insertions(+), 54 deletions(-) create mode 100755 libexec/portzap/utils/install/run create mode 100755 libexec/portzap/utils/install/update-changed-files create mode 100755 libexec/portzap/utils/install/update-deleted-files diff --git a/Makefile b/Makefile index 74f23d8..e4d2987 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,8 @@ install: @find share/ man/ -type f -exec install -v -m 0644 "{}" $(PREFIX)/"{}" \; deinstall: - rm $(BINDIR)/portzap - rm $(BINDIR)/setup-portzap - rm $(MANDIR)/portzap.8 + rm -rf $(BINDIR)/portzap + rm -rf $(MANDIR)/portzap.8 rm -rf $(LIBEXECDIR) rm -rf $(SHAREDIR) diff --git a/libexec/portzap/commands/portzap-install b/libexec/portzap/commands/portzap-install index d251382..0e4e331 100755 --- a/libexec/portzap/commands/portzap-install +++ b/libexec/portzap/commands/portzap-install @@ -5,7 +5,6 @@ set -e # variables localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} libexec="${localbase}"/libexec/portzap -mode=u=rwX,g=rX,o= git="${libexec}"/utils/git/run gitdir=$1 installdir=$2 @@ -16,51 +15,6 @@ revfile=$3 # shellcheck source=/dev/null . "${libexec}"/functions/print.sh -perform_update() -{ - rev=$(cat "${revfile}") - add=$("${libexec}"/utils/git/get-changed-files "${gitdir}" "${rev}") - del=$("${libexec}"/utils/git/get-removed-files "${gitdir}" "${rev}") - for file in ${del}; do - target="${installdir}/${file}" - parent=$(dirname "${target}") - echo "rm ${target}" - rm -f "${target}" - find "${parent}" -type d -maxdepth 0 -empty -delete - done - for file in ${add}; do - target="${installdir}/${file}" - parent=$(dirname "${target}") - parents="" - while [ ! -e "${parent}" ]; do - parents="${parent} ${parents}" - parent=$(dirname "${parent}") - done - for dir in ${parents}; do - run_install "-d" "${dir}" - done - run_install "${file}" "${target}" - done -} - -perform_install() -{ - find -s . \ - -maxdepth 1 \ - ! -name "." \ - ! -name ".git" \ - ! -name ".gitignore" \ - ! -name ".hooks" \ - ! -name ".arcconfig" \ - -exec cp -Rpv {} "${installdir}" \; - chown -Rv root "${installdir}" -} - -run_install() -{ - install -o root -g _portzap -m "${mode}" -v "${@}" -} - ## # main if [ "$(id -u)" != "0" ]; then @@ -68,14 +22,34 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi -umask "${mode}" cd "${gitdir}" -run_install "-d" "${installdir}" -chmod ${mode} "${installdir}" if [ -e "${revfile}" ]; then - perform_update + ## + # install update + rev=$(cat "${revfile}") + "${libexec}"/utils/install/run -d "${installdir}" + "${libexec}"/utils/install/update-deleted-files "${gitdir}" "${installdir}" "${rev}" + "${libexec}"/utils/install/update-changed-files "${gitdir}" "${installdir}" "${rev}" else - perform_install + ## + # install from scratch + umask u=rwX,g=rX,o= + "${libexec}"/utils/install/run -d "${installdir}" + find -s . \ + -maxdepth 1 \ + ! -name "." \ + ! -name ".git" \ + ! -name ".github" \ + ! -name ".gitignore" \ + ! -name ".gitattributes" \ + ! -name ".git-blame-ignore-revs" \ + ! -name ".cirrus-ci" \ + ! -name ".cirrus.yml" \ + ! -name ".gitignore" \ + ! -name ".arclint" \ + ! -name ".arcconfig" \ + -exec cp -Rpv {} "${installdir}" \; + chown -Rv root "${installdir}" fi "${git}" rev-parse HEAD > "${revfile}" printok "install complete" diff --git a/libexec/portzap/utils/install/run b/libexec/portzap/utils/install/run new file mode 100755 index 0000000..166fb34 --- /dev/null +++ b/libexec/portzap/utils/install/run @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +## +# variables +mode=u=rwX,g=rX,o= + +## +# main +install -o root \ + -g _portzap \ + -m "${mode}" \ + -v \ + "${@}" diff --git a/libexec/portzap/utils/install/update-changed-files b/libexec/portzap/utils/install/update-changed-files new file mode 100755 index 0000000..799dc2f --- /dev/null +++ b/libexec/portzap/utils/install/update-changed-files @@ -0,0 +1,28 @@ +#!/bin/sh +set -e + +## +# variables +localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../../..)} +libexec="${localbase}"/libexec/portzap +gitdir=$1 +installdir=$2 +rev=$3 + +## +# main +cd "${gitdir}" +files=$("${libexec}"/utils/git/get-changed-files "${gitdir}" "${rev}") +for file in ${files}; do + target="${installdir}/${file}" + parent=$(dirname "${target}") + parents="" + while [ ! -e "${parent}" ]; do + parents="${parent} ${parents}" + parent=$(dirname "${parent}") + done + for dir in ${parents}; do + "${libexec}"/utils/install/run -d "${dir}" + done + "${libexec}"/utils/install/run "${file}" "${target}" +done diff --git a/libexec/portzap/utils/install/update-deleted-files b/libexec/portzap/utils/install/update-deleted-files new file mode 100755 index 0000000..bb9af91 --- /dev/null +++ b/libexec/portzap/utils/install/update-deleted-files @@ -0,0 +1,22 @@ +#!/bin/sh +set -e + +## +# variables +localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../../..)} +libexec="${localbase}"/libexec/portzap +gitdir=$1 +installdir=$2 +rev=$3 + +## +# main +cd "${gitdir}" +files=$("${libexec}"/utils/git/get-removed-files "${gitdir}" "${rev}") +for file in ${files}; do + target="${installdir}"/"${file}" + parent=$(dirname "${target}") + echo "rm ${target}" + rm -f "${target}" + find "${parent}" -type d -maxdepth 0 -empty -delete +done diff --git a/share/portzap/CHANGELOG b/share/portzap/CHANGELOG index 9beefe2..111c614 100644 --- a/share/portzap/CHANGELOG +++ b/share/portzap/CHANGELOG @@ -1,5 +1,9 @@ * vNEXT +** Break up 'portzap-install' into multiple files +'libexec/portzap/utils/install/' contains files that cover both +a fresh install and applying an update + ** Add 'setup/setup-doas' improvements More likely to do what's expected, but blind spots still exist