class garage::webui {
  contain garage::webui::install
  contain garage::webui::service
}

class garage::webui::install {
  file { '/opt/garage-webui':
    ensure => directory
  }

  file { '/opt/garage-webui/webui':
    source => 'https://github.com/khairul169/garage-webui/releases/download/1.0.8/garage-webui-v1.0.8-linux-amd64',
    ensure => 'file',
    mode => '0740',
  }
}

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

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