From a6c98489a7c82d677a90439ce8d3e69de57272cc Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Wed, 17 Apr 2024 16:37:16 -0300 Subject: [PATCH] Add $PORTZAP_BRANCH --- README.md | 4 ++++ bin/portzap | 5 +++-- libexec/portzap/portzap-clone | 7 ++++++- libexec/portzap/portzap-pull | 3 ++- man/man8/portzap.8 | 8 ++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f7c0890..827a7d8 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ portzap is a utility that manages a local copy of the The URL to a git repository.
Default: https://git.hardenedbsd.org/hardenedbsd/ports.git. +* __$PORTZAP\_BRANCH__
+ The git branch to clone and pull updates from.
+ Default: hardenedbsd/main. + * __$PORTZAP\_INSTALLDIR__
The directory where the ports collection will be installed.
Default: /usr/ports/. diff --git a/bin/portzap b/bin/portzap index 547cac8..0918a13 100755 --- a/bin/portzap +++ b/bin/portzap @@ -5,6 +5,7 @@ rootdir=$(dirname "$0") gitdir="/home/_portzap/ports" giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}" +branch="${PORTZAP_BRANCH:-hardenedbsd/main}" installdir="${PORTZAP_INSTALLDIR:-/usr/ports}" revision="${installdir}/.portzap" libexec=$(realpath "${rootdir}/../libexec/portzap") @@ -43,12 +44,12 @@ case $1 in "clone") require_dependency "git doas" require_membership_of _portzap - doas -u _portzap "${libexec}"/portzap-clone "${giturl}" "${gitdir}" + doas -u _portzap "${libexec}"/portzap-clone "${giturl}" "${gitdir}" "${branch}" ;; "pull") require_dependency "git doas" require_membership_of _portzap - doas -u _portzap "${libexec}"/portzap-pull "${gitdir}" + doas -u _portzap "${libexec}"/portzap-pull "${gitdir}" "${branch}" ;; "install") require_root diff --git a/libexec/portzap/portzap-clone b/libexec/portzap/portzap-clone index 7e7c32c..f7c46c5 100755 --- a/libexec/portzap/portzap-clone +++ b/libexec/portzap/portzap-clone @@ -4,6 +4,7 @@ # variables giturl=$1 gitdir=$2 +branch=$3 ## # main @@ -12,7 +13,11 @@ if [ -e "${gitdir}/.git" ]; then echo "[-] Try 'portzap pull'" exit 1 fi -umask u=rwX,g=rwX,o= set -x +umask u=rwX,g=rwX,o= git clone "${giturl}" "${gitdir}" cd "${gitdir}" +set +x +e +echo "[-] Checkout ${branch}" +git checkout -t origin/"${branch}" > /dev/null 2>&1; +echo "[-] Done" diff --git a/libexec/portzap/portzap-pull b/libexec/portzap/portzap-pull index 69355dc..21350cc 100755 --- a/libexec/portzap/portzap-pull +++ b/libexec/portzap/portzap-pull @@ -3,6 +3,7 @@ ## # variables gitdir=$1 +branch=$2 ## # main @@ -10,7 +11,7 @@ umask u=rwX,g=rwX,o= if [ -e "${gitdir}/.git" ]; then set -x cd "${gitdir}" - git pull --rebase origin hardenedbsd/main + git pull --rebase origin "${branch}" else echo "[-] ${gitdir} is not a valid git repository." echo "[-] Try 'portzap clone'" diff --git a/man/man8/portzap.8 b/man/man8/portzap.8 index 6d5c8ff..289a528 100644 --- a/man/man8/portzap.8 +++ b/man/man8/portzap.8 @@ -51,11 +51,19 @@ The URL to a git repository. .br Default: https://git.hardenedbsd.org/hardenedbsd/ports.git .sp +.Nm PORTZAP_BRANCH +.br +The git branch to clone and pull updates from. +.br +Default: hardenedbsd/main +.br +.sp .Nm PORTZAP_INSTALLDIR .br The directory where the ports collection will be installed. .br Default: /usr/ports/ +.sp .Sh AUTHORS The .Nm portzap