Add 'portzap checkout'
A copy of the same sourcezap command ('sourcezap checkout')
This commit is contained in:
parent
8625d945b9
commit
dbd97d9562
5 changed files with 79 additions and 56 deletions
25
README.md
25
README.md
|
@ -13,8 +13,8 @@ can be installed into `/usr/ports/` by root.
|
||||||
This command should be run after installing portzap for
|
This command should be run after installing portzap for
|
||||||
the first time:
|
the first time:
|
||||||
|
|
||||||
# Add the portzap user, group and home directory.
|
# Add the portzap user, group and home directory
|
||||||
# This command requires root privileges.
|
# This command requires root privileges
|
||||||
# setup-portzap
|
# setup-portzap
|
||||||
|
|
||||||
### CLI: portzap
|
### CLI: portzap
|
||||||
|
@ -27,6 +27,10 @@ the first time:
|
||||||
# This command is delegated to the '_portzap' user
|
# This command is delegated to the '_portzap' user
|
||||||
$ portzap pull
|
$ portzap pull
|
||||||
|
|
||||||
|
# Checkout a branch other than the default: hardenedbsd/main
|
||||||
|
# This command is delegated to the '_portzap' user
|
||||||
|
$ portzap checkout
|
||||||
|
|
||||||
# Install /home/_portzap/ports/ into /usr/ports/
|
# Install /home/_portzap/ports/ into /usr/ports/
|
||||||
# This command requires root privileges
|
# This command requires root privileges
|
||||||
# portzap install
|
# portzap install
|
||||||
|
@ -35,20 +39,15 @@ the first time:
|
||||||
# This command requires root privileges
|
# This command requires root privileges
|
||||||
$ portzap rm
|
$ portzap rm
|
||||||
|
|
||||||
|
|
||||||
### ENVIRONMENT
|
### ENVIRONMENT
|
||||||
|
|
||||||
* __$PORTZAP\_GITURL__ <br>
|
* __$PORTZAP\_GITURL__ <br>
|
||||||
The URL to a git repository. <br>
|
The URL to a git repository <br>
|
||||||
Default: https://git.HardenedBSD.org/HardenedBSD/ports.git.
|
Default: https://git.HardenedBSD.org/HardenedBSD/ports.git
|
||||||
|
|
||||||
* __$PORTZAP\_BRANCH__ <br>
|
|
||||||
The git branch to clone and pull updates from. <br>
|
|
||||||
Default: hardenedbsd/main.
|
|
||||||
|
|
||||||
* __$PORTZAP\_INSTALLDIR__ <br>
|
* __$PORTZAP\_INSTALLDIR__ <br>
|
||||||
The directory where the ports collection will be installed. <br>
|
The directory where the ports collection will be installed <br>
|
||||||
Default: /usr/ports/.
|
Default: /usr/ports/
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
@ -82,5 +81,5 @@ via git:
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[BSD Zero Clause](https://choosealicense.com/licenses/0bsd/). <br>
|
[BSD Zero Clause](https://choosealicense.com/licenses/0bsd/) <br>
|
||||||
See [LICENSE](./LICENSE).
|
See [LICENSE](./LICENSE)
|
||||||
|
|
11
bin/portzap
11
bin/portzap
|
@ -4,9 +4,9 @@ set -e
|
||||||
##
|
##
|
||||||
# variables
|
# variables
|
||||||
localbase="${LOCALBASE:-/usr/local}"
|
localbase="${LOCALBASE:-/usr/local}"
|
||||||
|
defaultbranch="hardenedbsd/main"
|
||||||
gitdir="/home/_portzap/ports"
|
gitdir="/home/_portzap/ports"
|
||||||
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
|
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
|
||||||
branch="${PORTZAP_BRANCH:-hardenedbsd/main}"
|
|
||||||
installdir="${PORTZAP_INSTALLDIR:-/usr/ports}"
|
installdir="${PORTZAP_INSTALLDIR:-/usr/ports}"
|
||||||
revision="${installdir}"/.portzap
|
revision="${installdir}"/.portzap
|
||||||
libexec="${localbase}"/libexec/portzap
|
libexec="${localbase}"/libexec/portzap
|
||||||
|
@ -40,11 +40,15 @@ done
|
||||||
case $1 in
|
case $1 in
|
||||||
"clone")
|
"clone")
|
||||||
require_dependency "git doas"
|
require_dependency "git doas"
|
||||||
"${libexec}"/portzap-clone "${giturl}" "${gitdir}" "${branch}"
|
"${libexec}"/portzap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
|
||||||
;;
|
;;
|
||||||
"pull")
|
"pull")
|
||||||
require_dependency "git doas"
|
require_dependency "git doas"
|
||||||
"${libexec}"/portzap-pull "${gitdir}" "${branch}"
|
"${libexec}"/portzap-pull "${gitdir}"
|
||||||
|
;;
|
||||||
|
"checkout")
|
||||||
|
require_dependency "git doas"
|
||||||
|
"${libexec}"/portzap-checkout "${gitdir}" "${2}"
|
||||||
;;
|
;;
|
||||||
"rm")
|
"rm")
|
||||||
"${libexec}"/portzap-rm "${gitdir}" "${installdir}"
|
"${libexec}"/portzap-rm "${gitdir}" "${installdir}"
|
||||||
|
@ -59,6 +63,7 @@ case $1 in
|
||||||
printf "Commands:\n"
|
printf "Commands:\n"
|
||||||
printf " clone Clone the hardenedbsd ports tree\n"
|
printf " clone Clone the hardenedbsd ports tree\n"
|
||||||
printf " pull Pull updates from the hardenedbsd ports tree\n"
|
printf " pull Pull updates from the hardenedbsd ports tree\n"
|
||||||
|
printf " checkout Checkout a branch other than the default\n"
|
||||||
printf " rm Remove /usr/ports/ and /home/_portzap/ports/\n"
|
printf " rm Remove /usr/ports/ and /home/_portzap/ports/\n"
|
||||||
printf " install Install the ports tree into /usr/ports/\n"
|
printf " install Install the ports tree into /usr/ports/\n"
|
||||||
;;
|
;;
|
||||||
|
|
40
libexec/portzap/portzap-checkout
Normal file
40
libexec/portzap/portzap-checkout
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#!/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 _portzap \
|
||||||
|
/bin/sh -c "umask ${mode}; ${git} ${1}"
|
||||||
|
}
|
||||||
|
|
||||||
|
##
|
||||||
|
# main
|
||||||
|
if ! "${libexec}"/isportzap-member; then
|
||||||
|
echo "[x] This command must be run by a member of the '_portzap' group"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -e "${gitdir}/.git" ]; then
|
||||||
|
echo "[x] ${gitdir} is not a valid git repository."
|
||||||
|
echo "[x] Try: portzap 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}"
|
|
@ -7,7 +7,6 @@ libexec=$(dirname "$0")
|
||||||
localbase=${LOCALBASE:-/usr/local}
|
localbase=${LOCALBASE:-/usr/local}
|
||||||
git="${localbase}"/bin/git
|
git="${localbase}"/bin/git
|
||||||
gitdir=$1
|
gitdir=$1
|
||||||
branch=$2
|
|
||||||
mode="u=rwX,g=rX,o="
|
mode="u=rwX,g=rX,o="
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -18,43 +17,21 @@ gitexec()
|
||||||
/bin/sh -c "umask ${mode}; ${git} ${1}"
|
/bin/sh -c "umask ${mode}; ${git} ${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
change_branch()
|
|
||||||
{
|
|
||||||
set +e
|
|
||||||
remote=$1
|
|
||||||
branch=$2
|
|
||||||
echo "[-] Attempt to change branch: ${branch}"
|
|
||||||
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}"
|
|
||||||
else
|
|
||||||
echo "[-] Done"
|
|
||||||
fi
|
|
||||||
set -e
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# main
|
# main
|
||||||
if ! "${libexec}"/isportzap-member; then
|
if ! "${libexec}"/isportzap-member; then
|
||||||
echo "[-] This command must be run by a member of the '_portzap' group"
|
echo "[x] This command must be run by a member of the '_portzap' group"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -e "${gitdir}/.git" ]; then
|
if [ ! -e "${gitdir}/.git" ]; then
|
||||||
set +x
|
set +x
|
||||||
echo "[-] ${gitdir} is not a valid git repository."
|
echo "[x] ${gitdir} is not a valid git repository."
|
||||||
echo "[-] Try 'portzap clone'"
|
echo "[x] Try 'portzap clone'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "${gitdir}"
|
|
||||||
remote=$(gitexec "remote" | head -n1)
|
|
||||||
cbranch=$(gitexec "branch --show-current")
|
|
||||||
if [ "${cbranch}" != "${branch}" ]; then
|
|
||||||
change_branch "${remote}" "${branch}"
|
|
||||||
fi
|
|
||||||
set -x
|
set -x
|
||||||
gitexec "pull --rebase ${remote} ${branch}"
|
cd "${gitdir}"
|
||||||
|
branch=$(gitexec "branch --show-current")
|
||||||
|
gitexec "pull --rebase origin ${branch}"
|
||||||
|
|
|
@ -10,6 +10,8 @@ portzap clone
|
||||||
.br
|
.br
|
||||||
portzap pull
|
portzap pull
|
||||||
.br
|
.br
|
||||||
|
portzap checkout
|
||||||
|
.br
|
||||||
portzap install
|
portzap install
|
||||||
.br
|
.br
|
||||||
portzap rm
|
portzap rm
|
||||||
|
@ -33,6 +35,13 @@ This command is delegated to the '_portzap' user
|
||||||
Pull updates into /home/_portzap/ports/
|
Pull updates into /home/_portzap/ports/
|
||||||
.br
|
.br
|
||||||
This command is delegated to the '_portzap' user
|
This command is delegated to the '_portzap' user
|
||||||
|
.br
|
||||||
|
.Pp
|
||||||
|
.Nm portzap checkout
|
||||||
|
.br
|
||||||
|
Checkout a branch other than the default: hardenedbsd/main
|
||||||
|
.br
|
||||||
|
This command is delegated to the '_portzap' user
|
||||||
.Pp
|
.Pp
|
||||||
.Nm portzap install
|
.Nm portzap install
|
||||||
.br
|
.br
|
||||||
|
@ -55,13 +64,6 @@ The URL to a git repository
|
||||||
.br
|
.br
|
||||||
Default: https://git.HardenedBSD.org/HardenedBSD/ports.git
|
Default: https://git.HardenedBSD.org/HardenedBSD/ports.git
|
||||||
.sp
|
.sp
|
||||||
.Nm PORTZAP_BRANCH
|
|
||||||
.br
|
|
||||||
The git branch to clone and pull updates from
|
|
||||||
.br
|
|
||||||
Default: hardenedbsd/main
|
|
||||||
.br
|
|
||||||
.sp
|
|
||||||
.Nm PORTZAP_INSTALLDIR
|
.Nm PORTZAP_INSTALLDIR
|
||||||
.br
|
.br
|
||||||
The directory where the ports collection will be installed
|
The directory where the ports collection will be installed
|
||||||
|
|
Loading…
Reference in a new issue