#cloud-config

# Tested on:
# - Oracle Linux 8.6

yum_repos:
  epel:
    name: Extra Packages for Enterprise Linux 8 - $basearch
    baseurl: https://dl.fedoraproject.org/pub/epel/8/Everything/$basearch
    gpgcheck: true
    gpgkey: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-8

packages:
  - boinc-client
  - boinc-tui

bootcmd:
  # `cloud-init` has issues with `firewall-cmd`, using the offline version.
  - firewall-offline-cmd --add-port='31416/tcp' --zone='public'

runcmd:
  - grep -q 'boinc' '/etc/group' && sudo usermod -a -G 'boinc' 'opc'
  - chown -R 'boinc:boinc' '/var/lib/boinc'
  - systemctl enable --now 'boinc-client.service'
  - sleep '5s'
  - boinccmd --acct_mgr attach 'acct_mgr_url' 'acct_mgr_user' 'acct_mgr_password'
  - systemctl reload 'firewalld.service'

write_files:
  - path: /var/lib/boinc/gui_rpc_auth.cfg
    permissions: '0640'
    content: |
      gui_rpc_password
  - path: /var/lib/boinc/cc_config.xml
    content: |
      <cc_config>
        <options>
          <allow_remote_gui_rpc>1</allow_remote_gui_rpc>
        </options>
      </cc_config>
  - path: /var/lib/boinc/remote_hosts.cfg
    content: |
      192.168.1.10
      192.168.1.115
