Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repaired git #12

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions usr/local/etc/rocinante.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
rocinante_branches="main master"
rocinante_default_branch="main"
rocinante_libdir="/usr/local/libexec/rocinante"
rocinante_prefix="/usr/local/rocinante"
rocinante_templatesdir="/usr/local/rocinante/templates"
Expand Down
32 changes: 21 additions & 11 deletions usr/local/libexec/rocinante/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fetch_template() {
_url=${ROCINANTE_TEMPLATE_URL}
_user=${ROCINANTE_TEMPLATE_USER}
_repo=${ROCINANTE_TEMPLATE_REPO}
_branch=${ROCINANTE_TEMPLATE_BRANCH}
_template=${rocinante_templatesdir}/${_user}/${_repo}
_template_user=${rocinante_templatesdir}/${_user}

Expand All @@ -98,21 +99,30 @@ fetch_template() {
# rocinante verify "${_user}/${_repo}"
#fi
else
if [ ! -d "${rocinante_templatesdir}/.git" ]; then
git clone "${_url}" "${rocinante_templatesdir}" || error_notify "Clone unsuccessful."
elif [ -d "${rocinante_templatesdir}/.git" ]; then
git -C "${rocinante_templatesdir}" pull ||\
if [ ! -d "${_template}/.git" ]; then
mkdir -p "${_template}/"
git clone --branch ${_branch} --single-branch "${_url}" "${_template}" || error_notify "Clone unsuccessful."
elif [ -d "${_template}/.git" ]; then
git -C "${_template}" pull ||\
error_notify "Template update unsuccessful."
fi
#rocinante verify "${_user}/${_repo}"
fi
}

case "${1}" in
http?://*/*/*)
ROCINANTE_TEMPLATE_URL=${1}
ROCINANTE_TEMPLATE_USER=$(echo "${1}" | awk -F / '{ print $4 }')
ROCINANTE_TEMPLATE_REPO=$(echo "${1}" | awk -F / '{ print $5 }')
fetch_template
;;
if [ $# -lt 1 ]
error_exit "Usage: rocinante bootstrap <template_url> [branch]"
fi

ROCINANTE_TEMPLATE_URL=${1}
shift
ROCINANTE_TEMPLATE_BRANCH="${1:-$rocinance_default_branch}"


case "${ROCINANTE_TEMPLATE_URL}" in
http?://*/*/*)
ROCINANTE_TEMPLATE_USER=$(echo "${1}" | awk -F / '{ print $4 }')
ROCINANTE_TEMPLATE_REPO=$(echo "${1}" | awk -F / '{ print $5 }')
fetch_template
;;
esac
17 changes: 13 additions & 4 deletions usr/local/libexec/rocinante/template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
. /usr/local/etc/rocinante.conf

template_usage() {
error_exit "Usage: rocinante template template/path"
error_exit "Usage: rocinante template template/path [branch]"
}

post_command_hook() {
Expand Down Expand Up @@ -118,6 +118,9 @@ fi

## global variables
TEMPLATE="${1}"
shift
BRANCH="${1:-$rocinante_default_branch}"

rocinante_template=${rocinante_templatesdir}/${TEMPLATE}
if [ -z "${HOOKS}" ]; then
HOOKS='LIMITS INCLUDE PRE FSTAB PF PKG OVERLAY CONFIG SYSRC SERVICE CMD RENDER'
Expand Down Expand Up @@ -175,14 +178,20 @@ fi
case ${TEMPLATE} in
http?://*/*/*)
TEMPLATE_DIR=$(echo "${TEMPLATE}" | awk -F / '{ print $4 "/" $5 }')
if [ ! -d "${rocinante_templatesdir}/${TEMPLATE_DIR}" ]; then
LOCAL_REPO="${rocinante_templatesdir}/${TEMPLATE_DIR}"
if [ ! -d "${LOCAL_REPO}" ]; then
info "Bootstrapping ${TEMPLATE}..."
if ! rocinante bootstrap "${TEMPLATE}"; then
if ! rocinante bootstrap "${TEMPLATE} ${BRANCH}"; then
error_exit "Failed to bootstrap template: ${TEMPLATE}"
fi
else
git -C ${LOCAL_REPO} -b ${BRANCH} remote update || error_exit "Directory '${LOCAL_REPO}' exists but could not be updated from '${TEMPLATE}' using branch '${BRANCH}'."
if [ `git -C ${LOCAL_REPO} rev-list --branches=${BRANCH} HEAD...origin/master --count` = '0' ]; then
rocinante bootstrap "${TEMPLATE}" "${BRANCH}" || error_exit "Failed to pull template: ${TEMPLATE}"
fi
fi
TEMPLATE="${TEMPLATE_DIR}"
rocinante_template=${rocinante_templatesdir}/${TEMPLATE}
rocinante_template=${LOCAL_REPO}
;;
*/*)
if [ ! -d "${rocinante_templatesdir}/${TEMPLATE}" ]; then
Expand Down