diff --git a/docs/chapters/template.rst b/docs/chapters/template.rst index 9552755d..73770bb7 100644 --- a/docs/chapters/template.rst +++ b/docs/chapters/template.rst @@ -76,11 +76,10 @@ CMD - run the specified command CONFIG - set the specified property and value -CP/OVERLAY - copy specified files from template directory to specified path - inside jail +CP/OVERLAY - copy specified files from template directory to specified path inside jail INCLUDE - specify a template to include. Make sure the template is - bootstrapped, or you are using the template url +bootstrapped, or you are using the template url LIMITS - set the specified resource value for the jail @@ -93,8 +92,7 @@ PKG - install specified packages inside jail RDR - redirect specified ports to the jail RENDER - replace ARG values inside specified files inside the jail. If a - directory is specified, ARGS will be replaced in all files - underneath +directory is specified, ARGS will be replaced in all files underneath RESTART - restart the jail diff --git a/usr/local/share/bastille/bootstrap.sh b/usr/local/share/bastille/bootstrap.sh index 18542ec4..198d970b 100644 --- a/usr/local/share/bastille/bootstrap.sh +++ b/usr/local/share/bastille/bootstrap.sh @@ -405,23 +405,41 @@ bootstrap_template() { _url=${BASTILLE_TEMPLATE_URL} _user=${BASTILLE_TEMPLATE_USER} _repo=${BASTILLE_TEMPLATE_REPO%.*} # Remove the trailing ".git" - _template=${bastille_templatesdir}/${_user}/${_repo} + _raw_template_dir=${bastille_templatesdir}/${_user}/${_repo} ## support for non-git if ! which -s git; then error_notify "Git not found." error_exit "Not yet implemented." else - if [ ! -d "${_template}/.git" ]; then - git clone "${_url}" "${_template}" ||\ + if [ ! -d "${_raw_template_dir}/.git" ]; then + git clone "${_url}" "${_raw_template_dir}" ||\ error_notify "Clone unsuccessful." - elif [ -d "${_template}/.git" ]; then - git -C "${_template}" pull ||\ + elif [ -d "${_raw_template_dir}/.git" ]; then + git -C "${_raw_template_dir}" pull ||\ error_notify "Template update unsuccessful." fi fi - bastille verify "${_user}/${_repo}" + if [ ! -f ${_raw_template_dir}/Bastillefile ]; then + # Extract template in project/template format + find "${_raw_template_dir}" -type f -name Bastillefile | while read -r _file; do + _project="$(dirname "$(dirname ${_file})")" + _template="$(basename ${_project})" + _complete_template="$(basename ${_project})"/"$(basename "$(dirname ${_file})")" + cp -fR "${_project}" "${bastille_templatesdir}/${_template}" + bastille verify "${_complete_template}" + done + + # Remove the cloned repo + if [ -n "${_user}" ]; then + rm -r "${bastille_templatesdir:?}/${_user:?}" + fi + + else + # Verify a single template + bastille verify "${_user}/${_repo}" + fi } # Handle options. diff --git a/usr/local/share/bastille/list.sh b/usr/local/share/bastille/list.sh index 22f81f3f..07c541ca 100644 --- a/usr/local/share/bastille/list.sh +++ b/usr/local/share/bastille/list.sh @@ -204,7 +204,7 @@ list_release(){ } list_template(){ - find "${bastille_templatesdir}" -type d -maxdepth 2 + find "${bastille_templatesdir}" -type d -maxdepth 2 | sed 's#${bastille_templatesdir}/##g' } list_jail(){ diff --git a/usr/local/share/bastille/verify.sh b/usr/local/share/bastille/verify.sh index f1983902..89de9340 100644 --- a/usr/local/share/bastille/verify.sh +++ b/usr/local/share/bastille/verify.sh @@ -143,7 +143,7 @@ verify_template() { if [ "${_hook_validate}" -lt 1 ]; then error_notify "No valid template hooks found." error_notify "Template discarded." - rm -rf "${bastille_template}" + rm -rf "${_template_path}" exit 1 fi