# Maintainer (Manjaro): artoo <artoo@manjaro.org>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>

_url="https://raw.githubusercontent.com/gentoo/gentoo/master"

pkgbase=openrc-misc
pkgname=('cpupower-openrc'
        'connman-openrc'
        'fcron-openrc'
        'fuse-openrc'
        'metalog-openrc'
        'rsyslog-openrc'
        'sane-openrc'
        'syslog-ng-openrc'
        'lirc-utils-openrc'
        'lm_sensors-openrc'
        'ntp-openrc'
        'cups-openrc'
        'haveged-openrc'
        'salt-openrc'
        'mpd-openrc'
        'hdparm-openrc'
        'bitlbee-openrc'
        'thermald-openrc'
        'xe-guest-utilities-openrc'
        'zfs-openrc'
        'clamav-openrc'
        'at-openrc'
        'libvirt-openrc'
        'laptop-mode-tools-openrc')
pkgver=20160528
pkgrel=1.parabola2
pkgdesc="OpenRC init scripts"
arch=('any')
url="https://github.com/manjaro/packages-openrc"
license=('GPL2')
groups=('openrc-misc')
conflicts=('systemd-sysvcompat')
source=("fcron.initd::${_url}/sys-process/fcron/files/fcron.init.3"
        "rsyslog.confd::${_url}/app-admin/rsyslog/files/8-stable/rsyslog.confd-r1"
        "rsyslog.initd::${_url}/app-admin/rsyslog/files/8-stable/rsyslog.initd-r1"
        "saned.confd::${_url}/media-gfx/sane-backends/files/saned.confd"
        "saned.initd::${_url}/media-gfx/sane-backends/files/saned.initd"
        "fuse.initd::${_url}/sys-fs/fuse/files/fuse.init"
        "metalog.confd::${_url}/app-admin/metalog/files/metalog.confd"
        "metalog.initd::${_url}/app-admin/metalog/files/metalog.initd"
        "syslog-ng.confd::${_url}/app-admin/syslog-ng/files/3.7/syslog-ng.confd"
        "syslog-ng.initd::${_url}/app-admin/syslog-ng/files/3.7/syslog-ng.rc6"
        "lircd.confd::${_url}/app-misc/lirc/files/lircd.conf.4"
        "irexec.confd::${_url}/app-misc/lirc/files/irexec-confd"
        "lircd.initd::${_url}/app-misc/lirc/files/lircd-0.8.6-r2"
        "irexec.initd::${_url}/app-misc/lirc/files/irexec-initd-0.8.6-r2"
        "lircmd.initd::${_url}/app-misc/lirc/files/lircmd"
        "cpupower.confd::${_url}/sys-power/cpupower/files/conf.d-r2"
        "cpupower.initd::${_url}/sys-power/cpupower/files/init.d-r4"
        #"sensord.confd::${_url}/sys-apps/lm_sensors/files/sensord-conf.d"
        "sensord.initd::${_url}/sys-apps/lm_sensors/files/sensord-4-init.d"
        "fancontrol.initd::${_url}/sys-apps/lm_sensors/files/fancontrol-init.d-2"
        "lm_sensors.initd::${_url}/sys-apps/lm_sensors/files/lm_sensors-3-init.d"
        "ntpd.confd::${_url}/net-misc/ntp/files/ntpd.confd"
        "ntp-client.confd::${_url}/net-misc/ntp/files/ntp-client.confd"
        "sntp.confd::${_url}/net-misc/ntp/files/sntp.confd"
        "ntpd.initd::${_url}/net-misc/ntp/files/ntpd.rc-r1"
        "ntp-client.initd::${_url}/net-misc/ntp/files/ntp-client.rc"
        "sntp.initd::${_url}/net-misc/ntp/files/sntp.rc"
        "cupsd.initd::${_url}/net-print/cups/files/cupsd.init.d-r2"
        "connman.confd::${_url}/net-misc/connman/files/connman.confd"
        "connman.initd::${_url}/net-misc/connman/files/connman.initd2"
        "haveged.confd::${_url}/sys-apps/haveged/files/haveged-conf.d"
        "haveged.initd::${_url}/sys-apps/haveged/files/haveged-init.d.3"
        "salt-master.confd::${_url}/app-admin/salt/files/master-confd-1"
        "salt-master.initd::${_url}/app-admin/salt/files/master-initd-4"
        "salt-minion.confd::${_url}/app-admin/salt/files/minion-confd-1"
        "salt-minion.initd::${_url}/app-admin/salt/files/minion-initd-4"
        "salt-syncdic.confd::${_url}/app-admin/salt/files/syndic-confd-1"
        "salt-syncdic.initd::${_url}/app-admin/salt/files/syndic-initd-4"
        "salt-api.confd::${_url}/app-admin/salt/files/api-confd-1"
        "salt-api.initd::${_url}/app-admin/salt/files/api-initd-4"
        "mpd.initd::${_url}/media-sound/mpd/files/mpd2.init"
        "hdparm.confd::${_url}/sys-apps/hdparm/files/hdparm-conf.d.3"
        "hdparm.initd::${_url}/sys-apps/hdparm/files/hdparm-init-8"
        "bitlbee.confd::${_url}/net-im/bitlbee/files/bitlbee.confd-r1"
        "bitlbee.initd::${_url}/net-im/bitlbee/files/bitlbee.initd-r1"
        "xe-daemon.initd::${_url}/app-emulation/xe-guest-utilities/files/xe-daemon.initd"
        "clamd.confd::${_url}/app-antivirus/clamav/files/clamd.conf-r1"
        "clamd.initd::${_url}/app-antivirus/clamav/files/clamd.initd-r6"
        "atd.confd::${_url}/sys-process/at/files/atd.confd"
        "atd.initd::${_url}/sys-process/at/files/atd.rc8"
        "libvirtd.confd::${_url}/app-emulation/libvirt/files/libvirtd.confd-r5"
        "libvirtd.initd::${_url}/app-emulation/libvirt/files/libvirtd.init-r16"
        "virtlockd.initd::${_url}/app-emulation/libvirt/files/virtlockd.init-r1"
        "virtlogd.initd::${_url}/app-emulation/libvirt/files/virtlogd.init-r1"
        "libvirt-guests.confd::${_url}/app-emulation/libvirt/files/libvirt-guests.confd"
        "libvirt-guests.initd::${_url}/app-emulation/libvirt/files/libvirt-guests.init-r2"
        "laptop_mode.initd::${_url}/app-laptop/laptop-mode-tools/files/laptop_mode.init-1.4"
        "zfs.initd"
        "thermald.initd")
sha256sums=('c067d2a58609b53e5bc6f8397683604de893bd1aeb3d33e788250662187fda6e'
            '0be3575df8010523de6b37e98c417192e8ec481292ca9fb47c8d2211795e03a6'
            '2c8800c31b8411899b49036bd51ed58a625ee8b7bd523b18d6ad8b7399da0324'
            '197e44ba1f438a18f5f7d9f5858feb19c1ece4286d82a5e63caf9be5b964aa76'
            'bd336c156be06e3aa45b3185a26ba80232dfc0511fc99317cf2ef29af7347f34'
            '66ce65e2459fef26bb1711d706a23643a9af7a80e03ee6be836a377310b00682'
            'ddefb75e696ba13581e9cccf6dbe70e744793613070c01ad9505b059ae6f2317'
            '6a2483451c2907352018b9ca1c487a7024a7b5da907e06409d471186a80e08ab'
            'b29325498ee3b1f3d63672efcd1e93f0745eecdb9f4bb05fed82a2f085399484'
            '99102b37d9a644c24e016de7f79152f8a2dcdf4ffd8efda39c7380c1b42e7321'
            'd36ff77fa193a065d25e373723e03f1a9471205151b82c73a6574cce4f095962'
            'c404ad3b624004cab25bd3a89593cdeb0abbc25771d6e52caf2f37cb4f7b2b79'
            '2647b25b7516031e66ac252edafbaca2f2d6934473a6e15fdcc2a462ba0cb2ae'
            'c5fcf54620ae2c003fe6ea04ab624c3607c6b9b6f65c971c34fbb7293681d030'
            'aee017bea6c79a419ad40e55a4cc3ffbeacafe330d931b0dd8bfb4c6cb7c6183'
            '9ab6f022d2b2948660decf5e383984e6ddb9e9e5e6e2761c3031378ddd87e947'
            'bd7133303c9a0fc892267335b6fb371d6179c6f4251d7f360ae82d7d1f0b321f'
            'b273a293d405be78a28bd580ab93830598c54c95e9258dbd00b51370a9366e5c'
            'd8f9a0e12307a3fd788c9ba859cf9169b45686fd475d588a5b266e05f2ab8f3a'
            'c552aee739b30b74200877183ddadeab7c525b0496cac68a576207984cb9877b'
            '40803821f498267f6567436eedc18201b5ae4b5390d6872fb15a94200c2ac06f'
            'c7dc517cdb5ee10e2a07ccea15ec47ba0b7aff8ac1469204c8d7faf71bcae2c5'
            '97282007801cb9c0e3b431e2930dec3bb8ce8869f63f7e02d903846e96734684'
            '56dffdfa0d347ef667cb08a26ce68b1d445f71031ae1df3309ff3219f10307a9'
            'aebe701f1479a8dfe6b4b21b3ad4641f64fdc3c4ef5deafeb9adfea10d1649e9'
            '0f516f1f35afec9a7aeff1fe311d529b6907c3accaa476f982e0f93f7c932d61'
            '811da0e9b25d33af3e7f5f54765840e834fb55eb96d3654083991233ca294e81'
            '767a160c1b3392f0a12d3908a937548a2f604a9a121e744c309ee6f478420b02'
            'c4c21edcf04d7ce873a8075675b44af823175b133b41d2056ed9d1ea4c637c3f'
            'a34c6fac6cdb544653029be77298bb72345d10c70824412384e32efb73098d01'
            '945ebceff8a27cb043cbf455561d7e14b249a2bba912b8bac098f7c4b63573d3'
            '9f3f47a7af4d349a7c525455616139b5019d3b7d0290398ba8c50ab91a62d089'
            '88cb136de7e12f0519757637433afe45c7be7e4f77604ef33a26e8318dfff382'
            '286148f5391d42c04a62a13cc125fa2130b5821e50da913c5a20d3a913e5f2d1'
            '5276e72fe72a5b476a5b43478b4095d7e31d779617a4311e00816ca281c989f1'
            '286148f5391d42c04a62a13cc125fa2130b5821e50da913c5a20d3a913e5f2d1'
            '70c297293fa3563c7f06b9e16e1594fab106825da1ea3bf3842eb9ad9b89fca7'
            '9f3f47a7af4d349a7c525455616139b5019d3b7d0290398ba8c50ab91a62d089'
            '924b35f1b24ecca656ce5e4d4d6b2fcb1bdbe853ee08508cf7fbb6eb0f355635'
            '4e9bc6ae4af44c54cee6e661c01e788ee5e181f93144e80426a3fca2d464e094'
            '37c95ff723fa578e9039613d09dbf790d99113a318c065422986c744519214e9'
            '737e318b56c9de265c7a7a4c8cc00c0880163a0e1874c9d9f70a5ea2374c22e7'
            'cab8b8cb8709f27a5fa9f1cfce4b58db24f5cd38b8e6badb91dac0809e6ca8de'
            'c079bd4e3c551de7c14127aa4f31cd33d0f3e5210373145d4c11105626b42515'
            '444021f72322e781828ad70c8a49b70fa37c96a31024dc69f45268716c30006d'
            '28ebd47810b0568fc7692218867d6804a1df70290681462f5555e230ca817732'
            '443bdf8bab0014e4f60001c14350f609d94bc4a11d6319ed55a3c596f96f9a92'
            '64bd280926400d03b92ceeaf89982c52f299c2df39d8e01247678107d958574e'
            '4fe9dad976dac73b58db52984411ce8b54b7b4b8abc20b89730453c91251ee8c'
            '4f7fba7e64533868119c0f3355aa22932e163b208397323dc2cd96daadcc4079'
            '08e4527b5e7e44267eaacb9e093f23e5832393fa4dd0a427966142e81d9070ec'
            'e42c087342b510f8f3ec7bcc274b9e11841b41fe61e03365430ce40f6a180aa2'
            '51c030d7ba9a9dad1f927020592d7aef2dc2cd4abf38bd4ca97eee60943c7901'
            'd5f85bb8c1d2010347f23badc422e98046b97a0066254739b5829fce07837d63'
            'f78ced5ebe644522c6ce102b3f6bcf932686243a50629559f988548c570cad3a'
            'e76c20f84134d03068770c7521720b2b409a44892052bf1ebf54395eb24a6f27'
            '7321272190ea9846ab7e19b034649c1cd711d4f94a6bdcaaaec2f683bb822e7d'
            '4bbb4e610d2d6bb22d83aa2980dca052a23b90fa6985c8245601b716dec986f4')

pkgver() {
	date +%Y%m%d
}

_inst_initd(){
	install -Dm755 ${srcdir}/$1.initd ${pkgdir}/etc/init.d/$1

	sed -e 's|#!/sbin/runscript|#!/usr/bin/openrc-run|' \
            -e 's|#!/sbin/openrc-run|#!/usr/bin/openrc-run|' \
		-e 's|/var/run|/run|g' \
		-e 's|/usr/sbin|/usr/bin|g' \
		-i ${pkgdir}/etc/init.d/$1
}

_inst_confd(){
	install -Dm755 ${srcdir}/$1.confd ${pkgdir}/etc/conf.d/$1
}

package_bitlbee-openrc() {
	pkgdesc="OpenRC bitlbee init script"
	depends=('openrc' 'bitlbee')
	backup=('etc/conf.d/bitlbee')

	_inst_confd 'bitlbee'
	_inst_initd 'bitlbee'

	sed -e 's|need logger net|need net\n	use logger|' \
		-i "${pkgdir}/etc/init.d/bitlbee"
}

package_cpupower-openrc() {
	pkgdesc="OpenRC cpupower init script"
	depends=('openrc' 'cpupower')
	backup=('etc/conf.d/cpupower')

	_inst_confd 'cpupower'
	_inst_initd 'cpupower'
}

package_connman-openrc() {
	pkgdesc="OpenRC connman init script"
	depends=('openrc' 'connman')
	backup=('etc/conf.d/connman')

	_inst_confd 'connman'
	_inst_initd 'connman'
}

package_cups-openrc() {
	pkgdesc="OpenRC cups init script"
	depends=('cups' 'dbus-openrc')
	optdepends=('avahi-openrc: avahi initscript')

	_inst_initd 'cupsd'

	sed -e 's|lp:lpadmin|daemon:sys|' \
		-e 's|@neededservices@|need dbus avahi-daemon|' \
		-i "${pkgdir}/etc/init.d/cupsd"
}

package_fcron-openrc() {
	pkgdesc="OpenRC fcron init script"
	depends=('openrc' 'fcron')
	groups=('openrc-misc')
	provides=('openrc-cron')
	conflicts=('cronie'
		'cronie-openrc'
		'systemd-sysvcompat')

	_inst_initd 'fcron'

    sed -e 's|/usr/libexec|/usr/bin|g' \
		-i "${pkgdir}/etc/init.d/fcron"
}

package_ntp-openrc() {
	pkgdesc="OpenRC ntp init script"
	depends=('openrc' 'ntp')
	optdepends=('bind-openrc: bind initscript')
	provides=('openrc-timed')
	conflicts=('openntpd'
                'openntpd-openrc'
                'systemd-sysvcompat')
	backup=('etc/conf.d/ntpd'
		'etc/conf.d/ntp-client'
		'etc/init.d/sntp')

        for f in ntpd ntp-client sntp;do
            _inst_confd $f
            _inst_initd $f
        done
}

package_rsyslog-openrc() {
	pkgdesc="OpenRC rsyslog init script"
	depends=('openrc' 'rsyslog')
	backup=('etc/conf.d/rsyslog')

	_inst_confd 'rsyslog'
	_inst_initd 'rsyslog'
}

package_sane-openrc() {
	pkgdesc="OpenRC sane init script"
	depends=('openrc' 'sane')
	backup=('etc/conf.d/saned')

	_inst_confd 'saned'
	_inst_initd 'saned'

    sed -e 's|/run/saned/saned.pid|/run/saned.pid|' \
		-i ${pkgdir}/etc/init.d/saned
}

package_fuse-openrc(){
	pkgdesc="OpenRC fuse init script"
	depends=('openrc' 'fuse')

	_inst_initd 'fuse'
}

package_metalog-openrc() {
	pkgdesc="OpenRC metalog init script"
	depends=('openrc' 'metalog')
	backup=('etc/conf.d/metalog')

	_inst_confd 'metalog'
	_inst_initd 'metalog'
}

package_syslog-ng-openrc() {
	pkgdesc="OpenRC syslog-ng init script"
	depends=('openrc' 'syslog-ng')
	backup=('etc/conf.d/syslog-ng')

	_inst_confd 'syslog-ng'
	_inst_initd 'syslog-ng'
}

package_lm_sensors-openrc() {
	pkgdesc="OpenRC lm_sensors init script"
	depends=('openrc' 'lm_sensors')
	#backup=('etc/conf.d/sensord')

	_inst_initd 'sensord'
	_inst_initd 'fancontrol'
	_inst_initd 'lm_sensors'
}

package_lirc-utils-openrc() {
	pkgdesc="OpenRC lirc-utils init script"
	depends=('openrc' 'lirc-utils')
	backup=('etc/conf.d/lircd'
		'etc/conf.d/irexec')


	for f in lircd irexec;do
            _inst_confd $f
            _inst_initd $f
	done

	_inst_initd 'lircmd'
}

package_haveged-openrc() {
	pkgdesc="OpenRC haveged init script"
	depends=('openrc' 'haveged')
	backup=('etc/conf.d/haveged')

	_inst_confd 'haveged'
	_inst_initd 'haveged'
}

package_salt-openrc() {
	pkgdesc="OpenRC salt init scripts"
	depends=('openrc' 'salt')
	backup=('etc/conf.d/salt-master'
		'etc/conf.d/salt-minion'
		'etc/conf.d/salt-syncdic'
		'etc/conf.d/salt-api')

        for f in salt-master salt-minion salt-syncdic salt-api;do
            _inst_confd $f
            _inst_initd $f
        done
}

package_mpd-openrc(){
	pkgdesc="OpenRC fuse init script"
	depends=('openrc' 'mpd')

	_inst_initd 'mpd'
}

package_hdparm-openrc() {
	pkgdesc="OpenRC hdparm init script"
	depends=('openrc' 'hdparm')
	backup=('etc/conf.d/hdparm')

	_inst_confd 'hdparm'
	_inst_initd 'hdparm'
}

package_thermald-openrc() {
	pkgdesc="OpenRC thermald init script"
	depends=('dbus-openrc' 'thermald')

	_inst_initd 'thermald'
}

package_xe-guest-utilities-openrc() {
	pkgdesc="OpenRC xe-guest-utilities init script"
	depends=('openrc' 'xe-guest-utilities')

	_inst_initd 'xe-daemon'
}

package_zfs-openrc() {
	pkgdesc="OpenRC zfs init script"
	depends=('openrc' 'zfs-utils')

	_inst_initd 'zfs'
}

package_clamav-openrc() {
	pkgdesc="OpenRC clamav init script"
	depends=('openrc' 'clamav')
	backup=('etc/conf.d/clamd')

	_inst_confd 'clamd'
	_inst_initd 'clamd'
}

package_at-openrc() {
	pkgdesc="OpenRC at init script"
	depends=('openrc' 'at')
	backup=('etc/conf.d/atd')

	_inst_confd 'atd'
	_inst_initd 'atd'

	sed -e 's|/var/run|/run|g' \
		-i "${pkgdir}/etc/conf.d/atd"
}

package_libvirt-openrc() {
	pkgdesc="OpenRC libvirt init script"
	depends=('openrc' 'libvirt')
	backup=('etc/conf.d/libvirtd')

	_inst_confd 'libvirtd'
	_inst_initd 'libvirtd'
	_inst_initd 'virtlockd'
	_inst_initd 'virtlogd'

	_inst_confd 'libvirt-guests'
	_inst_initd 'libvirt-guests'

	sed -e "s/USE_FLAG_FIREWALLD/need firewalld/" \
		-e "s/USE_FLAG_AVAHI/use avahi-daemon/" \
		-e "s/USE_FLAG_ISCSI/use iscsid/" \
		-e "s/USE_FLAG_RBD/use ceph/" \
		-i "${pkgdir}/etc/init.d/libvirtd"
}

package_laptop-mode-tools-openrc() {
	pkgdesc="OpenRC laptop-mode init script"
	depends=('openrc' 'laptop-mode-tools')
	groups=('openrc-misc' 'openrc-mobile')

	_inst_initd 'laptop_mode'
}