From dd1308d1adaa92c102ec2da21367e49a3ef81012 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 21 Apr 2025 16:47:49 -0600 Subject: [PATCH 01/10] Allow bootstrapping templates in subdirectories --- usr/local/share/bastille/bootstrap.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/usr/local/share/bastille/bootstrap.sh b/usr/local/share/bastille/bootstrap.sh index 18542ec4..1aff642a 100644 --- a/usr/local/share/bastille/bootstrap.sh +++ b/usr/local/share/bastille/bootstrap.sh @@ -421,7 +421,14 @@ bootstrap_template() { fi fi - bastille verify "${_user}/${_repo}" + # Extract template in project/template format + find "${_template}" -type f -name Bastillefile | while read -r _file; do + _project="$(dirname "$(dirname ${_file})")" + _basename="$(basename ${_project})" + _complete_template="$(basename ${_project})/$(basename $(dirname ${_file}))" + cp -fR "${_project}" "${bastille_templatesdir}/${_basename}" + bastille verify "${_complete_template}" + done } # Handle options. From 6888212953db2706339524ec6dfa4e36a6365808 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 21 Apr 2025 16:50:25 -0600 Subject: [PATCH 02/10] fix shellcheck --- usr/local/share/bastille/bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/bootstrap.sh b/usr/local/share/bastille/bootstrap.sh index 1aff642a..1decf94b 100644 --- a/usr/local/share/bastille/bootstrap.sh +++ b/usr/local/share/bastille/bootstrap.sh @@ -425,7 +425,7 @@ bootstrap_template() { find "${_template}" -type f -name Bastillefile | while read -r _file; do _project="$(dirname "$(dirname ${_file})")" _basename="$(basename ${_project})" - _complete_template="$(basename ${_project})/$(basename $(dirname ${_file}))" + _complete_template=""$(basename ${_project})"/"$(basename "$(dirname ${_file})")"" cp -fR "${_project}" "${bastille_templatesdir}/${_basename}" bastille verify "${_complete_template}" done From 7f1a372baffd9c7df553f69deaa0e83aaa6259b9 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 21 Apr 2025 16:52:13 -0600 Subject: [PATCH 03/10] docs: Minor spacing fix --- docs/chapters/template.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/chapters/template.rst b/docs/chapters/template.rst index 1a4e36d4..6d31ec4c 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 From 78764e581c901f3906925d443157c6b5ebcf9f8c Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 21 Apr 2025 16:58:32 -0600 Subject: [PATCH 04/10] fix shellcheck --- usr/local/share/bastille/bootstrap.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/usr/local/share/bastille/bootstrap.sh b/usr/local/share/bastille/bootstrap.sh index 1decf94b..1db53f9e 100644 --- a/usr/local/share/bastille/bootstrap.sh +++ b/usr/local/share/bastille/bootstrap.sh @@ -405,30 +405,35 @@ 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 # Extract template in project/template format - find "${_template}" -type f -name Bastillefile | while read -r _file; do + find "${_raw_template_dir}" -type f -name Bastillefile | while read -r _file; do _project="$(dirname "$(dirname ${_file})")" - _basename="$(basename ${_project})" - _complete_template=""$(basename ${_project})"/"$(basename "$(dirname ${_file})")"" - cp -fR "${_project}" "${bastille_templatesdir}/${_basename}" + _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 "${_raw_template_dir}" ]; then + rm -r "${_raw_template_dir}" + fi } # Handle options. From 4cd63e5057b15d79dcec9383304c0023f107c61f Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 21 Apr 2025 17:05:26 -0600 Subject: [PATCH 05/10] verify: Fix wrong var name when removing wrong template --- usr/local/share/bastille/verify.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From fb3d300779ae67674a8d35649e62e6980000af60 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 21 Apr 2025 17:10:30 -0600 Subject: [PATCH 06/10] bootstrap: Fix cloning single template --- usr/local/share/bastille/bootstrap.sh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/usr/local/share/bastille/bootstrap.sh b/usr/local/share/bastille/bootstrap.sh index 1db53f9e..51f16193 100644 --- a/usr/local/share/bastille/bootstrap.sh +++ b/usr/local/share/bastille/bootstrap.sh @@ -421,18 +421,22 @@ bootstrap_template() { fi fi - # 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 + 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 + else + bastille verify "${_raw_template_dir}" + fi # Remove the cloned repo - if [ -n "${_raw_template_dir}" ]; then - rm -r "${_raw_template_dir}" + if [ -n "${_user}" ]; then + rm -r "${bastille_templatesdir}/${_user}" fi } From 511c6dbd23dd73862083e009279490441acf1ca0 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 21 Apr 2025 17:13:25 -0600 Subject: [PATCH 07/10] bootstrap: Fix verify --- usr/local/share/bastille/bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/bootstrap.sh b/usr/local/share/bastille/bootstrap.sh index 51f16193..89e1a2a9 100644 --- a/usr/local/share/bastille/bootstrap.sh +++ b/usr/local/share/bastille/bootstrap.sh @@ -431,7 +431,7 @@ bootstrap_template() { bastille verify "${_complete_template}" done else - bastille verify "${_raw_template_dir}" + bastille verify "${_user}/${_repo}" fi # Remove the cloned repo From 4feef07ca73a965c6f05989d3f02f2f141d321c9 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 21 Apr 2025 17:18:04 -0600 Subject: [PATCH 08/10] bootstrap: Bugfix when bootstrapping single template --- usr/local/share/bastille/bootstrap.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/usr/local/share/bastille/bootstrap.sh b/usr/local/share/bastille/bootstrap.sh index 89e1a2a9..e2205ab8 100644 --- a/usr/local/share/bastille/bootstrap.sh +++ b/usr/local/share/bastille/bootstrap.sh @@ -430,14 +430,16 @@ bootstrap_template() { 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 - - # Remove the cloned repo - if [ -n "${_user}" ]; then - rm -r "${bastille_templatesdir}/${_user}" - fi } # Handle options. From 601cd1c9cb619399cd8b994089c98ad6904bdfd8 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 21 Apr 2025 17:24:59 -0600 Subject: [PATCH 09/10] fix shellcheck --- usr/local/share/bastille/bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/bootstrap.sh b/usr/local/share/bastille/bootstrap.sh index e2205ab8..198d970b 100644 --- a/usr/local/share/bastille/bootstrap.sh +++ b/usr/local/share/bastille/bootstrap.sh @@ -433,7 +433,7 @@ bootstrap_template() { # Remove the cloned repo if [ -n "${_user}" ]; then - rm -r "${bastille_templatesdir}/${_user}" + rm -r "${bastille_templatesdir:?}/${_user:?}" fi else From 1cc713ec86dfcf7ecb795e5347b90331f579776a Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 21 Apr 2025 17:30:16 -0600 Subject: [PATCH 10/10] list: Only list the relevant template part of the directory --- usr/local/share/bastille/list.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(){