class forgejo {
  contain forgejo::install
  contain forgejo::service
}

class forgejo::install {
  user { 'forgejo':
    ensure => 'present',
  }

  file { '/opt/forgejo':
    ensure => directory,
    owner => 'forgejo',
  }

  file { '/opt/forgejo/forgejo':
    source => 'https://codeberg.org/forgejo/forgejo/releases/download/v10.0.3/forgejo-10.0.3-linux-amd64',
    ensure => file,
    owner => 'forgejo',
    mode => '0744'
  }
}


class forgejo::service {
  file { '/lib/systemd/system/forgejo.service':
    ensure => file,
    source => 'puppet:///modules/forgejo/forgejo.service',
    notify => Service['forgejo']
  }~>
  exec { 'forgejo-systemd-reload':
    command     => 'systemctl daemon-reload',
    path        => [ '/usr/bin', '/bin', '/usr/sbin' ],
    refreshonly => true,
  }

  service { 'forgejo':
    ensure => running,
    enable => true,
  }
}
