#!/usr/bin/env bash

### Ensure Qubes minimal templates have passwordless sudo
for TEMPLATE of {{ .qubes.templates | toString | replace "[" "" | replace "]" "" }}; do
  if [[ "$TEMPLATE" == *'-minimal' ]]; then
    if [[ "$TEMPLATE" == 'debian'* ]] || [[ "$TEMPLATE" == 'ubuntu'* ]]; then
      logg info "Installing qubes-core-agent-passwordless-root on $TEMPLATE"
      qvm-run -u root "$TEMPLATE" apt-get update
      qvm-run -u root "$TEMPLATE" apt-get install -y qubes-core-agent-passwordless-root
    elif [[ "$TEMPLATE" == 'fedora'* ]]; then
      logg info "Installing qubes-core-agent-passwordless-root on $TEMPLATE"
      qvm-run -u root "$TEMPLATE" dnf install -y qubes-core-agent-passwordless-root
    fi
  fi
done
