diff --git a/README.md b/README.md
index 4980a9a..2cb06a1 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,10 @@ the first time:
# This command is delegated to the '_sourcezap' user
$ 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/
# This command requires root privileges
# sourcezap install
@@ -42,10 +46,6 @@ the first time:
The URL to a git repository.
Default: https://git.HardenedBSD.org/HardenedBSD/HardenedBSD.git.
-* __$SOURCEZAP\_BRANCH__
- The git branch to clone and pull updates from.
- Default: hardened/14-stable/master.
-
* __$SOURCEZAP\_INSTALLDIR__
The directory where the source tree will be installed.
Default: /usr/src/.
diff --git a/bin/sourcezap b/bin/sourcezap
index b457e6c..88389bb 100755
--- a/bin/sourcezap
+++ b/bin/sourcezap
@@ -4,9 +4,9 @@ set -e
##
# variables
localbase="${LOCALBASE:-/usr/local}"
+defaultbranch="hardened/14-stable/master"
gitdir="/home/_sourcezap/src"
giturl="${SOURCEZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git}"
-branch="${SOURCEZAP_BRANCH:-hardened/14-stable/master}"
installdir="${SOURCEZAP_INSTALLDIR:-/usr/src}"
revision="${installdir}"/.sourcezap
libexec="${localbase}"/libexec/sourcezap
@@ -40,11 +40,15 @@ done
case $1 in
"clone")
require_dependency "git doas"
- "${libexec}"/sourcezap-clone "${giturl}" "${gitdir}" "${branch}"
+ "${libexec}"/sourcezap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
;;
"pull")
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")
"${libexec}"/sourcezap-erase "${gitdir}" "${installdir}"
@@ -57,9 +61,10 @@ case $1 in
printf "Usage: sourcezap COMMAND [OPTIONS]\n"
printf "\n"
printf "Commands:\n"
- printf " clone Clone the HardenedBSD source tree\n"
- printf " pull Pull source tree updates\n"
- printf " erase Erase /usr/src/ and /home/_sourcezap/src/\n"
- printf " install Install the source tree into /usr/src/\n"
+ printf " clone Clone the HardenedBSD source tree\n"
+ printf " pull Pull source tree updates\n"
+ printf " set-branch Set a branch other than the default\n"
+ printf " install Install the source tree into /usr/src/\n"
+ printf " erase Erase /usr/src/ and /home/_sourcezap/src/\n"
;;
esac
diff --git a/libexec/sourcezap/sourcezap-pull b/libexec/sourcezap/sourcezap-pull
index 86aa7ee..0fc7f6d 100755
--- a/libexec/sourcezap/sourcezap-pull
+++ b/libexec/sourcezap/sourcezap-pull
@@ -6,8 +6,7 @@ set -e
libexec=$(dirname "$0")
localbase=${LOCALBASE:-/usr/local}
git="${localbase}"/bin/git
-gitdir=$1
-branch=$2
+gitdir="$1"
mode="u=rwX,g=rX,o="
##
@@ -18,24 +17,6 @@ gitexec()
/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
if ! "${libexec}"/issourcezap-member; then
@@ -50,11 +31,7 @@ if [ ! -e "${gitdir}/.git" ]; then
exit 1
fi
-cd "${gitdir}"
-remote=$(gitexec "remote" | head -n1)
-cbranch=$(gitexec "branch --show-current")
-if [ "${cbranch}" != "${branch}" ]; then
- change_branch "${remote}" "${branch}"
-fi
set -x
-gitexec "pull --rebase ${remote} ${branch}"
+cd "${gitdir}"
+branch=$(gitexec "branch --show-current")
+gitexec "pull --rebase origin ${branch}"
diff --git a/libexec/sourcezap/sourcezap-setbranch b/libexec/sourcezap/sourcezap-setbranch
new file mode 100644
index 0000000..15addb8
--- /dev/null
+++ b/libexec/sourcezap/sourcezap-setbranch
@@ -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}"
diff --git a/man/man8/sourcezap.8 b/man/man8/sourcezap.8
index 4a1e758..fcbac1b 100644
--- a/man/man8/sourcezap.8
+++ b/man/man8/sourcezap.8
@@ -10,6 +10,8 @@ sourcezap clone
.br
sourcezap pull
.br
+sourcezap set-branch
+.br
sourcezap install
.br
sourcezap erase
@@ -34,6 +36,12 @@ Pull updates into /home/_sourcezap/src/.
.br
This command is delegated to the '_sourcezap' user.
.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
.br
Install /home/_sourcezap/src/ into /usr/src/.
@@ -55,13 +63,6 @@ The URL to a git repository.
.br
Default: https://git.HardenedBSD.org/HardenedBSD/HardenedBSD.git/
.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
.br
The directory where the ports collection will be installed.