Replace portzap-erase with portzap-rm

This commit is contained in:
0x1eef 2024-05-21 21:22:39 -03:00
parent 62a6fd7712
commit 397be0b927
3 changed files with 58 additions and 48 deletions

View file

@ -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

View file

@ -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"

View file

@ -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