diff --git a/bin/sourcezap b/bin/sourcezap index eee33e8..592fc79 100755 --- a/bin/sourcezap +++ b/bin/sourcezap @@ -5,8 +5,8 @@ set -e # variables localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)} libexec="${localbase}"/libexec/sourcezap -gitdir="/home/_sourcezap/src" -giturl="${SOURCEZAP_CLONEURL:-https://git.hardenedbsd.org/hardenedbsd/hardenedbsd.git}" +repodir="/home/_sourcezap/src" +repourl="${SOURCEZAP_CLONEURL:-https://git.hardenedbsd.org/hardenedbsd/hardenedbsd.git}" installdir="${SOURCEZAP_INSTALLDIR:-/usr/src}" defaultbranch="hardenedbsd/main" revfile="${installdir}"/.sourcezap @@ -52,26 +52,26 @@ case $1 in ;; "clone") require_dependency git doas - "${libexec}"/commands/sourcezap-clone "${giturl}" "${gitdir}" "${defaultbranch}" + "${libexec}"/commands/sourcezap-clone "${repourl}" "${repodir}" "${defaultbranch}" ;; "pull") require_dependency git doas - "${libexec}"/commands/sourcezap-pull "${gitdir}" + "${libexec}"/commands/sourcezap-pull "${repodir}" ;; "checkout") require_dependency git doas - "${libexec}"/commands/sourcezap-checkout "${gitdir}" "${2}" + "${libexec}"/commands/sourcezap-checkout "${repodir}" "${2}" ;; "sh") require_dependency doas - "${libexec}"/commands/sourcezap-sh "${gitdir}" + "${libexec}"/commands/sourcezap-sh "${repodir}" ;; "rm") - "${libexec}"/commands/sourcezap-rm "${gitdir}" "${installdir}" + "${libexec}"/commands/sourcezap-rm "${repodir}" "${installdir}" ;; "install") require_dependency git doas - "${libexec}"/commands/sourcezap-install "${gitdir}" "${installdir}" "${revfile}" + "${libexec}"/commands/sourcezap-install "${repodir}" "${installdir}" "${revfile}" ;; *) printf "Usage: sourcezap COMMAND [OPTIONS]\n" diff --git a/libexec/sourcezap/commands/sourcezap-checkout b/libexec/sourcezap/commands/sourcezap-checkout index 657b365..893a477 100755 --- a/libexec/sourcezap/commands/sourcezap-checkout +++ b/libexec/sourcezap/commands/sourcezap-checkout @@ -6,7 +6,7 @@ set -e localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} libexec="${localbase}"/libexec/sourcezap git="${libexec}"/utils/git/run -gitdir=$1 +repodir=$1 branch=$2 ## @@ -26,12 +26,12 @@ if ! "${libexec}"/utils/issourcezap-member; then exit 1 fi -if [ ! -e "${gitdir}/.git" ]; then +if [ ! -e "${repodir}/.git" ]; then printerr "try 'sourcezap clone' instead" exit 1 fi -cd "${gitdir}" +cd "${repodir}" "${git}" fetch origin "${git}" checkout "${branch}" || "${git}" checkout -t origin/"${branch}" diff --git a/libexec/sourcezap/commands/sourcezap-clone b/libexec/sourcezap/commands/sourcezap-clone index 04bf36b..34b3b0a 100755 --- a/libexec/sourcezap/commands/sourcezap-clone +++ b/libexec/sourcezap/commands/sourcezap-clone @@ -6,8 +6,8 @@ set -e localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} libexec="${localbase}"/libexec/sourcezap git="${libexec}"/utils/git/run -giturl=$1 -gitdir=$2 +repourl=$1 +repodir=$2 branch=$3 ## @@ -27,13 +27,13 @@ if ! "${libexec}"/utils/issourcezap-member; then exit 1 fi -if [ -e "${gitdir}/.git" ]; then +if [ -e "${repodir}/.git" ]; then printerr "try 'sourcezap pull' instead" exit 1 fi -"${git}" clone "${giturl}" "${gitdir}" -cd "${gitdir}" +"${git}" clone "${repourl}" "${repodir}" +cd "${repodir}" "${git}" config core.filemode off "${git}" checkout -t origin/"${branch}" > /dev/null 2>&1 || true printok "clone complete" diff --git a/libexec/sourcezap/commands/sourcezap-install b/libexec/sourcezap/commands/sourcezap-install index 431cdc9..d002b9b 100755 --- a/libexec/sourcezap/commands/sourcezap-install +++ b/libexec/sourcezap/commands/sourcezap-install @@ -7,7 +7,7 @@ localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} libexec="${localbase}"/libexec/sourcezap git="${libexec}"/utils/git/run mask=$("${libexec}"/utils/get-umask) -gitdir=$1 +repodir=$1 installdir=$2 revfile=$3 @@ -23,14 +23,14 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi -cd "${gitdir}" +cd "${repodir}" if [ -e "${revfile}" ]; then ## # install update rev=$(cat "${revfile}") "${libexec}"/utils/install/run -d "${installdir}" - "${libexec}"/utils/install/update-deleted-files "${gitdir}" "${installdir}" "${rev}" - "${libexec}"/utils/install/update-changed-files "${gitdir}" "${installdir}" "${rev}" + "${libexec}"/utils/install/update-deleted-files "${repodir}" "${installdir}" "${rev}" + "${libexec}"/utils/install/update-changed-files "${repodir}" "${installdir}" "${rev}" else ## # install from scratch diff --git a/libexec/sourcezap/commands/sourcezap-pull b/libexec/sourcezap/commands/sourcezap-pull index c971dd3..e0ff64c 100755 --- a/libexec/sourcezap/commands/sourcezap-pull +++ b/libexec/sourcezap/commands/sourcezap-pull @@ -6,7 +6,7 @@ set -e localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} libexec="${localbase}"/libexec/sourcezap git="${libexec}"/utils/git/run -gitdir=$1 +repodir=$1 ## # functions @@ -25,12 +25,12 @@ if ! "${libexec}"/utils/issourcezap-member; then exit 1 fi -if [ ! -e "${gitdir}/.git" ]; then +if [ ! -e "${repodir}/.git" ]; then printerr "try 'sourcezap clone' instead" exit 1 fi -cd "${gitdir}" +cd "${repodir}" branch=$("${git}" branch --show-current) "${git}" pull --rebase origin "${branch}" printok "pull complete" diff --git a/libexec/sourcezap/commands/sourcezap-rm b/libexec/sourcezap/commands/sourcezap-rm index 21f1e31..26ce9b7 100755 --- a/libexec/sourcezap/commands/sourcezap-rm +++ b/libexec/sourcezap/commands/sourcezap-rm @@ -5,7 +5,7 @@ set -e # variables localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} libexec="${localbase}"/libexec/sourcezap -gitdir=$1 +repodir=$1 installdir=$2 ## @@ -36,19 +36,19 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi -printf "1 Remove the contents of %s\n" "${gitdir}" +printf "1 Remove the contents of %s\n" "${repodir}" printf "2 Remove the contents of %s\n" "${installdir}" -printf "3 Remove the contents of both (%s and %s)\n" "${gitdir}" "${installdir}" +printf "3 Remove the contents of both (%s and %s)\n" "${repodir}" "${installdir}" printf "4 Do nothing\n" printf "1-4: " while true; do read -r r if [ "${r}" = "1" ]; then - erase "${gitdir}" + erase "${repodir}" elif [ "${r}" = "2" ]; then erase "${installdir}" elif [ "${r}" = "3" ]; then - erase "${gitdir}" + erase "${repodir}" erase "${installdir}" elif [ "${r}" = "4" ]; then break diff --git a/libexec/sourcezap/commands/sourcezap-sh b/libexec/sourcezap/commands/sourcezap-sh index efcb607..d102379 100755 --- a/libexec/sourcezap/commands/sourcezap-sh +++ b/libexec/sourcezap/commands/sourcezap-sh @@ -6,7 +6,7 @@ set -e localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} libexec="${localbase}"/libexec/sourcezap user=_sourcezap -gitdir="${1}" +repodir="${1}" ## # functions @@ -25,12 +25,12 @@ if ! "${libexec}"/utils/issourcezap-member; then exit 1 fi -if [ ! -e "${gitdir}" ]; then +if [ ! -e "${repodir}" ]; then printerr "try 'sourcezap clone' instead" exit 1 fi -cd "${gitdir}" +cd "${repodir}" doas -n \ -u "${user}" \ /bin/sh diff --git a/libexec/sourcezap/utils/git/get-changed-files b/libexec/sourcezap/utils/git/get-changed-files index d026bb4..45a46fd 100755 --- a/libexec/sourcezap/utils/git/get-changed-files +++ b/libexec/sourcezap/utils/git/get-changed-files @@ -6,11 +6,11 @@ set -e localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../../..)} libexec="${localbase}"/libexec/sourcezap git="${libexec}"/utils/git/run -gitdir=$1 +repodir=$1 commit=$2 ## # main -cd "${gitdir}" +cd "${repodir}" "${git}" diff -l0 --name-only --diff-filter=A "${commit}" "HEAD" "${git}" diff -l0 --name-only --diff-filter=M "${commit}" "HEAD" diff --git a/libexec/sourcezap/utils/git/get-removed-files b/libexec/sourcezap/utils/git/get-removed-files index 4d76c4a..1496528 100755 --- a/libexec/sourcezap/utils/git/get-removed-files +++ b/libexec/sourcezap/utils/git/get-removed-files @@ -6,10 +6,10 @@ set -e localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../../..)} libexec="${localbase}"/libexec/sourcezap git="${libexec}"/utils/git/run -gitdir=$1 +repodir=$1 commit=$2 ## # main -cd "${gitdir}" +cd "${repodir}" "${git}" diff -l0 --name-only --diff-filter=D "${commit}" "HEAD" diff --git a/libexec/sourcezap/utils/install/update-changed-files b/libexec/sourcezap/utils/install/update-changed-files index 51da754..577cb1a 100755 --- a/libexec/sourcezap/utils/install/update-changed-files +++ b/libexec/sourcezap/utils/install/update-changed-files @@ -5,14 +5,14 @@ set -e # variables localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../../..)} libexec="${localbase}"/libexec/sourcezap -gitdir=$1 +repodir=$1 installdir=$2 rev=$3 ## # main -cd "${gitdir}" -files=$("${libexec}"/utils/git/get-changed-files "${gitdir}" "${rev}") +cd "${repodir}" +files=$("${libexec}"/utils/git/get-changed-files "${repodir}" "${rev}") for file in ${files}; do target="${installdir}/${file}" parent=$(dirname "${target}") diff --git a/libexec/sourcezap/utils/install/update-deleted-files b/libexec/sourcezap/utils/install/update-deleted-files index 71ec800..fdcd104 100755 --- a/libexec/sourcezap/utils/install/update-deleted-files +++ b/libexec/sourcezap/utils/install/update-deleted-files @@ -5,14 +5,14 @@ set -e # variables localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../../..)} libexec="${localbase}"/libexec/sourcezap -gitdir=$1 +repodir=$1 installdir=$2 rev=$3 ## # main -cd "${gitdir}" -files=$("${libexec}"/utils/git/get-removed-files "${gitdir}" "${rev}") +cd "${repodir}" +files=$("${libexec}"/utils/git/get-removed-files "${repodir}" "${rev}") for file in ${files}; do target="${installdir}/${file}" parent=$(dirname "${target}")