53 lines
891 B
Bash
Executable file
53 lines
891 B
Bash
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
##
|
|
# variables
|
|
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../..)}
|
|
libexec="${localbase}"/libexec/portzap
|
|
git="${localbase}"/bin/git
|
|
giturl=$1
|
|
gitdir=$2
|
|
branch=$3
|
|
mode=u=rwX,g=rX,o=
|
|
|
|
##
|
|
# functions
|
|
gitexec()
|
|
{
|
|
doas -n -u _portzap \
|
|
/bin/sh -c "umask ${mode}; ${git} ${1}"
|
|
}
|
|
|
|
printok() {
|
|
"${libexec}"/printok "$1"
|
|
}
|
|
|
|
printerr() {
|
|
"${libexec}"/printerr "$1"
|
|
}
|
|
|
|
##
|
|
# main
|
|
if [ "$(id -u)" = "0" ]; then
|
|
printerr "you must be a user other than root"
|
|
exit 1
|
|
fi
|
|
|
|
if ! "${libexec}"/isportzap-member > /dev/null 2>&1; then
|
|
printerr "$(id -un) is not a member of _portzap"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -e "${gitdir}/.git" ]; then
|
|
printerr "try 'portzap pull' instead"
|
|
exit 1
|
|
fi
|
|
|
|
set -x
|
|
gitexec "clone ${giturl} ${gitdir}"
|
|
cd "${gitdir}"
|
|
gitexec "config core.filemode off"
|
|
set +x
|
|
gitexec "checkout -t origin/${branch}"
|
|
printok "clone complete"
|