From 397be0b927f4ff339b035e5fd83e2dfb2c1baa88 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Tue, 21 May 2024 21:22:39 -0300 Subject: [PATCH] Replace portzap-erase with portzap-rm --- bin/portzap | 8 +++--- libexec/portzap/portzap-erase | 44 ---------------------------- libexec/portzap/portzap-rm | 54 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 48 deletions(-) delete mode 100644 libexec/portzap/portzap-erase create mode 100644 libexec/portzap/portzap-rm diff --git a/bin/portzap b/bin/portzap index 6e12661..c609a3a 100755 --- a/bin/portzap +++ b/bin/portzap @@ -17,7 +17,7 @@ require_dependency() { deps=$1 for dep in $deps; do if ! which -s "$dep"; then - echo "[-] This command requires ${dep}, but ${dep} wasn't found" + echo "[x] This command requires ${dep}, but ${dep} wasn't found" exit 1 fi done @@ -46,8 +46,8 @@ case $1 in require_dependency "git doas" "${libexec}"/portzap-pull "${gitdir}" "${branch}" ;; - "erase") - "${libexec}"/portzap-erase "${gitdir}" "${installdir}" + "rm") + "${libexec}"/portzap-rm "${gitdir}" "${installdir}" ;; "install") require_dependency "git doas" @@ -59,7 +59,7 @@ case $1 in printf "Commands:\n" printf " clone Clone the hardenedbsd ports tree.\n" printf " pull Pull updates from the hardenedbsd ports tree.\n" - printf " erase Erase /usr/ports/ and /home/_portzap/ports/.\n" + printf " rm Remove /usr/ports/ and /home/_portzap/ports/.\n" printf " install Install the ports tree into /usr/ports/.\n" ;; esac diff --git a/libexec/portzap/portzap-erase b/libexec/portzap/portzap-erase deleted file mode 100644 index 32e7617..0000000 --- a/libexec/portzap/portzap-erase +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh -set -e - -## -# variables -gitdir=$1 -installdir=$2 - -## -# main -if [ "$(id -u)" != "0" ]; then - echo "[-] This command must be run by root" - exit 1 -fi - -printf "[-] Are you sure ? \n" -printf "[-] These directories will be erased:\n" -printf " [*] %s \n" "${gitdir}" -printf " [*] %s \n" "${installdir}" -printf "[y|n] " -while true; do - read -r r - if [ "${r}" = "y" ]; then - break - elif [ "${r}" = "n" ]; then - printf "[-] Nothing to do\n" - exit - else - printf "[-] '%s' is not a valid option.\n" "${r}" - printf "[y|n] " - fi -done -for dir in "${gitdir}" "${installdir}"; do - printf "%s " "${dir}" - find "${dir}" \ - -maxdepth 1 \ - \! -name "." \ - \! -name ".." \ - \! -name "ports" \ - -exec printf . \; \ - -exec rm -rf "{}" \; - echo -done -printf "[-] Done\n" diff --git a/libexec/portzap/portzap-rm b/libexec/portzap/portzap-rm new file mode 100644 index 0000000..04c62f4 --- /dev/null +++ b/libexec/portzap/portzap-rm @@ -0,0 +1,54 @@ +#!/bin/sh +set -e + +## +# variables +gitdir=$1 +installdir=$2 + +## +# functions +erase() +{ + dir="${1}" + printf "%s " "${dir}" + find "${dir}" \ + -maxdepth 1 \ + \! -name "." \ + \! -name ".." \ + \! -name "ports" \ + -exec printf . \; \ + -exec rm -rf "{}" \; + echo +} + +## +# main +if [ "$(id -u)" != "0" ]; then + echo "[-] This command must be run by root" + exit 1 +fi + +printf "1 Remove the contents of %s\n" "${gitdir}" +printf "2 Remove the contents of %s\n" "${installdir}" +printf "3 Remove the contents of both (%s and %s)\n" "${gitdir}" "${installdir}" +printf "4 Do nothing\n" +printf "1-4: " +while true; do + read -r r + if [ "${r}" = "1" ]; then + erase "${gitdir}" + elif [ "${r}" = "2" ]; then + erase "${installdir}" + elif [ "${r}" = "3" ]; then + erase "${gitdir}" + erase "${installdir}" + elif [ "${r}" = "4" ]; then + break + else + printf "%s is not a valid option\n" "${r}" + printf "1-4: " + continue + fi + exit +done