Add "portzap erase"

I haven't decided whether or not only root can do this (leaning towards
not), and we might want to be more flexible and let the user choose to
delete one of the two directories. For now it works.
This commit is contained in:
0x1eef 2024-04-17 20:21:34 -03:00
parent b22f32c12c
commit 50d648f06a
4 changed files with 45 additions and 0 deletions

View file

@ -51,6 +51,10 @@ case $1 in
require_membership_of _portzap require_membership_of _portzap
doas -u _portzap "${libexec}"/portzap-pull "${gitdir}" "${branch}" doas -u _portzap "${libexec}"/portzap-pull "${gitdir}" "${branch}"
;; ;;
"erase")
require_membership_of _portzap
doas -u _portzap "${libexec}"/portzap-erase "${gitdir}" "${installdir}"
;;
"install") "install")
require_root require_root
require_dependency "git doas" require_dependency "git doas"
@ -67,6 +71,7 @@ case $1 in
printf " clone Clone the hardenedbsd ports tree.\n" printf " clone Clone the hardenedbsd ports tree.\n"
printf " pull Pull updates from the hardenedbsd ports tree.\n" printf " pull Pull updates from the hardenedbsd ports tree.\n"
printf " install Install the ports tree into /usr/ports.\n" printf " install Install the ports tree into /usr/ports.\n"
printf " erase Erase /usr/ports/ and /home/_portzap/ports/.\n"
printf " setup Add the _portzap user, group and home directory.\n" printf " setup Add the _portzap user, group and home directory.\n"
;; ;;
esac esac

View file

@ -0,0 +1,38 @@
#!/bin/sh -e
##
# variables
gitdir=$1
installdir=$2
##
# main
printf "[-] Are you sure ? \n"
printf "[-] These directories will be erased:\n"
printf " [*] ${gitdir}\n"
printf " [*] ${installdir}\n"
printf "[y|n] "
while true; do
read r
if [ "${r}" = "y" ]; then
break
elif [ "${r}" = "n" ]; then
printf "[-] Nothing to do\n"
exit
else
printf "[-] '${r}' is not a valid option.\n"
printf "[y|n] "
fi
done
for dir in "${gitdir}" "${installdir}"; do
printf "${dir} "
find "${dir}" \
-maxdepth 1 \
\! -name "." \
\! -name ".." \
\! -name "ports" \
-exec printf . \; \
-exec rm -rf "{}" \;
echo
done
printf "[-] Done\n"

View file

@ -58,6 +58,7 @@ umask u=rwX,g=rwX,o=
cd "${gitdir}" cd "${gitdir}"
set +x set +x
run_install "-d" "${installdir}" run_install "-d" "${installdir}"
chmod u=rwx,g=rwx,o= "${installdir}"
if [ -e "${revfile}" ]; then if [ -e "${revfile}" ]; then
perform_update perform_update
else else

View file

@ -2,6 +2,7 @@
# portzap # portzap
permit nopass :_portzap as _portzap cmd /usr/local/libexec/portzap/portzap-clone permit nopass :_portzap as _portzap cmd /usr/local/libexec/portzap/portzap-clone
permit nopass :_portzap as _portzap cmd /usr/local/libexec/portzap/portzap-pull permit nopass :_portzap as _portzap cmd /usr/local/libexec/portzap/portzap-pull
permit nopass :_portzap as _portzap cmd /usr/local/libexec/portzap/portzap-erase
permit nopass root as _portzap cmd /usr/local/libexec/portzap/git-changed-files permit nopass root as _portzap cmd /usr/local/libexec/portzap/git-changed-files
permit nopass root as _portzap cmd /usr/local/libexec/portzap/git-removed-files permit nopass root as _portzap cmd /usr/local/libexec/portzap/git-removed-files
permit nopass root as _portzap cmd /usr/local/libexec/portzap/git-rev permit nopass root as _portzap cmd /usr/local/libexec/portzap/git-rev