class garage {
  contain garage::install
  contain garage::config
  contain garage::service

  contain garage::webui
}

class garage::install {
  file { '/opt/garage':
    ensure => directory,
    mode => '0640'
  }

  file { '/opt/garage/garage':
    ensure => file,
    source => 'https://garagehq.deuxfleurs.fr/_releases/v1.1.0/x86_64-unknown-linux-musl/garage',
    mode => '0740'
  }
}

class garage::config {
  file { '/opt/garage/garage.toml':
    content => template('garage/conf.toml.erb'),
    ensure => file,
    mode => '0644',
    notify => [Service['garage'], Service['garage-webui']]
  }
}

class garage::service {
  file { '/lib/systemd/system/garage.service':
    mode    => '0644',
    owner   => 'root',
    group   => 'root',
    content => template('garage/garage.service.erb'),
  }~>
  exec { 'garage-systemd-reload':
    command     => 'systemctl daemon-reload',
    path        => [ '/usr/bin', '/bin', '/usr/sbin' ],
    refreshonly => true,
  }

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