Honor umask

This change is a revert of previous commits that worked around
the umask not being honored. This commit runs git with the correct
umask, and avoids any need to run chmod manually. The number of
doas.conf rules has been reduced to 2.
This commit is contained in:
0x1eef 2024-04-20 05:21:19 -03:00
parent 6250b5f995
commit bd84f7f134
6 changed files with 55 additions and 31 deletions

View file

@ -7,10 +7,18 @@ git="${localbase}"/bin/git
gitdir=$1
commit=$2
##
# functions
gitexec()
{
doas -n -u _portzap \
/bin/sh -c "umask ${mode}; ${git} ${1}"
}
##
# main
cd "${gitdir}"
add=$(doas -u _portzap "${git}" diff --name-only --diff-filter=A "${commit}" HEAD)
mod=$(doas -u _portzap "${git}" diff --name-only --diff-filter=M "${commit}" HEAD)
add=$(gitexec "diff --name-only --diff-filter=A ${commit} HEAD")
mod=$(gitexec "diff --name-only --diff-filter=M ${commit} HEAD")
echo "${add}"
echo "${mod}"

View file

@ -7,7 +7,15 @@ git="${localbase}"/bin/git
gitdir=$1
commit=$2
##
# functions
gitexec()
{
doas -n -u _portzap \
/bin/sh -c "umask ${mode}; ${git} ${1}"
}
##
# main
cd "${gitdir}"
doas -u _portzap "${git}" diff --name-only --diff-filter=D "${commit}" HEAD
gitexec "diff --name-only --diff-filter=D ${commit} HEAD"

View file

@ -5,7 +5,15 @@
git=/usr/local/bin/git
gitdir=$1
##
# functions
gitexec()
{
doas -n -u _portzap \
/bin/sh -c "umask ${mode}; ${git} ${1}"
}
##
# main
cd "${gitdir}"
doas -u _portzap "${git}" rev-parse HEAD
gitexec "rev-parse HEAD"

View file

@ -8,7 +8,15 @@ git="${localbase}"/bin/git
giturl=$1
gitdir=$2
branch=$3
mode="u=rwX,g=rX,o="
mode=u=rwX,g=rX,o=
##
# functions
gitexec()
{
doas -n -u _portzap \
/bin/sh -c "umask ${mode}; ${git} ${1}"
}
##
# main
@ -24,16 +32,10 @@ if [ -e "${gitdir}/.git" ]; then
fi
set -x
umask ${mode}
doas -u _portzap "${git}" clone "${giturl}" "${gitdir}"
gitexec "clone ${giturl} ${gitdir}"
cd "${gitdir}"
gitexec "config core.filemode off"
set +x
echo "[-] Adjust filemode. This might take a while"
doas -u _portzap "${git}" config core.filemode off
doas -u root /bin/chmod -R ${mode} "${gitdir}"
echo "[-] git checkout ${branch}"
doas -u _portzap "${git}" \
checkout -t \
origin/"${branch}" \
> /dev/null 2>&1
gitexec "checkout -t origin/${branch} > /dev/null 2>&1"
echo "[-] Done"

View file

@ -12,15 +12,21 @@ owner="_portzap:_portzap"
##
# functions
gitexec()
{
doas -n -u _portzap \
/bin/sh -c "umask ${mode}; ${git} ${1}"
}
change_branch()
{
set +e
remote=$1
branch=$2
echo "[-] Attempt to change branch: ${branch}"
doas -u _portzap "${git}" fetch "${remote}" > /dev/null 2>&1
if ! doas -u _portzap "${git}" checkout "${branch}" > /dev/null 2>&1 ||
doas -u _portzap "${git}" checkout -t "${remote}"/"${branch}" > /dev/null 2>&1; then
gitexec "fetch ${remote} > /dev/null 2>&1"
if ! gitexec "checkout ${branch} > /dev/null 2>&1" ||
gitexec "checkout -t ${remote}/${branch} > /dev/null 2>&1"; then
r="${?}"
echo "[-] 'git checkout' exited with an error"
exit "${r}"
@ -45,15 +51,10 @@ if [ ! -e "${gitdir}/.git" ]; then
fi
umask ${mode}
doas -u root /bin/chmod -R "${mode}" "${gitdir}/.git"
doas -u root /usr/sbin/chown -R "${owner}" "${gitdir}/.git"
cd "${gitdir}"
remote=$("${git}" remote | head -n1)
if [ "$(git branch --show-current)" != "${branch}" ]; then
remote=$(gitexec "remote" | head -n1)
cbranch=$(gitexec "branch --show-current")
if [ "${cbranch}" != "${branch}" ]; then
change_branch "${remote}" "${branch}"
fi
set -x
doas -u _portzap "${git}" pull --rebase "${remote}" "${branch}"
set +x
echo "[-] Adjust filemode. This might take a while"
doas -u root /bin/chmod -R "${mode}" "${gitdir}"
gitexec "pull --rebase ${remote} ${branch}"

View file

@ -1,7 +1,4 @@
##
# portzap
permit nopass root as _portzap cmd /usr/local/bin/git
permit nopass :_portzap as _portzap cmd /usr/local/bin/git
permit nopass :_portzap as root cmd /bin/chmod args -R u=rwX,g=rX,o= /home/_portzap/ports
permit nopass :_portzap as root cmd /bin/chmod args -R u=rwX,g=rX,o= /home/_portzap/ports/.git
permit nopass :_portzap as root cmd /usr/sbin/chown args -R _portzap:_portzap /home/_portzap/ports/.git
permit nopass root as _portzap cmd /bin/sh
permit nopass :_portzap as _portzap cmd /bin/sh