Delegate 'portzap clone|pull' to the _portzap user (via doas)

This commit is contained in:
0x1eef 2024-04-07 20:27:18 -03:00
parent b88947dbd1
commit ea6a5e46e5
9 changed files with 73 additions and 31 deletions

View file

@ -1,18 +1,21 @@
PREFIX = /usr/local PREFIX = /usr/local
BINDIR = $(PREFIX)/bin BINDIR = $(PREFIX)/bin
LIBEXECDIR = $(PREFIX)/libexec/portzap
MANDIR = $(PREFIX)/man/man8 MANDIR = $(PREFIX)/man/man8
LIBEXECDIR = $(PREFIX)/libexec/portzap
SHAREDIR = $(PREFIX)/share/portzap
install: install:
install -d $(BINDIR) $(LIBEXECDIR) $(MANDIR) install -d $(BINDIR) $(LIBEXECDIR) $(SHAREDIR) $(MANDIR)
install -m 0755 bin/portzap $(BINDIR) install -m 0755 bin/portzap $(BINDIR)
install -m 0755 libexec/portzap/* $(LIBEXECDIR) install -m 0755 libexec/portzap/* $(LIBEXECDIR)
install -m 0644 share/portzap/* $(SHAREDIR)
install -m 0644 man/man8/portzap.8 $(MANDIR) install -m 0644 man/man8/portzap.8 $(MANDIR)
deinstall: deinstall:
rm $(BINDIR)/portzap
rm $(MANDIR)/portzap.8
rm -rf $(LIBEXECDIR) rm -rf $(LIBEXECDIR)
rm -f $(BINDIR)/portzap rm -rf $(SHAREDIR)
rm -f $(MANDIR)/portzap.8
shellcheck: shellcheck:
shellcheck bin/portzap shellcheck bin/portzap

View file

@ -8,16 +8,20 @@ portzap is a utility that manages a local copy of the
**CLI** **CLI**
# Clone the hardenedbsd ports tree into /home/_portzap/ports/. # Clone the hardenedbsd ports tree into /home/_portzap/ports/.
# This command is delegated to the '_portzap' user.
$ portzap clone $ portzap clone
# Pull updates into /home/_portzap/ports/. # Pull updates into /home/_portzap/ports/.
# This command is delegated to the '_portzap' user.
$ portzap pull $ portzap pull
# Install /home/_portzap/ports/ into /usr/ports/. # Install /home/_portzap/ports/ into /usr/ports/.
# This command requires root privileges.
# portzap install # portzap install
# Add the portzap user, group and home directory. # Add the portzap user, group and home directory.
# portzap adduser # This command requires root privileges.
# portzap setup
**ENVIRONMENT VARIABLES** **ENVIRONMENT VARIABLES**
@ -34,9 +38,14 @@ portzap is a utility that manages a local copy of the
$ git clone https://github.com/0x1eef/portzap.git $ git clone https://github.com/0x1eef/portzap.git
$ cd portzap $ cd portzap
# make install # make install
# portzap adduser # portzap setup
# pw groupmod -n _portzap -m <user> # pw groupmod -n _portzap -m <user>
## Requirements
* [doas](https://man.openbsd.org/doas) <br>
pkg install doas
## Sources ## Sources
* [GitHub](https://github.com/0x1eef/portzap) * [GitHub](https://github.com/0x1eef/portzap)

View file

@ -43,21 +43,21 @@ case $1 in
"clone") "clone")
require_dependency git require_dependency git
require_membership_of _portzap require_membership_of _portzap
"${libexec}"/portzap-clone "${giturl}" "${gitdir}" doas -u _portzap "${libexec}"/portzap-clone "${giturl}" "${gitdir}"
;; ;;
"pull") "pull")
require_dependency git require_dependency git
require_membership_of _portzap require_membership_of _portzap
"${libexec}"/portzap-pull "${gitdir}" doas -u _portzap "${libexec}"/portzap-pull "${gitdir}"
;; ;;
"install") "install")
require_root require_root
require_dependency git require_dependency git
"${libexec}"/portzap-install "${gitdir}" "${installdir}" "${revision}" "${libexec}"/portzap-install "${gitdir}" "${installdir}" "${revision}"
;; ;;
"adduser") "setup")
require_root require_root
"${libexec}"/portzap-adduser "${libexec}"/portzap-setup
;; ;;
*) *)
printf "Usage: portzap COMMAND [OPTIONS]\n" printf "Usage: portzap COMMAND [OPTIONS]\n"
@ -66,6 +66,6 @@ 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 " adduser Add the portzap user, group and home directory.\n" printf " setup Add the _portzap user, group and home directory.\n"
;; ;;
esac esac

View file

@ -1,10 +0,0 @@
#!/bin/sh -e
##
# main
pw useradd -n _portzap \
-c "portzap user" \
-m \
-s /sbin/nologin
chmod -R u=rwX,g=rwX,o= /home/_portzap/
echo OK

View file

@ -12,6 +12,7 @@ if [ -e "${gitdir}/.git" ]; then
echo "Try 'portzap pull' instead." echo "Try 'portzap pull' instead."
exit 1 exit 1
fi fi
umask u=rwX,g=rwX,o= umask u=rwX,g=rX,o=rX
set -x set -x
git clone --depth 1 "${giturl}" "${gitdir}" git clone --depth 1 "${giturl}" "${gitdir}"
cd "${gitdir}"

View file

@ -6,7 +6,7 @@ gitdir=$1
## ##
# main # main
umask u=rwX,g=rwX,o= umask u=rwX,g=rX,o=rX
if [ -e "${gitdir}/.git" ]; then if [ -e "${gitdir}/.git" ]; then
set -x set -x
cd "${gitdir}" cd "${gitdir}"

22
libexec/portzap/portzap-setup Executable file
View file

@ -0,0 +1,22 @@
#!/bin/sh -e
##
# variables
conf=$(cat /usr/local/share/portzap/doas.conf)
doas=/usr/local/etc/doas.conf
##
# main
if ! id -u _portzap > /dev/null 2>&1; then
pw useradd -n _portzap \
-c "portzap user" \
-m \
-s /sbin/nologin
chmod u=rwX,g=rX,o= /home/_portzap/
echo "[ok] add _portzap user, group and home directory"
fi
if ! fgrep "${conf}" "${doas}" > /dev/null 2>&1; then
echo "${conf}" >> "${doas}"
echo "[ok] update ${doas}"
fi

View file

@ -12,35 +12,50 @@ portzap pull
.br .br
portzap install portzap install
.br .br
portzap adduser portzap setup
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm portzap .Nm portzap
manages a copy of the hardenedbsd ports tree. manages a copy of the hardenedbsd ports tree.
.Sh EXAMPLES .Sh EXAMPLES
.Pp .sp
.sp
.Nm portzap clone .Nm portzap clone
.br .br
Clone the hardenedbsd ports tree into /home/_portzap/ports/. Clone the hardenedbsd ports tree into /home/_portzap/ports/.
.br
This command is delegated to the '_portzap' user.
.Pp .Pp
.Nm portzap pull .Nm portzap pull
.br .br
Pull updates into /home/_portzap/ports/. Pull updates into /home/_portzap/ports/.
.br
This command is delegated to the '_portzap' user.
.Pp .Pp
.Nm portzap install .Nm portzap install
.br .br
Install /home/_portzap/ports/ into /usr/ports/. Install /home/_portzap/ports/ into /usr/ports/.
.br
This command requires root privileges.
.Pp .Pp
.Nm portzap adduser .Nm portzap setup
.br .br
Add the portzap user, group and home directory. Add the portzap user, group and home directory.
.br
This command requires root privileges.
.Sh ENVIRONMENT VARIABLES .Sh ENVIRONMENT VARIABLES
.Pp .sp
.Bl -tag -width $PORTZAP_GITURL .sp
.It Ev PORTZAP_GITURL .Nm PORTZAP_GITURL
.br
The URL to a git repository. The URL to a git repository.
.br
Default: https://git.hardenedbsd.org/hardenedbsd/ports.git Default: https://git.hardenedbsd.org/hardenedbsd/ports.git
.It Ev PORTZAP_INSTALLDIR .sp
The directory where the ports collection will be installed. Default: /usr/ports/. .Nm PORTZAP_INSTALLDIR
.br
The directory where the ports collection will be installed.
.br
Default: /usr/ports/
.Sh AUTHORS .Sh AUTHORS
The The
.Nm portzap .Nm portzap

2
share/portzap/doas.conf Normal file
View file

@ -0,0 +1,2 @@
permit nopass :_portzap as _portzap cmd /usr/local/libexec/portzap/portzap-clone
permit nopass :_portzap as _portzap cmd /usr/local/libexec/portzap/portzap-pull