class owncloud {
  contain owncloud::install
  contain owncloud::config
  contain owncloud::service
}

class owncloud::install {
  file { '/opt/owncloud':
    ensure => directory
  }

  file { '/opt/owncloud/ocis':
    ensure => file,
    source => 'https://github.com/owncloud/ocis/releases/download/v7.1.2/ocis-7.1.2-linux-amd64',
    mode => '0744'
  }
}

class owncloud::config {
  file { '/opt/owncloud/ocis.yaml':
    ensure => file,
    source => 'puppet:///modules/owncloud/ocis.yaml',
    notify => Service['owncloud']
  }
}

class owncloud::service {
  file { '/lib/systemd/system/owncloud.service':
    ensure => file,
    content => template('owncloud/owncloud.service.erb'),
    notify => Service['owncloud']
  }~>
  exec { 'owncloud-systemd-reload':
    command     => 'systemctl daemon-reload',
    path        => [ '/usr/bin', '/bin', '/usr/sbin' ],
    refreshonly => true,
  }

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