Adopt many recent portzap updates

This commit is contained in:
0x1eef 2024-06-01 00:50:47 -03:00
parent 7d90c2ca99
commit 8b63c53aa9
17 changed files with 236 additions and 141 deletions

View file

@ -3,35 +3,44 @@ set -e
##
# variables
localbase="${LOCALBASE:-/usr/local}"
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
libexec="${localbase}"/libexec/sourcezap
conf=$(cat "${localbase}"/share/sourcezap/doas.conf)
doas="${localbase}"/etc/doas.conf
##
# functions
printok()
{
"${libexec}"/utils/printok "${1}"
}
printerr()
{
"${libexec}"/utils/printerr "${1}"
}
##
# main
if [ "$(id -u)" != "0" ]; then
echo "[x] This command must be run by root"
printerr "you must be root"
exit 1
fi
if id -u _sourcezap > /dev/null 2>&1; then
echo "[-] The _sourcezap user exists"
echo "[-] Add user(s) to the _sourcezap group:"
echo "root# pw groupmod -n _sourcezap -m user1,user2"
printok "_sourcezap user exists"
else
pw useradd -n _sourcezap \
-c "sourcezap user" \
-m \
-s /sbin/nologin
chmod u=rwX,g=rX,o= /home/_sourcezap/
echo "[-] The _sourcezap user, group and home directory have been created."
echo "[-] Add user(s) to the _sourcezap group:"
echo "root# pw groupmod -n _sourcezap -m user1,user2"
printok "create _sourcezap user"
fi
if grep -F "^${conf}$" "${doas}" > /dev/null 2>&1; then
echo "[-] No changes made to ${doas}"
printok "${doas} is up to date"
else
echo "$conf" >> "$doas"
echo "[-] ${doas} has been changed. Please review the changes"
printok "update ${doas} (note: review the update)"
fi

View file

@ -3,21 +3,27 @@ set -e
##
# variables
localbase="${LOCALBASE:-/usr/local}"
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
libexec="${localbase}"/libexec/sourcezap
defaultbranch="hardened/14-stable/master"
gitdir="/home/_sourcezap/src"
giturl="${SOURCEZAP_CLONEURL:-https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git}"
installdir="${SOURCEZAP_INSTALLDIR:-/usr/src}"
revision="${installdir}"/.sourcezap
libexec="${localbase}"/libexec/sourcezap
##
# functions
require_dependency() {
printerr()
{
"${libexec}"/utils/printerr "${1}"
}
require_dependency()
{
deps=$1
for dep in $deps; do
if ! which -s "$dep"; then
echo "[x] This command requires ${dep}, but ${dep} wasn't found"
printerr "${dep} wasn't found on \$PATH"
exit 1
fi
done
@ -40,22 +46,22 @@ done
case $1 in
"clone")
require_dependency "git doas"
"${libexec}"/sourcezap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
"${libexec}"/commands/sourcezap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
;;
"pull")
require_dependency "git doas"
"${libexec}"/sourcezap-pull "${gitdir}"
"${libexec}"/commands/sourcezap-pull "${gitdir}"
;;
"checkout")
require_dependency "git doas"
"${libexec}"/sourcezap-checkout "${gitdir}" "${2}"
"${libexec}"/commands/sourcezap-checkout "${gitdir}" "${2}"
;;
"rm")
"${libexec}"/sourcezap-rm "${gitdir}" "${installdir}"
"${libexec}"/commands/sourcezap-rm "${gitdir}" "${installdir}"
;;
"install")
require_dependency "git doas"
"${libexec}"/sourcezap-install "${gitdir}" "${installdir}" "${revision}"
"${libexec}"/commands/sourcezap-install "${gitdir}" "${installdir}" "${revision}"
;;
*)
printf "Usage: sourcezap COMMAND [OPTIONS]\n"

View file

@ -0,0 +1,51 @@
#!/bin/sh
set -e
##
# variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/sourcezap
gitdir=$1
branch=$2
##
# functions
gitexec()
{
"${libexec}"/utils/gitexec "${1}"
}
printok()
{
"${libexec}"/utils/printok "${1}"
}
printerr()
{
"${libexec}"/utils/printerr "${1}"
}
##
# main
if [ "$(id -u)" = "0" ]; then
printerr "you must be a user other than root"
exit 1
fi
if ! "${libexec}"/issourcezap-member; then
printerr "$(id -un) is not a member of _sourcezap"
exit 1
fi
if [ ! -e "${gitdir}/.git" ]; then
printerr "try 'portzap clone' instead"
exit 1
fi
set -x
cd "${gitdir}"
gitexec "fetch origin"
gitexec "checkout ${branch}" ||
gitexec "checkout -t origin/${branch}"
set +x
printok "${branch} checked out"

View file

@ -0,0 +1,52 @@
#!/bin/sh
set -e
##
# variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/sourcezap
giturl=$1
gitdir=$2
branch=$3
##
# functions
gitexec()
{
"${libexec}"/util/gitexec "${1}"
}
printok()
{
"${libexec}"/utils/printerr "${1}"
}
printerr()
{
"${libexec}"/utils/printerr "${1}"
}
##
# main
if [ "$(id -u)" = "0" ]; then
printerr "you must be a user other than root"
exit 1
fi
if ! "${libexec}"/issourcezap-member; then
printerr "$(id -un) is not a member of _sourcezap"
exit 1
fi
if [ -e "${gitdir}/.git" ]; then
printerr "try 'sourcezap pull' instead"
exit 1
fi
set -x
gitexec "clone ${giturl} ${gitdir}"
cd "${gitdir}"
gitexec "config core.filemode off"
gitexec "checkout -t origin/${branch}"
set +x
printok "clone complete"

View file

@ -3,11 +3,12 @@ set -e
##
# variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/sourcezap
mode=u=rwX,g=rX,o=
gitdir=$1
installdir=$2
revfile=$3
libexec=$(dirname "$0")
mode="u=rwX,g=rX,o="
##
# functions
@ -63,10 +64,15 @@ run_install()
install -o root -g _sourcezap -m "${mode}" -v "$@"
}
printerr()
{
"${libexec}"/utils/printerr "${1}"
}
##
# main
if [ "$(id -u)" != "0" ]; then
echo "[x] This command must be run by root"
printerr "you must be root"
exit 1
fi

View file

@ -0,0 +1,49 @@
#!/bin/sh
set -e
##
# variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/sourcezap
gitdir=$1
##
# functions
gitexec()
{
"${libexec}"/utils/gitexec "${1}"
}
printok()
{
"${libexec}"/utils/printok "${1}"
}
printerr()
{
"${libexec}"/utils/printerr "${1}"
}
##
# main
if [ "$(id -u)" = "0" ]; then
printerr "you must be a user other than root"
exit 1
fi
if ! "${libexec}"/issourcezap-member; then
printerr "$(id -un) is not a member of _sourcezap"
exit 1
fi
if [ ! -e "${gitdir}/.git" ]; then
set +x
printerr "try 'sourcezap clone' instead"
exit 1
fi
set -x
cd "${gitdir}"
branch=$(gitexec "branch --show-current")
gitexec "pull --rebase origin ${branch}"
printok "pull complete"

View file

@ -3,6 +3,8 @@ set -e
##
# variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/sourcezap
gitdir=$1
installdir=$2
@ -22,10 +24,15 @@ erase()
echo
}
printerr()
{
"${libexec}"/utils/printerr "${1}"
}
##
# main
if [ "$(id -u)" != "0" ]; then
echo "[x] This command must be run by root"
printerr "you must be root"
exit 1
fi

0
libexec/sourcezap/git-changed-files Normal file → Executable file
View file

0
libexec/sourcezap/git-removed-files Normal file → Executable file
View file

0
libexec/sourcezap/git-rev Normal file → Executable file
View file

0
libexec/sourcezap/issourcezap-member Normal file → Executable file
View file

View file

@ -1,40 +0,0 @@
#!/bin/sh
set -e
##
# variables
libexec=$(dirname "$0")
localbase=${LOCALBASE:-/usr/local}
git="${localbase}"/bin/git
mode="u=rwX,g=rX,o="
gitdir="$1"
branch="$2"
##
# functions
gitexec()
{
doas -n -u _sourcezap \
/bin/sh -c "umask ${mode}; ${git} ${1}"
}
##
# main
if ! "${libexec}"/issourcezap-member; then
echo "[x] This command must be run by a member of the '_sourcezap' group"
exit 1
fi
if [ ! -e "${gitdir}/.git" ]; then
echo "[x] ${gitdir} is not a valid git repository."
echo "[x] Try: sourcezap clone"
exit 1
fi
set -x
cd "${gitdir}"
gitexec "fetch origin"
gitexec "checkout ${branch}" ||
gitexec "checkout -t origin/${branch}"
set +x
printf "current branch: %s\n" "${branch}"

View file

@ -1,41 +0,0 @@
#!/bin/sh
set -e
##
# variables
localbase=${LOCALBASE:-/usr/local}
libexec=$(dirname "$0")
git="${localbase}"/bin/git
giturl=$1
gitdir=$2
branch=$3
mode=u=rwX,g=rX,o=
##
# functions
gitexec()
{
doas -n -u _sourcezap \
/bin/sh -c "umask ${mode}; ${git} ${1}"
}
##
# main
if ! "${libexec}"/issourcezap-member; then
echo "[x] This command must be run by a member of the '_sourcezap' group"
exit 1
fi
if [ -e "${gitdir}/.git" ]; then
echo "[x] ${gitdir} exists."
echo "[x] Try: sourcezap pull"
exit 1
fi
set -x
gitexec "clone ${giturl} ${gitdir}"
cd "${gitdir}"
gitexec "config core.filemode off"
gitexec "checkout -t origin/${branch}"
set +x
echo "[-] Done"

View file

@ -1,37 +0,0 @@
#!/bin/sh
set -e
##
# variables
libexec=$(dirname "$0")
localbase=${LOCALBASE:-/usr/local}
git="${localbase}"/bin/git
gitdir="$1"
mode="u=rwX,g=rX,o="
##
# functions
gitexec()
{
doas -n -u _sourcezap \
/bin/sh -c "umask ${mode}; ${git} ${1}"
}
##
# main
if ! "${libexec}"/issourcezap-member; then
echo "[x] This command must be run by a member of the '_sourcezap' group"
exit 1
fi
if [ ! -e "${gitdir}/.git" ]; then
set +x
echo "[x] ${gitdir} is not a valid git repository."
echo "[x] Try: sourcezap clone"
exit 1
fi
set -x
cd "${gitdir}"
branch=$(gitexec "branch --show-current")
gitexec "pull --rebase origin ${branch}"

13
libexec/sourcezap/utils/gitexec Executable file
View file

@ -0,0 +1,13 @@
#!/bin/sh
set -e
##
# variables
git=$(which git)
mode=u=rwX,g=rX,o=
##
# main
doas -n \
-u _sourcezap \
/bin/sh -c "umask ${mode}; ${git} ${1}"

View file

@ -0,0 +1,10 @@
#!/bin/sh
set -e
##
# variables
err="${1}"
##
# main
printf "error: %s\n" "${err}" > /dev/stderr

10
libexec/sourcezap/utils/printok Executable file
View file

@ -0,0 +1,10 @@
#!/bin/sh
set -e
##
# variables
msg="${1}"
##
# main
printf "ok: %s\n" "${msg}" > /dev/stdout