{{- if (eq .host.distro.id "qubes") -}}
#!/usr/bin/env bash
# @file Qubes Install Templates
# @brief Ensures the templates defined in `.qubes.templates` in the `home/.chezmoidata.yaml` file are installed
# @description
#     This script runs in dom0 and ensures the templates defined in `home/.chezmoidata.yaml` are all installed.

{{ includeTemplate "universal/profile-before" }}
{{ includeTemplate "universal/logg-before" }}

### Ensure Qubes templates exist and download if they are not present
for TEMPLATE of {{ .qubes.templates | toString | replace "[" "" | replace "]" "" }}; do
  if [ ! -f "/var/lib/qubes/vm-templates/$TEMPLATE" ]; then
    logg info "Installing $TEMPLATE"
    sudo qubes-dom0-update "qubes-template-$TEMPLATE"
  fi
done
{{ end -}}
