Add 'sourcezap set-branch'
The $SOURCEZAP_BRANCH environment variable has been removed. When you want to change branch 'sourcezap set-branch <branch name>' can be used instead.
This commit is contained in:
parent
6c1aebcbde
commit
e1e9ea0cff
5 changed files with 71 additions and 45 deletions
|
@ -27,6 +27,10 @@ the first time:
|
||||||
# This command is delegated to the '_sourcezap' user
|
# This command is delegated to the '_sourcezap' user
|
||||||
$ sourcezap pull
|
$ sourcezap pull
|
||||||
|
|
||||||
|
# Set a branch other than the default: hardened/14-stable/master
|
||||||
|
# This command is delegated to the '_sourcezap' user
|
||||||
|
$ sourcezap set-branch hardened/13-stable/master
|
||||||
|
|
||||||
# Install /home/_sourcezap/src/ into /usr/src/
|
# Install /home/_sourcezap/src/ into /usr/src/
|
||||||
# This command requires root privileges
|
# This command requires root privileges
|
||||||
# sourcezap install
|
# sourcezap install
|
||||||
|
@ -42,10 +46,6 @@ the first time:
|
||||||
The URL to a git repository. <br>
|
The URL to a git repository. <br>
|
||||||
Default: https://git.HardenedBSD.org/HardenedBSD/HardenedBSD.git.
|
Default: https://git.HardenedBSD.org/HardenedBSD/HardenedBSD.git.
|
||||||
|
|
||||||
* __$SOURCEZAP\_BRANCH__ <br>
|
|
||||||
The git branch to clone and pull updates from. <br>
|
|
||||||
Default: hardened/14-stable/master.
|
|
||||||
|
|
||||||
* __$SOURCEZAP\_INSTALLDIR__ <br>
|
* __$SOURCEZAP\_INSTALLDIR__ <br>
|
||||||
The directory where the source tree will be installed. <br>
|
The directory where the source tree will be installed. <br>
|
||||||
Default: /usr/src/.
|
Default: /usr/src/.
|
||||||
|
|
|
@ -4,9 +4,9 @@ set -e
|
||||||
##
|
##
|
||||||
# variables
|
# variables
|
||||||
localbase="${LOCALBASE:-/usr/local}"
|
localbase="${LOCALBASE:-/usr/local}"
|
||||||
|
defaultbranch="hardened/14-stable/master"
|
||||||
gitdir="/home/_sourcezap/src"
|
gitdir="/home/_sourcezap/src"
|
||||||
giturl="${SOURCEZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git}"
|
giturl="${SOURCEZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git}"
|
||||||
branch="${SOURCEZAP_BRANCH:-hardened/14-stable/master}"
|
|
||||||
installdir="${SOURCEZAP_INSTALLDIR:-/usr/src}"
|
installdir="${SOURCEZAP_INSTALLDIR:-/usr/src}"
|
||||||
revision="${installdir}"/.sourcezap
|
revision="${installdir}"/.sourcezap
|
||||||
libexec="${localbase}"/libexec/sourcezap
|
libexec="${localbase}"/libexec/sourcezap
|
||||||
|
@ -40,11 +40,15 @@ done
|
||||||
case $1 in
|
case $1 in
|
||||||
"clone")
|
"clone")
|
||||||
require_dependency "git doas"
|
require_dependency "git doas"
|
||||||
"${libexec}"/sourcezap-clone "${giturl}" "${gitdir}" "${branch}"
|
"${libexec}"/sourcezap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
|
||||||
;;
|
;;
|
||||||
"pull")
|
"pull")
|
||||||
require_dependency "git doas"
|
require_dependency "git doas"
|
||||||
"${libexec}"/sourcezap-pull "${gitdir}" "${branch}"
|
"${libexec}"/sourcezap-pull "${gitdir}"
|
||||||
|
;;
|
||||||
|
"set-branch")
|
||||||
|
require_dependency "git doas"
|
||||||
|
"${libexec}"/sourcezap-setbranch "${gitdir}" "${2}"
|
||||||
;;
|
;;
|
||||||
"erase")
|
"erase")
|
||||||
"${libexec}"/sourcezap-erase "${gitdir}" "${installdir}"
|
"${libexec}"/sourcezap-erase "${gitdir}" "${installdir}"
|
||||||
|
@ -57,9 +61,10 @@ case $1 in
|
||||||
printf "Usage: sourcezap COMMAND [OPTIONS]\n"
|
printf "Usage: sourcezap COMMAND [OPTIONS]\n"
|
||||||
printf "\n"
|
printf "\n"
|
||||||
printf "Commands:\n"
|
printf "Commands:\n"
|
||||||
printf " clone Clone the HardenedBSD source tree\n"
|
printf " clone Clone the HardenedBSD source tree\n"
|
||||||
printf " pull Pull source tree updates\n"
|
printf " pull Pull source tree updates\n"
|
||||||
printf " erase Erase /usr/src/ and /home/_sourcezap/src/\n"
|
printf " set-branch Set a branch other than the default\n"
|
||||||
printf " install Install the source tree into /usr/src/\n"
|
printf " install Install the source tree into /usr/src/\n"
|
||||||
|
printf " erase Erase /usr/src/ and /home/_sourcezap/src/\n"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -6,8 +6,7 @@ set -e
|
||||||
libexec=$(dirname "$0")
|
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,24 +17,6 @@ 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 "[x] 'git checkout' exited with an error"
|
|
||||||
exit "${r}"
|
|
||||||
else
|
|
||||||
echo "[-] Done"
|
|
||||||
fi
|
|
||||||
set -e
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# main
|
# main
|
||||||
if ! "${libexec}"/issourcezap-member; then
|
if ! "${libexec}"/issourcezap-member; then
|
||||||
|
@ -50,11 +31,7 @@ if [ ! -e "${gitdir}/.git" ]; then
|
||||||
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}"
|
||||||
|
|
43
libexec/sourcezap/sourcezap-setbranch
Normal file
43
libexec/sourcezap/sourcezap-setbranch
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#!/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"
|
||||||
|
remote="origin"
|
||||||
|
|
||||||
|
##
|
||||||
|
# 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
|
||||||
|
|
||||||
|
printf "Set new branch: %s\n" "${branch}"
|
||||||
|
set -x
|
||||||
|
cd "${gitdir}"
|
||||||
|
gitexec "fetch origin"
|
||||||
|
gitexec "checkout ${branch}" ||
|
||||||
|
gitexec "checkout -t origin/${branch}"
|
||||||
|
set +x
|
||||||
|
printf "New branch: %s\n" "${branch}"
|
|
@ -10,6 +10,8 @@ sourcezap clone
|
||||||
.br
|
.br
|
||||||
sourcezap pull
|
sourcezap pull
|
||||||
.br
|
.br
|
||||||
|
sourcezap set-branch
|
||||||
|
.br
|
||||||
sourcezap install
|
sourcezap install
|
||||||
.br
|
.br
|
||||||
sourcezap erase
|
sourcezap erase
|
||||||
|
@ -34,6 +36,12 @@ Pull updates into /home/_sourcezap/src/.
|
||||||
.br
|
.br
|
||||||
This command is delegated to the '_sourcezap' user.
|
This command is delegated to the '_sourcezap' user.
|
||||||
.Pp
|
.Pp
|
||||||
|
.Nm sourcezap set-branch
|
||||||
|
.br
|
||||||
|
Set a branch other than the default: hardened/14-stable/master.
|
||||||
|
.br
|
||||||
|
This command is delegated to the '_sourcezap' user.
|
||||||
|
.Pp
|
||||||
.Nm sourcezap install
|
.Nm sourcezap install
|
||||||
.br
|
.br
|
||||||
Install /home/_sourcezap/src/ into /usr/src/.
|
Install /home/_sourcezap/src/ into /usr/src/.
|
||||||
|
@ -55,13 +63,6 @@ The URL to a git repository.
|
||||||
.br
|
.br
|
||||||
Default: https://git.HardenedBSD.org/HardenedBSD/HardenedBSD.git/
|
Default: https://git.HardenedBSD.org/HardenedBSD/HardenedBSD.git/
|
||||||
.sp
|
.sp
|
||||||
.Nm SOURCEZAP_BRANCH
|
|
||||||
.br
|
|
||||||
The git branch to clone and pull updates from.
|
|
||||||
.br
|
|
||||||
Default: hardened/14-stable/master
|
|
||||||
.br
|
|
||||||
.sp
|
|
||||||
.Nm SOURCEZAP_INSTALLDIR
|
.Nm SOURCEZAP_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