Compare commits

..

10 commits

Author SHA1 Message Date
3f625d08db Add gitdiff
Some checks are pending
portzap / shellcheck (push) Waiting to run
2024-07-02 08:33:21 -03:00
7de0fd39a0 Update README 2024-06-30 09:23:42 -03:00
8d8346d51f Add verify_denyfile, and other small fixes 2024-06-30 07:56:17 -03:00
69a66825ab Add setup-cron
Add a setup script that adds a crontab entry that
runs 'portzap pull' everyday at 12AM localtime
2024-06-30 04:25:23 -03:00
d3c3e3e2f0 Bump diff.renameLimit
After a successful clone, we set the configuration
knob 'diff.renameList' to 7000. This change is made
after observing a warning about the value being too
low.
2024-06-30 03:03:16 -03:00
b02c61fd8c Apply patterns consistently 2024-06-01 05:30:11 -03:00
fca5d70228 Update docs 2024-06-01 05:27:11 -03:00
48d182813c v0.12.0 2024-05-25 19:25:23 -03:00
d2eea33999 s|PORTZAP_GITURL|PORTZAP_CLONEURL|g 2024-05-23 17:00:03 -03:00
80edfe0da1 Fix example 2024-05-23 16:20:04 -03:00
17 changed files with 188 additions and 63 deletions

View file

@ -5,11 +5,12 @@ LIBEXECDIR = $(PREFIX)/libexec/portzap
SHAREDIR = $(PREFIX)/share/portzap SHAREDIR = $(PREFIX)/share/portzap
install: install:
install -d $(BINDIR) $(LIBEXECDIR) $(LIBEXECDIR)/commands $(LIBEXECDIR)/utils $(SHAREDIR) $(MANDIR) install -d $(BINDIR) $(LIBEXECDIR) $(LIBEXECDIR)/commands $(LIBEXECDIR)/utils $(LIBEXECDIR)/setup $(SHAREDIR) $(MANDIR)
install -m 0755 bin/portzap $(BINDIR) install -m 0755 bin/portzap $(BINDIR)
install -m 0755 bin/setup-portzap $(BINDIR) install -m 0755 bin/setup-portzap $(BINDIR)
install -m 0755 libexec/portzap/commands/* $(LIBEXECDIR)/commands install -m 0755 libexec/portzap/commands/* $(LIBEXECDIR)/commands
install -m 0755 libexec/portzap/utils/* $(LIBEXECDIR)/utils install -m 0755 libexec/portzap/utils/* $(LIBEXECDIR)/utils
install -m 0755 libexec/portzap/setup/* $(LIBEXECDIR)/setup
install -m 0644 share/portzap/* $(SHAREDIR) install -m 0644 share/portzap/* $(SHAREDIR)
install -m 0644 man/man8/portzap.8 $(MANDIR) install -m 0644 man/man8/portzap.8 $(MANDIR)
@ -24,3 +25,4 @@ shellcheck:
shellcheck bin/* shellcheck bin/*
shellcheck libexec/portzap/utils/* shellcheck libexec/portzap/utils/*
shellcheck libexec/portzap/commands/* shellcheck libexec/portzap/commands/*
shellcheck libexec/portzap/setup/*

View file

@ -41,8 +41,8 @@ the first time:
#### Environment #### Environment
* __$PORTZAP\_GITURL__ <br> * __$PORTZAP\_CLONEURL__ <br>
The URL to a git repository <br> The URL of a git repository <br>
Default: https://git.HardenedBSD.org/HardenedBSD/ports.git Default: https://git.HardenedBSD.org/HardenedBSD/ports.git
* __$PORTZAP\_INSTALLDIR__ <br> * __$PORTZAP\_INSTALLDIR__ <br>
@ -51,27 +51,26 @@ the first time:
## Install ## Install
**Port** #### Package
portzap is available portzap is available
[as a HardenedBSD port](https://git.HardenedBSD.org/HardenedBSD/ports/-/tree/HardenedBSD/main/hardenedbsd/portzap). <br> [from the HardenedBSD ports tree](https://git.HardenedBSD.org/HardenedBSD/ports/-/tree/HardenedBSD/main/hardenedbsd/portzap). <br>
`pkg install portzap` should work too but expect slower updates. `pkg install portzap` should work too but expect slower updates.
**Source** #### Git
The most recent version of portzap can be installed directly The most recent version of portzap can be installed via git:
via git:
user@localhost$ git clone https://github.com/0x1eef/portzap.git user@localhost$ git clone https://git.hardenedbsd.org/0x1eef/portzap.git
user@localhost$ cd portzap user@localhost$ cd portzap
root@localhost# root make install root@localhost# make install
root@localhost# setup-portzap root@localhost# setup-portzap
root@localhost# pw groupmod -n _portzap -m <user> root@localhost# pw groupmod -n _portzap -m <user>
## Requirements ## Requirements
* [doas](https://man.openbsd.org/doas) (`pkg install doas`) * [doas](https://man.openbsd.org/doas)
* [git](https://www.man7.org/linux/man-pages/man1/git.1.html) (`pkg install git`) * [git](https://www.man7.org/linux/man-pages/man1/git.1.html)
## Sources ## Sources

View file

@ -6,18 +6,20 @@ set -e
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)} localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
libexec="${localbase}"/libexec/portzap libexec="${localbase}"/libexec/portzap
gitdir="/home/_portzap/ports" gitdir="/home/_portzap/ports"
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}" giturl="${PORTZAP_CLONEURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
installdir="${PORTZAP_INSTALLDIR:-/usr/ports}" installdir="${PORTZAP_INSTALLDIR:-/usr/ports}"
defaultbranch="hardenedbsd/main" defaultbranch="hardenedbsd/main"
revfile="${installdir}"/.portzap revfile="${installdir}"/.portzap
## ##
# functions # functions
printerr() { printerr()
{
"${libexec}"/utils/printerr "$1" "${libexec}"/utils/printerr "$1"
} }
require_dependency() { require_dependency()
{
deps=$1 deps=$1
for dep in $deps; do for dep in $deps; do
if ! which -s "$dep"; then if ! which -s "$dep"; then

View file

@ -5,16 +5,16 @@ set -e
# variables # variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)} localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
libexec="${localbase}"/libexec/portzap libexec="${localbase}"/libexec/portzap
conf=$(cat "${localbase}"/share/portzap/doas.conf)
doas="${localbase}"/etc/doas.conf
## ##
# functions # functions
printok() { printok()
{
"${libexec}"/utils/printok "$1" "${libexec}"/utils/printok "$1"
} }
printerr() { printerr()
{
"${libexec}"/utils/printerr "$1" "${libexec}"/utils/printerr "$1"
} }
@ -33,15 +33,12 @@ else
-m \ -m \
-s /sbin/nologin -s /sbin/nologin
chmod u=rwX,g=rX,o= /home/_portzap/ chmod u=rwX,g=rX,o= /home/_portzap/
printok "create _portzap user" printok "_portzap user created"
fi fi
if grep -F "^${conf}$" "${doas}" > /dev/null 2>&1; then "${libexec}"/setup/setup-doas
printok "${doas} is up to date" "${libexec}"/setup/setup-cron
else echo
echo "$conf" >> "$doas" echo "If you haven't already, add users to the _portzap group: "
printok "update ${doas} (note: review the update)" echo "root@$(hostname)# pw groupmod -n _portzap -m user1,user2"
fi echo
printf "Add user(s) to the _portzap group:\n"
printf "root# pw groupmod -n _portzap -m user1,user2\n"

View file

@ -5,8 +5,8 @@ set -e
# variables # variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/portzap libexec="${localbase}"/libexec/portzap
gitdir="$1" gitdir=$1
branch="$2" branch=$2
## ##
# functions # functions
@ -16,11 +16,11 @@ gitexec()
} }
printok() { printok() {
"${libexec}"/utils/printok "$1" "${libexec}"/utils/printok "${1}"
} }
printerr() { printerr() {
"${libexec}"/utils/printerr "$1" "${libexec}"/utils/printerr "${1}"
} }
## ##

View file

@ -17,11 +17,11 @@ gitexec()
} }
printok() { printok() {
"${libexec}"/utils/printok "$1" "${libexec}"/utils/printok "${1}"
} }
printerr() { printerr() {
"${libexec}"/utils/printerr "$1" "${libexec}"/utils/printerr "${1}"
} }
## ##

View file

@ -55,15 +55,15 @@ perform_install()
run_install() run_install()
{ {
install -o root -g _portzap -m "${mode}" -v "$@" install -o root -g _portzap -m "${mode}" -v "${@}"
} }
printok() { printok() {
"${libexec}"/utils/printok "$1" "${libexec}"/utils/printok "${1}"
} }
printerr() { printerr() {
"${libexec}"/utils/printerr "$1" "${libexec}"/utils/printerr "${1}"
} }
## ##

View file

@ -15,11 +15,11 @@ gitexec()
} }
printok() { printok() {
"${libexec}"/utils/printok "$1" "${libexec}"/utils/printok "${1}"
} }
printerr() { printerr() {
"${libexec}"/utils/printerr "$1" "${libexec}"/utils/printerr "${1}"
} }
## ##

View file

@ -25,7 +25,7 @@ erase()
} }
printerr() { printerr() {
"${libexec}"/utils/printerr "$1" "${libexec}"/utils/printerr "${1}"
} }
## ##

View file

@ -0,0 +1,84 @@
#!/bin/sh
set -e
##
# variables
user="_portzap"
localbase=$(realpath "$(dirname "$0")"/../../..)
libexec="${localbase}"/libexec/portzap
sharedir="${localbase}"/share/portzap
##
# functions
printok()
{
"${libexec}"/utils/printok "$1"
}
printerr()
{
"${libexec}"/utils/printerr "$1"
}
verify_allowfile()
{
allowfile="/var/cron/allow"
if [ -e "${allowfile}" ]; then
if grep -Eqe "^${user}$" "${allowfile}"; then
printok "${user} found in ${allowfile}"
else
printerr "add ${user} to ${allowfile} in order to proceed"
exit 1
fi
else
printok "${allowfile} not found"
fi
}
verify_denyfile()
{
denyfile="/var/cron/deny"
if [ -e "${denyfile}" ]; then
if grep -Eqe "^${user}$" "${denyfile}"; then
printerr "remove ${user} from ${denyfile} in order to proceed"
exit 1
else
printok "${user} not found in ${denyfile}"
fi
else
printok "${denyfile} not found"
fi
}
install_crontab()
{
src="${sharedir}/crontab"
dest="/var/cron/tabs/${user}"
if [ -e "${dest}" ]; then
yes | crontab -u "${user}" -r
printok "crontab removed (${dest})"
fi
crontab -u "${user}" "${src}"
chmod u=rw,g=,o= "${dest}"
printok "crontab installed (${dest})"
}
##
# main
echo -n "configure portzap to run via cron(8) ? yes or no: "
while read -r r; do
case "${r}" in
yes|YES)
verify_allowfile
verify_denyfile
install_crontab
break
;;
no|NO)
break
;;
*)
echo -n "yes or no: "
;;
esac
done

View file

@ -0,0 +1,36 @@
#!/bin/sh
set -e
##
# variables
localbase=$(realpath "$(dirname "$0")"/../../..)
libexec="${localbase}/libexec/portzap"
sharedir="${localbase}/share/portzap"
##
# functions
printok()
{
"${libexec}"/utils/printok "$1"
}
printerr()
{
"${libexec}"/utils/printerr "$1"
}
install_doasconf()
{
src="${sharedir}/doas.conf"
dest="${localbase}/etc/doas.conf"
if grep -Fq "$(cat "${src}")" "${dest}"; then
printok "doas.conf looks up to date"
else
cat "${src}" >> "${dest}"
printok "${dest} has been updated"
fi
}
##
# main
install_doasconf

View file

@ -10,15 +10,13 @@ commit=$2
## ##
# functions # functions
gitexec() diff()
{ {
"${libexec}"/utils/gitexec "${1}" "${libexec}"/utils/gitdiff ${@}
} }
## ##
# main # main
cd "${gitdir}" cd "${gitdir}"
add=$(gitexec "diff --name-only --diff-filter=A ${commit} HEAD") diff "--name-only" "--diff-filter=A" "${commit}" "HEAD"
mod=$(gitexec "diff --name-only --diff-filter=M ${commit} HEAD") diff "--name-only" "--diff-filter=M" "${commit}" "HEAD"
echo "${add}"
echo "${mod}"

View file

@ -10,12 +10,12 @@ commit=$2
## ##
# functions # functions
gitexec() diff()
{ {
"${libexec}"/utils/gitexec "${1}" "${libexec}"/utils/gitdiff ${@}
} }
## ##
# main # main
cd "${gitdir}" cd "${gitdir}"
gitexec "diff --name-only --diff-filter=D ${commit} HEAD" diff "--name-only" "--diff-filter=D" "${commit}" "HEAD"

View file

@ -0,0 +1,11 @@
#!/bin/sh
set -e
##
# variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/portzap
##
# main
"${libexec}"/utils/gitexec diff -l0 ${@}

View file

@ -5,16 +5,11 @@
.Nm portzap .Nm portzap
.Nd manages a copy of the HardenedBSD ports tree .Nd manages a copy of the HardenedBSD ports tree
.Sh SYNOPSIS .Sh SYNOPSIS
.br .Nm portzap clone
portzap clone .Nm portzap pull
.br .Nm portzap checkout
portzap pull .Nm portzap install
.br .Nm portzap rm
portzap checkout
.br
portzap install
.br
portzap rm
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm portzap .Nm portzap
manages a copy of the HardenedBSD ports tree. manages a copy of the HardenedBSD ports tree.
@ -58,9 +53,9 @@ This command requires root privileges
.Sh ENVIRONMENT .Sh ENVIRONMENT
.sp .sp
.sp .sp
.Nm PORTZAP_GITURL .Nm PORTZAP_CLONEURL
.br .br
The URL to a git repository The URL of a git repository
.br .br
Default: https://git.HardenedBSD.org/HardenedBSD/ports.git Default: https://git.HardenedBSD.org/HardenedBSD/ports.git
.sp .sp

View file

@ -1 +1 @@
v0.11.5 v0.12.0

1
share/portzap/crontab Normal file
View file

@ -0,0 +1 @@
0 0 * * * /usr/local/bin/portzap pull