Compare commits
10 commits
00def5a087
...
3f625d08db
Author | SHA1 | Date | |
---|---|---|---|
3f625d08db | |||
7de0fd39a0 | |||
8d8346d51f | |||
69a66825ab | |||
d3c3e3e2f0 | |||
b02c61fd8c | |||
fca5d70228 | |||
48d182813c | |||
d2eea33999 | |||
80edfe0da1 |
17 changed files with 188 additions and 63 deletions
4
Makefile
4
Makefile
|
@ -5,11 +5,12 @@ LIBEXECDIR = $(PREFIX)/libexec/portzap
|
|||
SHAREDIR = $(PREFIX)/share/portzap
|
||||
|
||||
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/setup-portzap $(BINDIR)
|
||||
install -m 0755 libexec/portzap/commands/* $(LIBEXECDIR)/commands
|
||||
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 man/man8/portzap.8 $(MANDIR)
|
||||
|
||||
|
@ -24,3 +25,4 @@ shellcheck:
|
|||
shellcheck bin/*
|
||||
shellcheck libexec/portzap/utils/*
|
||||
shellcheck libexec/portzap/commands/*
|
||||
shellcheck libexec/portzap/setup/*
|
||||
|
|
21
README.md
21
README.md
|
@ -41,8 +41,8 @@ the first time:
|
|||
|
||||
#### Environment
|
||||
|
||||
* __$PORTZAP\_GITURL__ <br>
|
||||
The URL to a git repository <br>
|
||||
* __$PORTZAP\_CLONEURL__ <br>
|
||||
The URL of a git repository <br>
|
||||
Default: https://git.HardenedBSD.org/HardenedBSD/ports.git
|
||||
|
||||
* __$PORTZAP\_INSTALLDIR__ <br>
|
||||
|
@ -51,27 +51,26 @@ the first time:
|
|||
|
||||
## Install
|
||||
|
||||
**Port**
|
||||
#### Package
|
||||
|
||||
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.
|
||||
|
||||
**Source**
|
||||
#### Git
|
||||
|
||||
The most recent version of portzap can be installed directly
|
||||
via git:
|
||||
The most recent version of portzap can be installed 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
|
||||
root@localhost# root make install
|
||||
root@localhost# make install
|
||||
root@localhost# setup-portzap
|
||||
root@localhost# pw groupmod -n _portzap -m <user>
|
||||
|
||||
## Requirements
|
||||
|
||||
* [doas](https://man.openbsd.org/doas) (`pkg install doas`)
|
||||
* [git](https://www.man7.org/linux/man-pages/man1/git.1.html) (`pkg install git`)
|
||||
* [doas](https://man.openbsd.org/doas)
|
||||
* [git](https://www.man7.org/linux/man-pages/man1/git.1.html)
|
||||
|
||||
## Sources
|
||||
|
||||
|
|
|
@ -6,18 +6,20 @@ set -e
|
|||
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
|
||||
libexec="${localbase}"/libexec/portzap
|
||||
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}"
|
||||
defaultbranch="hardenedbsd/main"
|
||||
revfile="${installdir}"/.portzap
|
||||
|
||||
##
|
||||
# functions
|
||||
printerr() {
|
||||
printerr()
|
||||
{
|
||||
"${libexec}"/utils/printerr "$1"
|
||||
}
|
||||
|
||||
require_dependency() {
|
||||
require_dependency()
|
||||
{
|
||||
deps=$1
|
||||
for dep in $deps; do
|
||||
if ! which -s "$dep"; then
|
||||
|
|
|
@ -5,16 +5,16 @@ set -e
|
|||
# variables
|
||||
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
|
||||
libexec="${localbase}"/libexec/portzap
|
||||
conf=$(cat "${localbase}"/share/portzap/doas.conf)
|
||||
doas="${localbase}"/etc/doas.conf
|
||||
|
||||
##
|
||||
# functions
|
||||
printok() {
|
||||
printok()
|
||||
{
|
||||
"${libexec}"/utils/printok "$1"
|
||||
}
|
||||
|
||||
printerr() {
|
||||
printerr()
|
||||
{
|
||||
"${libexec}"/utils/printerr "$1"
|
||||
}
|
||||
|
||||
|
@ -33,15 +33,12 @@ else
|
|||
-m \
|
||||
-s /sbin/nologin
|
||||
chmod u=rwX,g=rX,o= /home/_portzap/
|
||||
printok "create _portzap user"
|
||||
printok "_portzap user created"
|
||||
fi
|
||||
|
||||
if grep -F "^${conf}$" "${doas}" > /dev/null 2>&1; then
|
||||
printok "${doas} is up to date"
|
||||
else
|
||||
echo "$conf" >> "$doas"
|
||||
printok "update ${doas} (note: review the update)"
|
||||
fi
|
||||
|
||||
printf "Add user(s) to the _portzap group:\n"
|
||||
printf "root# pw groupmod -n _portzap -m user1,user2\n"
|
||||
"${libexec}"/setup/setup-doas
|
||||
"${libexec}"/setup/setup-cron
|
||||
echo
|
||||
echo "If you haven't already, add users to the _portzap group: "
|
||||
echo "root@$(hostname)# pw groupmod -n _portzap -m user1,user2"
|
||||
echo
|
||||
|
|
|
@ -5,8 +5,8 @@ set -e
|
|||
# variables
|
||||
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
|
||||
libexec="${localbase}"/libexec/portzap
|
||||
gitdir="$1"
|
||||
branch="$2"
|
||||
gitdir=$1
|
||||
branch=$2
|
||||
|
||||
##
|
||||
# functions
|
||||
|
@ -16,11 +16,11 @@ gitexec()
|
|||
}
|
||||
|
||||
printok() {
|
||||
"${libexec}"/utils/printok "$1"
|
||||
"${libexec}"/utils/printok "${1}"
|
||||
}
|
||||
|
||||
printerr() {
|
||||
"${libexec}"/utils/printerr "$1"
|
||||
"${libexec}"/utils/printerr "${1}"
|
||||
}
|
||||
|
||||
##
|
||||
|
|
|
@ -17,11 +17,11 @@ gitexec()
|
|||
}
|
||||
|
||||
printok() {
|
||||
"${libexec}"/utils/printok "$1"
|
||||
"${libexec}"/utils/printok "${1}"
|
||||
}
|
||||
|
||||
printerr() {
|
||||
"${libexec}"/utils/printerr "$1"
|
||||
"${libexec}"/utils/printerr "${1}"
|
||||
}
|
||||
|
||||
##
|
||||
|
|
|
@ -55,15 +55,15 @@ perform_install()
|
|||
|
||||
run_install()
|
||||
{
|
||||
install -o root -g _portzap -m "${mode}" -v "$@"
|
||||
install -o root -g _portzap -m "${mode}" -v "${@}"
|
||||
}
|
||||
|
||||
printok() {
|
||||
"${libexec}"/utils/printok "$1"
|
||||
"${libexec}"/utils/printok "${1}"
|
||||
}
|
||||
|
||||
printerr() {
|
||||
"${libexec}"/utils/printerr "$1"
|
||||
"${libexec}"/utils/printerr "${1}"
|
||||
}
|
||||
|
||||
##
|
||||
|
|
|
@ -15,11 +15,11 @@ gitexec()
|
|||
}
|
||||
|
||||
printok() {
|
||||
"${libexec}"/utils/printok "$1"
|
||||
"${libexec}"/utils/printok "${1}"
|
||||
}
|
||||
|
||||
printerr() {
|
||||
"${libexec}"/utils/printerr "$1"
|
||||
"${libexec}"/utils/printerr "${1}"
|
||||
}
|
||||
|
||||
##
|
||||
|
|
|
@ -25,7 +25,7 @@ erase()
|
|||
}
|
||||
|
||||
printerr() {
|
||||
"${libexec}"/utils/printerr "$1"
|
||||
"${libexec}"/utils/printerr "${1}"
|
||||
}
|
||||
|
||||
##
|
||||
|
|
84
libexec/portzap/setup/setup-cron
Normal file
84
libexec/portzap/setup/setup-cron
Normal 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
|
36
libexec/portzap/setup/setup-doas
Normal file
36
libexec/portzap/setup/setup-doas
Normal 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
|
|
@ -10,15 +10,13 @@ commit=$2
|
|||
|
||||
##
|
||||
# functions
|
||||
gitexec()
|
||||
diff()
|
||||
{
|
||||
"${libexec}"/utils/gitexec "${1}"
|
||||
"${libexec}"/utils/gitdiff ${@}
|
||||
}
|
||||
|
||||
##
|
||||
# main
|
||||
cd "${gitdir}"
|
||||
add=$(gitexec "diff --name-only --diff-filter=A ${commit} HEAD")
|
||||
mod=$(gitexec "diff --name-only --diff-filter=M ${commit} HEAD")
|
||||
echo "${add}"
|
||||
echo "${mod}"
|
||||
diff "--name-only" "--diff-filter=A" "${commit}" "HEAD"
|
||||
diff "--name-only" "--diff-filter=M" "${commit}" "HEAD"
|
||||
|
|
|
@ -10,12 +10,12 @@ commit=$2
|
|||
|
||||
##
|
||||
# functions
|
||||
gitexec()
|
||||
diff()
|
||||
{
|
||||
"${libexec}"/utils/gitexec "${1}"
|
||||
"${libexec}"/utils/gitdiff ${@}
|
||||
}
|
||||
|
||||
##
|
||||
# main
|
||||
cd "${gitdir}"
|
||||
gitexec "diff --name-only --diff-filter=D ${commit} HEAD"
|
||||
diff "--name-only" "--diff-filter=D" "${commit}" "HEAD"
|
||||
|
|
11
libexec/portzap/utils/gitdiff
Normal file
11
libexec/portzap/utils/gitdiff
Normal 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 ${@}
|
|
@ -5,16 +5,11 @@
|
|||
.Nm portzap
|
||||
.Nd manages a copy of the HardenedBSD ports tree
|
||||
.Sh SYNOPSIS
|
||||
.br
|
||||
portzap clone
|
||||
.br
|
||||
portzap pull
|
||||
.br
|
||||
portzap checkout
|
||||
.br
|
||||
portzap install
|
||||
.br
|
||||
portzap rm
|
||||
.Nm portzap clone
|
||||
.Nm portzap pull
|
||||
.Nm portzap checkout
|
||||
.Nm portzap install
|
||||
.Nm portzap rm
|
||||
.Sh DESCRIPTION
|
||||
.Nm portzap
|
||||
manages a copy of the HardenedBSD ports tree.
|
||||
|
@ -58,9 +53,9 @@ This command requires root privileges
|
|||
.Sh ENVIRONMENT
|
||||
.sp
|
||||
.sp
|
||||
.Nm PORTZAP_GITURL
|
||||
.Nm PORTZAP_CLONEURL
|
||||
.br
|
||||
The URL to a git repository
|
||||
The URL of a git repository
|
||||
.br
|
||||
Default: https://git.HardenedBSD.org/HardenedBSD/ports.git
|
||||
.sp
|
||||
|
|
|
@ -1 +1 @@
|
|||
v0.11.5
|
||||
v0.12.0
|
||||
|
|
1
share/portzap/crontab
Normal file
1
share/portzap/crontab
Normal file
|
@ -0,0 +1 @@
|
|||
0 0 * * * /usr/local/bin/portzap pull
|
Loading…
Reference in a new issue