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

View file

@ -3,21 +3,27 @@ set -e
## ##
# variables # variables
localbase="${LOCALBASE:-/usr/local}" localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
libexec="${localbase}"/libexec/sourcezap
defaultbranch="hardened/14-stable/master" defaultbranch="hardened/14-stable/master"
gitdir="/home/_sourcezap/src" gitdir="/home/_sourcezap/src"
giturl="${SOURCEZAP_CLONEURL:-https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git}" giturl="${SOURCEZAP_CLONEURL:-https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git}"
installdir="${SOURCEZAP_INSTALLDIR:-/usr/src}" installdir="${SOURCEZAP_INSTALLDIR:-/usr/src}"
revision="${installdir}"/.sourcezap revision="${installdir}"/.sourcezap
libexec="${localbase}"/libexec/sourcezap
## ##
# functions # functions
require_dependency() { printerr()
{
"${libexec}"/utils/printerr "${1}"
}
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
echo "[x] This command requires ${dep}, but ${dep} wasn't found" printerr "${dep} wasn't found on \$PATH"
exit 1 exit 1
fi fi
done done
@ -40,22 +46,22 @@ done
case $1 in case $1 in
"clone") "clone")
require_dependency "git doas" require_dependency "git doas"
"${libexec}"/sourcezap-clone "${giturl}" "${gitdir}" "${defaultbranch}" "${libexec}"/commands/sourcezap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
;; ;;
"pull") "pull")
require_dependency "git doas" require_dependency "git doas"
"${libexec}"/sourcezap-pull "${gitdir}" "${libexec}"/commands/sourcezap-pull "${gitdir}"
;; ;;
"checkout") "checkout")
require_dependency "git doas" require_dependency "git doas"
"${libexec}"/sourcezap-checkout "${gitdir}" "${2}" "${libexec}"/commands/sourcezap-checkout "${gitdir}" "${2}"
;; ;;
"rm") "rm")
"${libexec}"/sourcezap-rm "${gitdir}" "${installdir}" "${libexec}"/commands/sourcezap-rm "${gitdir}" "${installdir}"
;; ;;
"install") "install")
require_dependency "git doas" require_dependency "git doas"
"${libexec}"/sourcezap-install "${gitdir}" "${installdir}" "${revision}" "${libexec}"/commands/sourcezap-install "${gitdir}" "${installdir}" "${revision}"
;; ;;
*) *)
printf "Usage: sourcezap COMMAND [OPTIONS]\n" 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 # variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/sourcezap
mode=u=rwX,g=rX,o=
gitdir=$1 gitdir=$1
installdir=$2 installdir=$2
revfile=$3 revfile=$3
libexec=$(dirname "$0")
mode="u=rwX,g=rX,o="
## ##
# functions # functions
@ -63,10 +64,15 @@ run_install()
install -o root -g _sourcezap -m "${mode}" -v "$@" install -o root -g _sourcezap -m "${mode}" -v "$@"
} }
printerr()
{
"${libexec}"/utils/printerr "${1}"
}
## ##
# main # main
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
echo "[x] This command must be run by root" printerr "you must be root"
exit 1 exit 1
fi 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 # variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/sourcezap
gitdir=$1 gitdir=$1
installdir=$2 installdir=$2
@ -22,10 +24,15 @@ erase()
echo echo
} }
printerr()
{
"${libexec}"/utils/printerr "${1}"
}
## ##
# main # main
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
echo "[x] This command must be run by root" printerr "you must be root"
exit 1 exit 1
fi 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